From 99385854b616d4fafe4c79050a2945e2341ded1b Mon Sep 17 00:00:00 2001 From: Eric Sieg Date: Fri, 3 Jun 2016 16:01:44 -0700 Subject: [PATCH] create cachedSessionToken for fast in memory use in the app, clear it when backgrounding, preserve it in keychain --- .../APCAppCore/DataSubstrate/Model/APCUser.h | 12 ++++++++---- .../APCAppCore/DataSubstrate/Model/APCUser.m | 14 ++++++++++++++ APCAppCore/APCAppCore/Startup/APCAppDelegate.m | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.h b/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.h index 1629b0c6..64a57fae 100644 --- a/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.h +++ b/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.h @@ -58,7 +58,6 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) { @property (nonatomic, strong, nullable) NSString * firstName DEPRECATED_ATTRIBUTE; @property (nonatomic, strong, nullable) NSString * lastName DEPRECATED_ATTRIBUTE; - @property (nonatomic, strong, nullable) NSString * email; @property (nonatomic, strong, nullable) NSString * password; @property (nonatomic, strong, nullable) NSString * sessionToken; @@ -98,9 +97,6 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) { @property (nonatomic, strong, nullable) NSDate *consentSignatureDate; @property (nonatomic, strong, nullable) NSData *consentSignatureImage; -@property (nonatomic, strong, nullable) NSDate *downloadDataStartDate; // NOT stored in CoreData -@property (nonatomic, strong, nullable) NSDate *downloadDataEndDate; // NOT stored in CoreData - @property (nonatomic, getter=isSecondaryInfoSaved) BOOL secondaryInfoSaved; /*********************************************************************************/ @@ -126,6 +122,14 @@ typedef NS_ENUM(NSInteger, APCUserConsentSharingScope) { @property (nonatomic, nullable) NSNumber * savedSharingScope; @property (nonatomic, nullable) NSArray * dataGroups; +/*********************************************************************************/ +#pragma mark - Stored In Memory Only +/*********************************************************************************/ +@property (nonatomic, strong, nullable) NSString * cachedSessionToken; // Memory Only, can nil this out and sessionToken will remain safely in keychain +@property (nonatomic, strong, nullable) NSDate *downloadDataStartDate; // NOT stored in CoreData +@property (nonatomic, strong, nullable) NSDate *downloadDataEndDate; // NOT stored in CoreData + + - (BOOL) isLoggedOut; /** diff --git a/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.m b/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.m index 56c0513c..919670c9 100644 --- a/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.m +++ b/APCAppCore/APCAppCore/DataSubstrate/Model/APCUser.m @@ -275,6 +275,20 @@ -(void)setPassword:(NSString *)password [APCKeychainStore setString:[self hashIfNeeded:password] forKey:kPasswordPropertyName]; } +- (NSString *)sessionToken +{ + if (self.cachedSessionToken == nil) { + self.cachedSessionToken = [APCKeychainStore stringForKey:kSessionTokenPropertyName]; + } + return self.cachedSessionToken; +} + +-(void)setSessionToken:(NSString *)sessionToken +{ + self.cachedSessionToken = sessionToken; + [APCKeychainStore setString:[self hashIfNeeded:sessionToken] forKey:kSessionTokenPropertyName]; +} + - (NSString *)externalId { return [APCKeychainStore stringForKey:kExternalIdPropertyName]; diff --git a/APCAppCore/APCAppCore/Startup/APCAppDelegate.m b/APCAppCore/APCAppCore/Startup/APCAppDelegate.m index 3eb51c93..765fa63f 100644 --- a/APCAppCore/APCAppCore/Startup/APCAppDelegate.m +++ b/APCAppCore/APCAppCore/Startup/APCAppDelegate.m @@ -273,7 +273,8 @@ - (void)applicationDidEnterBackground:(UIApplication *) __unused application [[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithLong:uptime()] forKey:kLastUsedTimeKey]; [[NSUserDefaults standardUserDefaults] synchronize]; } - self.dataSubstrate.currentUser.sessionToken = nil; + // Clear the in memory token while preserving the keychain version + self.dataSubstrate.currentUser.cachedSessionToken = nil; [self showSecureView]; }