2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * The contents of this file are subject to the terms of the Common Development and
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Distribution License (the License). You may not use this file except in compliance with the
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * License.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell *
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * specific language governing permission and limitations under the License.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell *
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * When distributing Covered Software, include this CDDL Header Notice in each file and include
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Header, with the fields enclosed by brackets [] replaced by your own identifying
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * information: "Portions copyright [year] [name of copyright owner]".
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell *
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Copyright 2016 ForgeRock AS.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#import "FRAModelObject.h"
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@class FRAIdentityDatabase;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott@class FRAMechanism;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Identity is responsible for modelling the information that makes up part of a user's identity in
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * the context of logging into that user's account.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@interface FRAIdentity : FRAModelObject
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Name of the Identity Provider (IdP) that issued this identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@property (copy, nonatomic, readonly) NSString *issuer;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Name of this identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@property (copy, nonatomic, readonly) NSString *accountName;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * URL pointing to an image (such as a logo) that represents the issuer of this identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@property (copy, nonatomic, readonly) NSURL *image;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott/*!
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott * Text representation of the background colour to be used by the user interface for this Identity.
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott */
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott@property (copy, nonatomic, readonly) NSString *backgroundColor;
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott/*!
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * The Mechanisms assigned to the Identity. Maybe empty.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@property (getter=mechanisms, nonatomic, readonly) NSArray<FRAMechanism *> *mechanisms;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark -
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark Lifecycle
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell/*!
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * Prevent external use of super class' initWithDatabase: method.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel __unavailable;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Creates a new identity object with the provided property values.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel accountName:(NSString *)accountName issuer:(NSString *)issuer image:(NSURL *)image backgroundColor:(NSString *)color;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Creates a new identity object with the provided property values.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni+ (instancetype)identityWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel accountName:(NSString *)accountName issuer:(NSString *)issuer image:(NSURL *)image backgroundColor:(NSString *)color;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark -
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark Mechanism Functions
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell/*!
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * Returns mechanism of the specified type if one has been registered to this identity.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param aClass The type of mechanism to look for.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @return The mechanism object, or nil if no such mechanism has been registered.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell- (FRAMechanism *)mechanismOfClass:(Class)aClass;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott/*!
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni * When a new mechanism is created, it will assigned to the identity via
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * this call.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param mechanism The new mechanism to add to this identity.
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott * @return BOOL False if there was an error with the operation, in which case check the error parameter for details.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott- (BOOL)addMechanism:(FRAMechanism *)mechanism error:(NSError *__autoreleasing *)error;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott/*!
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni * Removes the mechanism, only if it was assigned to this identity.
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni * If the identity has no more mechanisms, the identity is removed from the identity model.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param mechanism The mechanism to remove from the identity.
7c51d54f23c5581d2cf894f9eafb9798e3febd22Diego Colantoni * @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott * @return BOOL False if there was an error with the operation, in which case check the error parameter for details.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott- (BOOL)removeMechanism:(FRAMechanism *)mechanism error:(NSError *__autoreleasing *)error;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell#pragma mark -
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell#pragma mark Notification Functions
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell/*!
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell * Count of notifications that have not yet been dealt with.
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell *
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell * @return The number of pending notifications.
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell */
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell- (NSInteger)pendingNotificationsCount;
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@end