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
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@class FRAIdentity;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@class FRAIdentityDatabase;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott@class FRANotification;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * A mechanism used for authentication within the Authenticator Application.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott *
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * Encapsulates the related settings, as well as an owning Identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni@interface FRAMechanism : FRAModelObject {
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni @protected
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni NSInteger _version;
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni}
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * The parent Identity object which this mechanism belongs to.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell// NB. FRAIdentity and FRAMechanism hold a strong reference to each other - Necessary as FRAMechanismFactory
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell// returns FRAMechanism which may reference a new FRAIdentity.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell@property (nonatomic) FRAIdentity *parent;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott/*!
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni * The version number of this mechanism.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni@property (nonatomic, readonly) NSInteger version;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni/*!
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni * A list of the current Notficiations that are assigned to this Mechanism.
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni */
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni@property (getter=notifications, nonatomic, readonly) NSArray<FRANotification *> *notifications;
78c07714ec1113f7f21c75b818f2bf6a7021618aDiego Colantoni
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark -
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark Lifecyle
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell/*!
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * Init method.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param database The database to which this mechanism can be persisted.
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni * @param identityModel The identity model which contains the list of identities.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @return The initialized mechanism or nil if initialization failed.
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel;
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark -
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#pragma mark Notification Functions
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott/*!
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * When a new notification is received by the App, it will be appended to
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * the owning Mechanism using this method.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param notification The notification to add to this Mechanism.
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 NO if there was an error adding the Notification, in which case the error value will be populated.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott- (BOOL)addNotification:(FRANotification *)notification error:(NSError *__autoreleasing*)error;
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott * Once a Notification has been marked as deleted, it will be removed from
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * the Mechanism by this method.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott *
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @param notification The notification to remove from the Mechanism.
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 NO if there was an error adding the Notification, in which case the error value will be populated.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott- (BOOL)removeNotification:(FRANotification *)notification error:(NSError *__autoreleasing*)error;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig 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
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell/*!
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell * Gets the notification identified uniquely by the provided messageID.
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell * @param messageId The message id of the notification to get.
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell * @return The notification with the specified messageId or nil if no match is found.
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell */
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell- (FRANotification *)notificationWithMessageId:(NSString *)messageId;
916ef74523ecddc8140815c084ab6971ee366bcfCraig McDonnell
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni/*!
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni * Return the mechanism type (i.e. totp, hotp or push).
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni */
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni+ (NSString *)mechanismType;
caa9e77dc369fea8df9ae2c598d3c83b7214c1cfDiego Colantoni
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@end