Class DJLDAPv3Repo

    • Constructor Detail

      • DJLDAPv3Repo

        public DJLDAPv3Repo()
    • Method Detail

      • initialize

        public void initialize​(Map<String,​Set<String>> configParams)
                        throws IdRepoException
        Initializes the IdRepo instance, basically within this method we process the configuration settings and set up the connection factories that will be used later in the lifetime of the IdRepo plugin.
        Overrides:
        initialize in class IdRepo
        Parameters:
        configParams - The IdRepo configuration as defined in the service configurations.
        Throws:
        IdRepoException - Shouldn't be thrown.
      • createConnectionFactory

        protected ConnectionFactory<org.forgerock.opendj.ldap.Connection> createConnectionFactory​(String username,
                                                                                                  char[] password,
                                                                                                  int maxPoolSize)
      • supportsAuthentication

        public boolean supportsAuthentication()
        Tells whether this identity repository supports authentication.
        Overrides:
        supportsAuthentication in class IdRepo
        Returns:
        true since this repository supports authentication.
      • authenticate

        public boolean authenticate​(Callback[] credentials)
                             throws IdRepoException,
                                    AuthLoginException
        Tries to bind as the user with the credentials passed in via callbacks. This authentication mechanism does not handle password policies, nor password expiration.
        Overrides:
        authenticate in class IdRepo
        Parameters:
        credentials - The username/password combination.
        Returns:
        true if the bind operation was successful.
        Throws:
        IdRepoException - If the passed in username/password was null, or if the specified user cannot be found.
        AuthLoginException - If an LDAP error occurs during authentication.
        InvalidPasswordException - If the provided password is not valid, so Account Lockout can be triggered.
      • changePassword

        public void changePassword​(SSOToken token,
                                   IdType type,
                                   String name,
                                   String attrName,
                                   String oldPassword,
                                   String newPassword)
                            throws IdRepoException
        Changes password for the given identity by binding as the user first (i.e. this is not password reset). In case of Active Directory the password will be encoded first. This will issue a DELETE for the old password and an ADD for the new password value.
        Overrides:
        changePassword in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER.
        name - The name of the identity.
        attrName - The name of the password attribute, usually "userpassword" or "unicodepwd".
        oldPassword - The current password of the identity.
        newPassword - The new password of the idenity.
        Throws:
        IdRepoException - If the identity type is invalid, or the entry cannot be found, or some other LDAP error occurs while changing the password (like password policy related errors).
      • getFullyQualifiedName

        public String getFullyQualifiedName​(SSOToken token,
                                            IdType type,
                                            String name)
                                     throws IdRepoException
        Returns a fully qualified name of the identity, which should be unique per data store.
        Overrides:
        getFullyQualifiedName in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        Returns:
        Fully qualified name of this identity or null if the identity cannot be found.
        Throws:
        IdRepoException - If there was an error while looking up the user.
      • getSupportedOperations

        public Set<IdOperation> getSupportedOperations​(IdType type)
        Returns the set of supported operations for a given identity type.
        Overrides:
        getSupportedOperations in class IdRepo
        Parameters:
        type - The identity type for which we want to get the supported operations.
        Returns:
        The set of supported operations for this identity type.
      • getSupportedTypes

        public Set<IdType> getSupportedTypes()
        Returns the set of supported identity types.
        Overrides:
        getSupportedTypes in class IdRepo
        Returns:
        The set of supported identity types.
      • setActiveStatus

        public void setActiveStatus​(SSOToken token,
                                    IdType type,
                                    String name,
                                    boolean active)
                             throws IdRepoException
        Sets the user status to the value provided for the given identity.
        Specified by:
        setActiveStatus in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER.
        name - The name of the identity.
        active - The new status of the identity.
        Throws:
        IdRepoException - If the identity type is invalid, or either the previous status retrieval failed (AD), or there was a failure while setting the status.
      • isActive

        public boolean isActive​(SSOToken token,
                                IdType type,
                                String name)
                         throws IdRepoException
        Tells whether the given identity is considered as "active" or not. In case the user status attribute is not configured, this method will always return true. In case of Active Directory the returned userAccountControl attribute will be masked with 0x2 to detect whether the given account is disabled or not.
        Overrides:
        isActive in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER.
        name - The name of the identity.
        Returns:
        true if user status attribute is not configured, or decision based on the status attribute value. If there was any error while retrieving the status attribute this method will return false.
        Throws:
        IdRepoException - If the identity type is invalid.
      • isExists

        public boolean isExists​(SSOToken token,
                                IdType type,
                                String name)
                         throws IdRepoException
        Tells whether a given identity exists or not.
        Specified by:
        isExists in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        Returns:
        true if the identity exists.
        Throws:
        IdRepoException - Shouldn't be thrown.
      • create

        public String create​(SSOToken token,
                             IdType type,
                             String name,
                             Map<String,​Set<String>> attrMap)
                      throws IdRepoException
        Creates a new identity using the passed in attributes. The following steps will be performed with the passed in data:
        • The password will be encoded in case we are dealing with AD.
        • If the attribute map contains the default status attribute, then it will be converted to the status values specified in the configuration.
        • Performing creation attribute mapping, so certain attributes can have default values (coming from other attributes, or from the identity name if there is no mapping for the attribute).
        • Removes all attributes that are not defined in the configuration.
        If the default group member setting is being used and a new group identity is being created, the newly created group will also have the default group member assigned.
        Specified by:
        create in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attrMap - The attributes of the new identity, that needs to be stored.
        Returns:
        The DN of the newly created identity
        Throws:
        IdRepoException - If there is an error while creating the new identity, or if it's a group and there is a problem while adding the default group member.
      • getAttributes

        public Map<String,​Set<String>> getAttributes​(SSOToken token,
                                                           IdType type,
                                                           String name)
                                                    throws IdRepoException
        Returns all the attributes that are defined in the configuration for the given identity.
        Specified by:
        getAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        Returns:
        The attributes of this identity.
        Throws:
        IdRepoException - If there is an error while retrieving the identity attributes.
      • getAttributes

        public Map<String,​Set<String>> getAttributes​(SSOToken token,
                                                           IdType type,
                                                           String name,
                                                           Set<String> attrNames)
                                                    throws IdRepoException
        Returns all the requested attributes that are defined in the configuration for this given identity.
        Specified by:
        getAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attrNames - The names of the requested attributes or null to retrieve all the attributes.
        Returns:
        The requested attributes of this identity.
        Throws:
        IdRepoException - If there is an error while retrieving the identity attributes.
      • getBinaryAttributes

        public Map<String,​byte[][]> getBinaryAttributes​(SSOToken token,
                                                              IdType type,
                                                              String name,
                                                              Set<String> attrNames)
                                                       throws IdRepoException
        Returns all the requested binary attributes that are defined in the configuration for this given identity.
        Specified by:
        getBinaryAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attrNames - The names of the requested binary attributes or null to retrieve all the attributes.
        Returns:
        The requested attributes of this identity in binary format.
        Throws:
        IdRepoException - If there is an error while retrieving the identity attributes.
      • setAttributes

        public void setAttributes​(SSOToken token,
                                  IdType type,
                                  String name,
                                  Map<String,​Set<String>> attributes,
                                  boolean isAdd)
                           throws IdRepoException
        Sets the provided attributes for the given identity.
        Specified by:
        setAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attributes - The attributes that needs to be set for the entry.
        isAdd - true if the attributes should be ADDed, false if the attributes should be REPLACEd instead.
        Throws:
        IdRepoException - Can be thrown in the following cases:
        • the identity cannot be found,
        • there was a problem while retrieving the current user status from the directory (AD),
        • there are no modifications to actually perform,
        • there was an error while retrieving the objectClass attribute,
        • there was an error while trying to read the directory schema,
        • there was an error while trying to perform the modifications.
      • setBinaryAttributes

        public void setBinaryAttributes​(SSOToken token,
                                        IdType type,
                                        String name,
                                        Map<String,​byte[][]> attributes,
                                        boolean isAdd)
                                 throws IdRepoException
        Sets the provided binary attributes for the given identity.
        Specified by:
        setBinaryAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attributes - The binary attributes that needs to be set for the entry.
        isAdd - true if the attributes should be ADDed, false if the attributes should be REPLACEd instead.
        Throws:
        IdRepoException - Can be thrown in the following cases:
        • the identity cannot be found,
        • there was a problem while retrieving the current user status from the directory (AD),
        • there are no modifications to actually perform,
        • there was an error while retrieving the objectClass attribute,
        • there was an error while trying to read the directory schema,
        • there was an error while trying to perform the modifications.
      • removeAttributes

        public void removeAttributes​(SSOToken token,
                                     IdType type,
                                     String name,
                                     Set<String> attrNames)
                              throws IdRepoException
        Removes the specified attributes from the identity.
        Specified by:
        removeAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        attrNames - The set of attribute names that needs to be removed from the identity.
        Throws:
        IdRepoException - If there is no attribute name provided, or if the identity cannot be found, or there is an error while modifying the entry.
      • search

        public RepoSearchResults search​(SSOToken token,
                                        IdType type,
                                        CrestQuery crestQuery,
                                        int maxTime,
                                        int maxResults,
                                        Set<String> returnAttrs,
                                        boolean returnAllAttrs,
                                        int filterOp,
                                        Map<String,​Set<String>> avPairs,
                                        boolean recursive)
                                 throws IdRepoException
        Performs a search in the directory based on the provided parameters. Using the pattern and avPairs parameters an example search filter would look something like: (&(|(attr1=value1)(attr2=value2))(searchAttr=pattern)(objectclassfilter)).
        Specified by:
        search in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        crestQuery - Either a string, coming from something like the CREST endpoint _queryId or a fully fledged query filter, coming from a CREST endpoint's _queryFilter
        maxTime - The time limit for this search (in seconds). When maxTime < 1, the default time limit will be used.
        maxResults - The number of maximum results we should receive for this search. When maxResults < 1 the default sizelimit will be used.
        returnAttrs - The attributes that should be returned from the "search hits".
        returnAllAttrs - true if all user attribute should be returned.
        filterOp - When avPairs is provided, this logical operation will be used between them. Use IdRepo.AND_MOD or IdRepo.OR_MOD.
        avPairs - Attribute-value pairs based on the search should be performed.
        recursive - Deprecated setting, not used.
        Returns:
        The search results based on the provided parameters.
        Throws:
        IdRepoException - Shouldn't be thrown as the returned RepoSearchResults will contain the error code.
      • delete

        public void delete​(SSOToken token,
                           IdType type,
                           String name)
                    throws IdRepoException
        Deletes the identity from the directory.
        Specified by:
        delete in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity.
        name - The name of the identity.
        Throws:
        IdRepoException - If the identity cannot be found, or there is an error while deleting the identity.
      • getMembers

        public Set<String> getMembers​(SSOToken token,
                                      IdType type,
                                      String name,
                                      IdType membersType)
                               throws IdRepoException
        Gets membership data for a given group/role/filtered role.
        Specified by:
        getMembers in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always GROUP, ROLE or FILTEREDROLE.
        name - The name of the identity.
        membersType - The type of the member identity, this should be always USER.
        Returns:
        The DNs of the members.
        Throws:
        IdRepoException - Can be thrown in the following cases:
        • the identity type is not GROUP/ROLE/FILTEREDROLE,
        • the membersType is not USER,
        • the identity cannot be found,
        • there was an error while retrieving the members.
      • getMemberships

        public Set<String> getMemberships​(SSOToken token,
                                          IdType type,
                                          String name,
                                          IdType membershipType)
                                   throws IdRepoException
        Returns the membership information of a user for the given membership type.
        Specified by:
        getMemberships in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER.
        name - The name of the identity.
        membershipType - The type of the membership identity, this should be always GROUP/ROLE/FILTEREDROLE.
        Returns:
        The DNs of the groups/roles/filtered roles this user is member of.
        Throws:
        IdRepoException - if the identity type is not USER, or if there was an error while retrieving the membership data.
      • modifyMemberShip

        public void modifyMemberShip​(SSOToken token,
                                     IdType type,
                                     String name,
                                     Set<String> members,
                                     IdType membersType,
                                     int operation)
                              throws IdRepoException
        Adds or removes members to the provided group/role.
        Specified by:
        modifyMemberShip in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always GROUP or ROLE.
        name - The name of the identity.
        members - The set of members that needs to be added/removed.
        membersType - The type of the member, this should be always USER.
        operation - The operation that needs to be performed with the provided members. Use IdRepo.ADDMEMBER and IdRepo.REMOVEMEMBER.
        Throws:
        IdRepoException - Can be thrown in the following cases:
        • there are no members provided,
        • the provided type/membersType are invalid,
        • the identity to be modified cannot be found,
        • one of the members cannot be found,
        • there was an error while trying to modify the membership data.
      • assignService

        public void assignService​(SSOToken token,
                                  IdType type,
                                  String name,
                                  String serviceName,
                                  SchemaType stype,
                                  Map<String,​Set<String>> attrMap)
                           throws IdRepoException
        Assigns a service to the provided identity. In case of a USER if the attribute map contains objectclasses, then the existing set of objectclasses will be retrieved, and added to those. These settings will override the existing values if any present. In case of a REALM the service attributes will be persisted by the IdRepoListener implementation.
        Specified by:
        assignService in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity. Only used when identity type is USER.
        serviceName - The name of the service that needs to be assigned to the identity.
        stype - The schema type of the service that needs to be assigned.
        attrMap - The service configuration that needs to be saved for the identity.
        Throws:
        IdRepoException - If there was an error while retrieving the user objectclasses, or when the settings were being saved to the identity.
      • getAssignedServices

        public Set<String> getAssignedServices​(SSOToken token,
                                               IdType type,
                                               String name,
                                               Map<String,​Set<String>> mapOfServicesAndOCs)
                                        throws IdRepoException
        Returns the currently assigned to the given identity. In case of a USER this will retrieve the objectclasses defined for this user, and based on the provided mapOfServicesAndOCs if all of the objectclasses mapped to a service is present, only then will the service be added to the resulting list. In case of a REALM the locally stored serviceMap's keySet will be returned, since that contains all the different service names defined within this realm.
        Specified by:
        getAssignedServices in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity. Only used when identity type is USER.
        mapOfServicesAndOCs - A mapping between the names of services and the corresponding objectclasses.
        Returns:
        The list of services that are currently assigned to the identity.
        Throws:
        IdRepoException - If the identity type was invalid, or if there was an error while retrieving the objectclasses.
      • getServiceAttributes

        public Map<String,​Set<String>> getServiceAttributes​(SSOToken token,
                                                                  IdType type,
                                                                  String name,
                                                                  String serviceName,
                                                                  Set<String> attrNames)
                                                           throws IdRepoException
        Returns the service attributes in string format for the given identity.
        Specified by:
        getServiceAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity to query. Only used when identity type is USER.
        serviceName - The name of the service, which in case of USER may be null.
        attrNames - The name of the service attributes that needs to be queried. In case of USER this may NOT be null. In case of REALM, when null this will return all attributes for the service.
        Returns:
        The matching service attributes.
        Throws:
        IdRepoException - If there was an error while retrieving the service attributes from the user, or if the identity type was invalid.
      • getBinaryServiceAttributes

        public Map<String,​byte[][]> getBinaryServiceAttributes​(SSOToken token,
                                                                     IdType type,
                                                                     String name,
                                                                     String serviceName,
                                                                     Set<String> attrNames)
                                                              throws IdRepoException
        Returns the service attributes in binary format for the given identity.
        Specified by:
        getBinaryServiceAttributes in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity to query. Only used when identity type is USER.
        serviceName - The name of the service, which in case of USER may be null.
        attrNames - The name of the service attributes that needs to be queried. In case of USER this may NOT be null. In case of REALM, when null this will return all attributes for the service.
        Returns:
        The matching service attributes.
        Throws:
        IdRepoException - If there was an error while retrieving the service attributes from the user, or if the identity type was invalid.
      • modifyService

        public void modifyService​(SSOToken token,
                                  IdType type,
                                  String name,
                                  String serviceName,
                                  SchemaType sType,
                                  Map<String,​Set<String>> attrMap)
                           throws IdRepoException
        Modifies the service attributes based on the incoming attributeMap. In case of a USER the attributes will be saved in case the schema type is not DYNAMIC. In case of a REALM this will only modify the locally stored Map structure by making sure that non-modified attributes are kept.
        Specified by:
        modifyService in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity. Only used when identity type is USER.
        serviceName - The name of the service that needs to be modified.
        sType - The type of the service schema.
        attrMap - The attributes that needs to be set for the service.
        Throws:
        IdRepoException - If the type was invalid, or if there was an error while setting the service attributes.
      • unassignService

        public void unassignService​(SSOToken token,
                                    IdType type,
                                    String name,
                                    String serviceName,
                                    Map<String,​Set<String>> attrMap)
                             throws IdRepoException
        Unassigns a service from the provided identity. In case of a USER this will traverse through all the existing user attributes and will remove those that are currently present in the entry. This will also remove the objectclass corresponding to the service. In case of a REALM this will remove the service from the locally cached serviceMap, and will notify the registered IdRepoListener.
        Specified by:
        unassignService in class IdRepo
        Parameters:
        token - Not used.
        type - The type of the identity, this should be always USER or REALM.
        name - The name of the identity. Only used when identity type is USER.
        serviceName - The name of the service to remove from the identity.
        attrMap - Holds the objectclasses relevant for this service removal.
        Throws:
        IdRepoException - If the identity type was invalid or if there was an error while removing the service.
      • addListener

        public int addListener​(SSOToken token,
                               IdRepoListener idRepoListener)
        Registers an IdRepoListener, which will be notified of realm level service changes and persistent search results. If persistent search is not yet established with the current settings, this will create a new persistent search against the configured directory.
        Specified by:
        addListener in class IdRepo
        Parameters:
        token - Not used.
        idRepoListener - The IdRepoListener that will be used to notify about service changes and persistent search results.
        Returns:
        Always returns 0.
      • removeListener

        public void removeListener()
        This method will be called by the end of the IdRepo's lifetime, and makes sure that persistent search is properly terminated for this IdRepo.
        Specified by:
        removeListener in class IdRepo
      • shutdown

        public void shutdown()
        This method is being invoked during OpenAM shutdown and also when the configuration changes and OpenAM needs to reload the Data Store configuration. This mechanism will make sure that the connection pools are closed, and the persistent search is also terminated (if there is no other data store implementation using the same psearch connection.
        Overrides:
        shutdown in class IdRepo
      • identityMovedOrRenamed

        public void identityMovedOrRenamed​(org.forgerock.opendj.ldap.DN previousDN)
        Called if an identity has been renamed or moved within the identity store.
        Specified by:
        identityMovedOrRenamed in interface IdentityMovedOrRenamedListener
        Parameters:
        previousDN - The DN of the identity before the move or rename
      • constructFilter

        protected org.forgerock.opendj.ldap.Filter constructFilter​(int operation,
                                                                   Map<String,​Set<String>> attributes)