FRANotification.h revision 5d37db6a3aca50ba14cba8909d3ae44f7d43e407
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * The contents of this file are subject to the terms of the Common Development and
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * Distribution License (the License). You may not use this file except in compliance with the
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * License.
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston *
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * specific language governing permission and limitations under the License.
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston *
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * When distributing Covered Software, include this CDDL Header Notice in each file and include
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * Header, with the fields enclosed by brackets [] replaced by your own identifying
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * information: "Portions copyright [year] [name of copyright owner]".
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston *
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * Copyright 2016 ForgeRock AS.
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston */
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac#import "FRAModelObject.h"
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston@class FRAIdentityDatabase;
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston@class FRAMechanism;
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston
65e99be301d5a19db33f25841f671756e8dbb9b5ludovicp/*!
3b027e67340d58dc53a74d3498d6a75704d39d5agary.williams * Models a notification in the Authenticator Application. This notification
e60213872d70f9bf42bbf4b68208636a8e9c219fugaston * currently could be assiged to any Mechanism.
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin *
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * Node: In practice this will currently just be Push Notifications, but
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * we imagine other kinds of notifications might be useful later on.
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin */
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin@interface FRANotification : FRAModelObject
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * Each Notification must be associated with a parent Mechanism.
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin */
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin@property (nonatomic, weak) FRAMechanism *parent;
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * A timestamp of when the Notification was received by the application.
3aefffce90936644674d12447aeec64c746e72d4maudj */
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin@property (nonatomic, readonly) NSDate *timeReceived;
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * The timestamp of when the Notification is expected to expire.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (nonatomic) NSDate *timeExpired;
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * Indicator of whether this Notification is pending. In the pending state a
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * Notification can either be marked as approved or denied. Once it has been
3aefffce90936644674d12447aeec64c746e72d4maudj * either approved or denied, it will move to the non-pending state.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (getter=isPending, nonatomic, readonly) BOOL pending;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Indicator of whether the Notification has been approved. Once in the approved
b304b0df5c7c7e052d5a635732f909e592209a12maudj * state, the Notification is complete and no further action is required.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (getter=isApproved, nonatomic, readonly) BOOL approved;
3b027e67340d58dc53a74d3498d6a75704d39d5agary.williams
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Indicator of whether the Notification has been denied. Once in the denied
3aefffce90936644674d12447aeec64c746e72d4maudj * state, the Notification is complete and no further action is required.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (getter=isDenied, nonatomic, readonly) BOOL denied;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Indicator of whether the Notification has expired. Once in the expired
3aefffce90936644674d12447aeec64c746e72d4maudj * state, the Notification is complete and no further action is required.
3b027e67340d58dc53a74d3498d6a75704d39d5agary.williams */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (getter=isExpired, nonatomic, readonly) BOOL expired;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Message Id of the message.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (nonatomic, readonly) NSString *messageId;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * The push challenge.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (nonatomic, readonly) NSString *challenge;
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * The time to live of the push login window.
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin */
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin@property (nonatomic, readonly) NSTimeInterval timeToLive;
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin/*!
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin * The load balancer cooky to send with the notification response. Format = "<cookiename>=<cookievalue">.
ed04f43fdb6e943544e77d0cb7c2df7a5171b00fsmaguin */
3aefffce90936644674d12447aeec64c746e72d4maudj@property (nonatomic, readonly) NSString *loadBalancerCookie;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Constructor for creating a Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie pending:(BOOL)pendingState approved:(BOOL)approvedState;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Constructor for creating a Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Static factory for creating a Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj+ (instancetype)notificationWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie pending:(BOOL)pendingState approved:(BOOL)approvedState;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Static factory for creating a Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj+ (instancetype)notificationWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj- (instancetype) __unavailable initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Generates description of the age of this notification as:
3aefffce90936644674d12447aeec64c746e72d4maudj *
3aefffce90936644674d12447aeec64c746e72d4maudj * @code
3aefffce90936644674d12447aeec64c746e72d4maudj * if (timeReceived < 60 seconds ago)
3aefffce90936644674d12447aeec64c746e72d4maudj * return "n seconds ago";
3aefffce90936644674d12447aeec64c746e72d4maudj * else if (timeReceived < 60 minutes ago)
3aefffce90936644674d12447aeec64c746e72d4maudj * return "n minutes ago";
3aefffce90936644674d12447aeec64c746e72d4maudj * else if (timeReceived < 24 hours ago)
3aefffce90936644674d12447aeec64c746e72d4maudj * return "n hours ago";
3aefffce90936644674d12447aeec64c746e72d4maudj * else if (timeReceived < 1 day ago)
3aefffce90936644674d12447aeec64c746e72d4maudj * return "Yesterday";
3aefffce90936644674d12447aeec64c746e72d4maudj * else if (timeReceived < 7 days ago)
3aefffce90936644674d12447aeec64c746e72d4maudj * return "n days ago";
3aefffce90936644674d12447aeec64c746e72d4maudj * else
3aefffce90936644674d12447aeec64c746e72d4maudj * return timeReceived using date format "dd/MM/yyyy";
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj- (NSString *)age;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Mark the notification as accepted to indicate the user accepts this
3aefffce90936644674d12447aeec64c746e72d4maudj * Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj *
3aefffce90936644674d12447aeec64c746e72d4maudj * @param error If there was an error, this value will be populated.
3aefffce90936644674d12447aeec64c746e72d4maudj * @return BOOL NO if there was an error approving the Notification, in which case the error value will be populated.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj- (BOOL)approveWithError:(NSError *__autoreleasing*)error;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj/*!
3aefffce90936644674d12447aeec64c746e72d4maudj * Mark the notification as denied to indicate the user has denied the
3aefffce90936644674d12447aeec64c746e72d4maudj * Notification.
3aefffce90936644674d12447aeec64c746e72d4maudj *
3aefffce90936644674d12447aeec64c746e72d4maudj * @param error If there was an error, this value will be populated.
3aefffce90936644674d12447aeec64c746e72d4maudj * @return BOOL NO if there was an error denying the Notification, in which case the error value will be populated.
3aefffce90936644674d12447aeec64c746e72d4maudj */
3aefffce90936644674d12447aeec64c746e72d4maudj- (BOOL)denyWithError:(NSError *__autoreleasing*)error;
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj
3aefffce90936644674d12447aeec64c746e72d4maudj@end
3aefffce90936644674d12447aeec64c746e72d4maudj