ForgeRock SDKs 3.3

Customize the StorageClient

The ForgeRock Authenticator module offers a default storage client that uses SecuredSharedPreferences, an encrypted storage mechanism built on Android SharedPreferences. It is available in the forgerock-core module.

SecuredSharedPreferences stores and manages all shared secret account information and notifications.

The Authenticator module lets you customize the StorageClient. You can implement the StorageClient protocol, and register your own StorageClient in the module.

You can implement it with SQLite EncryptedSharedPreferences, or any other storage destination.

The ForgeRock Authenticator module uses your storage client and manages all data through that client.

To customize the StorageClient, implement the following interfaces:

public interface StorageClient {
    /**
     * Get the Account object with its id
     * @param accountId The account unique ID
     * @return The account object.
     */
    Account getAccount(String accountId);
    /**
     * Get all accounts stored in the system.
     * @return The complete list of accounts.
     */
    List<Account> getAllAccounts();
    /**
     * Delete the Account that was passed in.
     * @param account The account object to delete.
     * @return boolean as result of the operation
     */
    boolean removeAccount(Account account);
    /**
     * Add or Update the Account to the storage system.
     * @param account The Account to store or update.
     * @return boolean as result of the operation
     */
    boolean setAccount(Account account);
    /**
     * Get the mechanisms associated with an account.
     * @param account The Account object
     * @return The list of mechanisms for the account.
     */
    List<Mechanism> getMechanismsForAccount(Account account);
    /**
     * Get the mechanism by UUID.
     * @param mechanismUID The uniquely identifiable UUID for the mechanism
     * @return The mechanism object.
     */
    Mechanism getMechanismByUUID(String mechanismUID);
    /**
     * Delete the mechanism uniquely identified by an id.
     * @param mechanism The mechanism object to delete.
     * @return boolean as result of the operation
     */
    boolean removeMechanism(Mechanism mechanism);
    /**
     * Add or update the mechanism to the storage system.
     * If the owning Account is not yet stored, store that as well.
     * @param mechanism The mechanism to store or update.
     * @return boolean as result of the operation
     */
    boolean setMechanism(Mechanism mechanism);
    /**
     * Get all notifications for within the mechanism.
     * @param mechanism The mechanism object
     * @return The list of notifications for the mechanism.
     */
    List<PushNotification> getAllNotificationsForMechanism(Mechanism mechanism);
    /**
     * Delete the pushNotification uniquely identified by an id.
     * @param pushNotification The pushNotification object to delete.
     */
    boolean removeNotification(PushNotification pushNotification);
    /**
     * Add or update the pushNotification to the storage system.
     * @param pushNotification The pushNotification to store.
     * @return boolean as result of the operation
     */
    boolean setNotification(PushNotification pushNotification);
    /**
     * Whether the storage system currently contains any data.
     * @return True if the storage system is empty, false otherwise.
     */
    boolean isEmpty();
}

For each method of getting an Account, Mechanism, or PushNotification object, your StorageClient should only be responsible for retrieving the objects, and not any other object associated with it.

For example, when retrieving Account objects, the StorageClient should not be responsible for retrieving Mechanism and PushNotification objects. All object mapping and associations are handled by the ForgeRock Authenticator module itself.

After implementing your custom StorageClient, register it to FRAClient as follows:

//Initiate your custom StorageClient
StorageClient customStorageClient = CustomStorageClient()

//Register it to FRAClient
FRAClient fraClient = new FRAClient.FRAClientBuilder()
                .withContext(this)
                .withStorage(customStorageClient)
                .start();

You must register the StorageClient before you start the ForgeRock SDK.

Once the SDK starts, the StorageClient used by FRAClient cannot be changed.

Copyright © 2010-2022 ForgeRock, all rights reserved.