FRAIdentityDatabase.h revision e2d1c3c0c150e511b0df83a3c49451ae773ea93a
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
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell#import <Foundation/Foundation.h>
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@class FRAIdentity;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@class FRAOathMechanism;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Listens to a database for the data to change.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@protocol FRADatabaseListener <NSObject>
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Called when any write operation takes place.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)onUpdate;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@end
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Data Access Object which can store and load both Identities and Mechanisms.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Encapsulates the specific storage mechanism.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@interface FRAIdentityDatabase : NSObject
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Accessor for singleton.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell *
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * This is a temporary solution that should be fixed when setting up the skeleton screens and segues;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * the correct solution for making the database accessible to all objects that need it is dependency injection.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2229ffbfe08c2cd606c305f8934e627548002c9eCraig McDonnell+ (instancetype)singleton;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Gets all of the identities which are stored.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @return The list of identities.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (NSArray*)identities;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell/*!
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell * Gets the identity identified uniquely by the provided ID.
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell * @param uid The storage id of the identity to get.
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell * @return The identity with the specified storage ID.
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell */
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell- (FRAIdentity*)identityWithId:(NSInteger)uid;
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Gets the mechanism identified uniquely by the provided ID.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param uid The storage id of the mechanism to get.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @return The mechanism with the specified storage ID.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (FRAOathMechanism*)mechanismWithId:(NSInteger)uid;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Get the mechanisms associated with an owning identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param owner The account to which the returned mechanisms were registered.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @return The mechanisms registered to the specified identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (NSArray*)mechanismsWithOwner:(FRAIdentity*)owner;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Gets the identity uniquely identified by the specified issuer and accountName.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param issuer The issuer of the identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param accountName The name of the identity.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @return The identity that was stored.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (FRAIdentity*)identityWithIssuer:(NSString*)issuer accountName:(NSString*)accountName;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Add the identity to the database.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param id The identity to add.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)addIdentity:(FRAIdentity*)identity;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell/*!
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell * Delete the identity uniquely identified by the specified storage ID.
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell * @param uid The storage ID of the identity to delete.
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell */
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell- (void)removeIdentityWithId:(NSInteger)uid;
e2d1c3c0c150e511b0df83a3c49451ae773ea93aCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Add the mechanism to the database. If the owning identity is not yet stored, store that as well.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param mechanism The mechanism to store.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)addMechanism:(FRAOathMechanism*)mechanism;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Update the mechanism in the database. Does not create it if it does not exist.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param mechanism The mechanism to update.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)updateMechanism:(FRAOathMechanism*)mechanism;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Delete the mechanism uniquely identified by the specified storage ID.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param uid The storage ID of the mechanism to delete.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)removeMechanismWithId:(NSInteger)uid;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell/*!
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * Add a listener to this connection.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @param listener The listener to add.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell- (void)addListener:(id<FRADatabaseListener>)listener;
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell@end