Class LdapAdapter

  • All Implemented Interfaces:
    TokenStorageAdapter

    public class LdapAdapter
    extends Object
    implements TokenStorageAdapter
    Responsible adapting the LDAP SDK Connection and its associated domain values into Tokens. This class will manage the associated conversion tasks and present a common interface to calling classes. It also helps us work around a number of final classes in the SDK which were hindering unit testing.
    • Constructor Detail

    • Method Detail

      • create

        public Token create​(Token token,
                            org.forgerock.util.Options options)
                     throws DataLayerException
        Create the Token in LDAP.
        Specified by:
        create in interface TokenStorageAdapter
        Parameters:
        token - Non null Token to create.
        options - Non null Options for the operations.
        Returns:
        A copy of the created Token with the ETag set.
        Throws:
        DataLayerException - If the operation failed, this exception will capture the reason.
      • read

        public Token read​(String tokenId,
                          org.forgerock.util.Options options)
                   throws DataLayerException
        Performs a read against the LDAP connection and converts the result into a Token.
        Specified by:
        read in interface TokenStorageAdapter
        Parameters:
        tokenId - The id of the Token to read.
        options - Non null Options for the operations.
        Returns:
        Token if found, otherwise null.
        Throws:
        DataLayerException - If the operation failed, this exception will capture the reason.
      • update

        public Token update​(Token previous,
                            Token updated,
                            org.forgerock.util.Options options)
                     throws DataLayerException
        Update the Token based on whether there were any changes between the two. It is up to the underlying ldap later to update the etag so the etag so the etag is removed from the previous and updated token before the diff is computed.

        If the previous Token contains a non-null CoreTokenField.ETAG attribute value then the update will be performed with an optimistic concurrency check. If it does not contain the attribute or it contains a null value the update will be performed without any concurrency checks.

        Specified by:
        update in interface TokenStorageAdapter
        Parameters:
        previous - The non null previous Token to check against.
        options - The non null Options for the operation.
        updated - The non null Token to update with.
        Returns:
        A copy of the updated token. The token would contain the updated etag.
        Throws:
        OptimisticConcurrencyCheckFailedException - If the operation failed due to an assertion on the tokens ETag. Only possible if the CoreTokenField.ETAG attribute is present on the previous token.
        DataLayerException - If the operation failed for a known reason.
      • delete

        public PartialToken delete​(String tokenId,
                                   org.forgerock.util.Options options)
                            throws DataLayerException
        Performs a delete against the Token ID provided.

        If the etag parameter is a non-null value then the delete will be performed with an optimistic concurrency check. If it is null then the delete will be performed without any concurrency checks.

        Specified by:
        delete in interface TokenStorageAdapter
        Parameters:
        tokenId - The non null Token ID to delete.
        options - The non null Options for the operation.
        Returns:
        A PartialToken containing at least the CoreTokenField.TOKEN_ID.
        Throws:
        DataLayerException - If the operation failed, this exception will capture the reason.
        OptimisticConcurrencyCheckFailedException - If the operation failed due to an assertion on the tokens ETag.