91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * The contents of this file are subject to the terms of the Common Development and
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * specific language governing permission and limitations under the License.
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * Copyright 2016 ForgeRock AS.
306fc147c159b5ea1a92aa9466cd30a9bf743fe0Craig McDonnell#import "FRADateUtils.h"
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#import "FRAIdentityDatabase.h"
a1e92b2783be4bfeb0c7e267223cc7779a6f324cKen Stubbings#import "FRAMessageUtils.h"
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell#import "FRAModelObjectProtected.h"
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott#import "FRANotification.h"
a1e92b2783be4bfeb0c7e267223cc7779a6f324cKen Stubbings#import "FRAPushMechanism.h"
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * All notifications are expected to be able to transition from the initial state
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * of pending, to the final state of approved or denied.
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings- (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 {
f877f6ca2428244a6d0954a1dbef471577b32c60Diego Colantoni self = [super initWithDatabase:database identityModel:identityModel];
3cb6a584a87fa8fec140b0bb20dd91731d13e751Diego Colantoni _timeExpired = [timeReceived dateByAddingTimeInterval:timeToLive];
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings- (instancetype)initWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie{
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings return [self initWithDatabase:database identityModel:identityModel messageId:messageId challenge:challenge timeReceived:timeReceived timeToLive:timeToLive loadBalancerCookieData:loadBalancerCookie pending:YES approved:NO];
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings+ (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{
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings return [[FRANotification alloc] initWithDatabase:database identityModel:identityModel messageId:messageId challenge:challenge timeReceived:timeReceived timeToLive:timeToLive loadBalancerCookieData:loadBalancerCookie pending:pendingState approved:approvedState];
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings+ (instancetype)notificationWithDatabase:(FRAIdentityDatabase *)database identityModel:(FRAIdentityModel *)identityModel messageId:(NSString *)messageId challenge:(NSString *)challenge timeReceived:(NSDate *)timeReceived timeToLive:(NSTimeInterval)timeToLive loadBalancerCookieData:(NSString *)loadBalancerCookie{
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings return [[FRANotification alloc] initWithDatabase:database identityModel:identityModel messageId:messageId challenge:challenge timeReceived:timeReceived timeToLive:timeToLive loadBalancerCookieData:loadBalancerCookie pending:YES approved:NO];
306fc147c159b5ea1a92aa9466cd30a9bf743fe0Craig McDonnell return [[[FRADateUtils alloc] init] ageOfEventTime:self.timeReceived];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (BOOL)approveWithHandler:(void (^)(NSInteger, NSError *))handler error:(NSError *__autoreleasing*)error {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni return [self sendAuthenticationResponse:YES handler:handler error:error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (BOOL)denyWithHandler:(void (^)(NSInteger, NSError *))handler error:(NSError *__autoreleasing*)error {
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni return [self sendAuthenticationResponse:NO handler:handler error:error];
6a2ae9c7fb4d2c40d75cab0edaf940f22c18224fDiego Colantoni- (BOOL)sendAuthenticationResponse:(BOOL)approved handler:(void (^)(NSInteger, NSError *))handler error:(NSError *__autoreleasing*)error {
721bb987c406979bcfe705fa1ca8d54497d40fcbRobert Wapshott if (![self.database updateNotification:self error:error]) {
cc2ae888007384c94072d7864e53548dd2840d33Craig McDonnell FRAPushMechanism *mechanism = (FRAPushMechanism *)self.parent;
cc2ae888007384c94072d7864e53548dd2840d33Craig McDonnell NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
cc2ae888007384c94072d7864e53548dd2840d33Craig McDonnell data[@"response"] = [FRAMessageUtils generateChallengeResponse:self.challenge secret:mechanism.secret];
a1e92b2783be4bfeb0c7e267223cc7779a6f324cKen Stubbings [FRAMessageUtils respondWithEndpoint:mechanism.authEndpoint
5d37db6a3aca50ba14cba8909d3ae44f7d43e407Ken Stubbings loadBalancerCookieData:self.loadBalancerCookie