Package org.forgerock.openam.idrepo.ldap
Class DJLDAPv3Repo
- java.lang.Object
-
- com.sun.identity.idm.IdRepo
-
- org.forgerock.openam.idrepo.ldap.DJLDAPv3Repo
-
- All Implemented Interfaces:
IdentityMovedOrRenamedListener
public class DJLDAPv3Repo extends IdRepo implements IdentityMovedOrRenamedListener
This is an IdRepo implementation that utilizes the LDAP protocol via OpenDJ LDAP SDK to access directory servers.
-
-
Constructor Summary
Constructors Constructor Description DJLDAPv3Repo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddListener(SSOToken token, IdRepoListener idRepoListener)Registers an IdRepoListener, which will be notified of realm level service changes and persistent search results.voidassignService(SSOToken token, IdType type, String name, String serviceName, SchemaType stype, Map<String,Set<String>> attrMap)Assigns a service to the provided identity.booleanauthenticate(Callback[] credentials)Tries to bind as the user with the credentials passed in via callbacks.voidchangePassword(SSOToken token, IdType type, String name, String attrName, String oldPassword, String newPassword)Changes password for the given identity by binding as the user first (i.e. this is not password reset).protected org.forgerock.opendj.ldap.FilterconstructFilter(int operation, Map<String,Set<String>> attributes)Stringcreate(SSOToken token, IdType type, String name, Map<String,Set<String>> attrMap)Creates a new identity using the passed in attributes.protected ConnectionFactory<org.forgerock.opendj.ldap.Connection>createConnectionFactory(String username, char[] password, int maxPoolSize)voiddelete(SSOToken token, IdType type, String name)Deletes the identity from the directory.Set<String>getAssignedServices(SSOToken token, IdType type, String name, Map<String,Set<String>> mapOfServicesAndOCs)Returns the currently assigned to the given identity.Map<String,Set<String>>getAttributes(SSOToken token, IdType type, String name)Returns all the attributes that are defined in the configuration for the given identity.Map<String,Set<String>>getAttributes(SSOToken token, IdType type, String name, Set<String> attrNames)Returns all the requested attributes that are defined in the configuration for this given identity.Map<String,byte[][]>getBinaryAttributes(SSOToken token, IdType type, String name, Set<String> attrNames)Returns all the requested binary attributes that are defined in the configuration for this given identity.Map<String,byte[][]>getBinaryServiceAttributes(SSOToken token, IdType type, String name, String serviceName, Set<String> attrNames)Returns the service attributes in binary format for the given identity.protected org.forgerock.opendj.ldap.FiltergetFilter(IdType type, CrestQuery crestQuery, int filterOp, Map<String,Set<String>> avPairs)StringgetFullyQualifiedName(SSOToken token, IdType type, String name)Returns a fully qualified name of the identity, which should be unique per data store.Set<String>getMembers(SSOToken token, IdType type, String name, IdType membersType)Gets membership data for a given group/role/filtered role.Set<String>getMemberships(SSOToken token, IdType type, String name, IdType membershipType)Returns the membership information of a user for the given membership type.protected org.forgerock.opendj.ldap.schema.SchemagetSchema()Map<String,Set<String>>getServiceAttributes(SSOToken token, IdType type, String name, String serviceName, Set<String> attrNames)Returns the service attributes in string format for the given identity.Set<IdOperation>getSupportedOperations(IdType type)Returns the set of supported operations for a given identity type.Set<IdType>getSupportedTypes()Returns the set of supported identity types.voididentityMovedOrRenamed(org.forgerock.opendj.ldap.DN previousDN)Called if an identity has been renamed or moved within the identity store.voidinitialize(Map<String,Set<String>> configParams)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.booleanisActive(SSOToken token, IdType type, String name)Tells whether the given identity is considered as "active" or not.booleanisExists(SSOToken token, IdType type, String name)Tells whether a given identity exists or not.voidmodifyMemberShip(SSOToken token, IdType type, String name, Set<String> members, IdType membersType, int operation)Adds or removes members to the provided group/role.voidmodifyService(SSOToken token, IdType type, String name, String serviceName, SchemaType sType, Map<String,Set<String>> attrMap)Modifies the service attributes based on the incoming attributeMap.voidremoveAttributes(SSOToken token, IdType type, String name, Set<String> attrNames)Removes the specified attributes from the identity.voidremoveListener()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.RepoSearchResultssearch(SSOToken token, IdType type, CrestQuery crestQuery, int maxTime, int maxResults, Set<String> returnAttrs, boolean returnAllAttrs, int filterOp, Map<String,Set<String>> avPairs, boolean recursive)Performs a search in the directory based on the provided parameters.voidsetActiveStatus(SSOToken token, IdType type, String name, boolean active)Sets the user status to the value provided for the given identity.voidsetAttributes(SSOToken token, IdType type, String name, Map<String,Set<String>> attributes, boolean isAdd)Sets the provided attributes for the given identity.voidsetBinaryAttributes(SSOToken token, IdType type, String name, Map<String,byte[][]> attributes, boolean isAdd)Sets the provided binary attributes for the given identity.voidshutdown()This method is being invoked during OpenAM shutdown and also when the configuration changes and OpenAM needs to reload the Data Store configuration.booleansupportsAuthentication()Tells whether this identity repository supports authentication.voidunassignService(SSOToken token, IdType type, String name, String serviceName, Map<String,Set<String>> attrMap)Unassigns a service from the provided identity.-
Methods inherited from class com.sun.identity.idm.IdRepo
getConfiguration
-
-
-
-
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:
initializein classIdRepo- 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:
supportsAuthenticationin classIdRepo- Returns:
truesince 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:
authenticatein classIdRepo- Parameters:
credentials- The username/password combination.- Returns:
trueif 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:
changePasswordin classIdRepo- 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:
getFullyQualifiedNamein classIdRepo- Parameters:
token- Not used.type- The type of the identity.name- The name of the identity.- Returns:
- Fully qualified name of this identity or
nullif 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:
getSupportedOperationsin classIdRepo- 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:
getSupportedTypesin classIdRepo- 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:
setActiveStatusin classIdRepo- 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 returntrue. 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:
isActivein classIdRepo- Parameters:
token- Not used.type- The type of the identity, this should be always USER.name- The name of the identity.- Returns:
trueif 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 returnfalse.- 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:
isExistsin classIdRepo- Parameters:
token- Not used.type- The type of the identity.name- The name of the identity.- Returns:
trueif 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.
- Specified by:
createin classIdRepo- 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:
getAttributesin classIdRepo- 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:
getAttributesin classIdRepo- Parameters:
token- Not used.type- The type of the identity.name- The name of the identity.attrNames- The names of the requested attributes ornullto 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:
getBinaryAttributesin classIdRepo- Parameters:
token- Not used.type- The type of the identity.name- The name of the identity.attrNames- The names of the requested binary attributes ornullto 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:
setAttributesin classIdRepo- 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-trueif the attributes should be ADDed,falseif 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:
setBinaryAttributesin classIdRepo- 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-trueif the attributes should be ADDed,falseif 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:
removeAttributesin classIdRepo- 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:
searchin classIdRepo- 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 _queryFiltermaxTime- 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-trueif all user attribute should be returned.filterOp- When avPairs is provided, this logical operation will be used between them. UseIdRepo.AND_MODorIdRepo.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.
-
getFilter
protected org.forgerock.opendj.ldap.Filter getFilter(IdType type, CrestQuery crestQuery, int filterOp, Map<String,Set<String>> avPairs)
-
delete
public void delete(SSOToken token, IdType type, String name) throws IdRepoException
Deletes the identity from the directory.- Specified by:
deletein classIdRepo- 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:
getMembersin classIdRepo- 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:
getMembershipsin classIdRepo- 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:
modifyMemberShipin classIdRepo- 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. UseIdRepo.ADDMEMBERandIdRepo.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 theIdRepoListenerimplementation.- Specified by:
assignServicein classIdRepo- 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:
getAssignedServicesin classIdRepo- 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:
getServiceAttributesin classIdRepo- 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:
getBinaryServiceAttributesin classIdRepo- 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:
modifyServicein classIdRepo- 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 registeredIdRepoListener.- Specified by:
unassignServicein classIdRepo- 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:
addListenerin classIdRepo- 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:
removeListenerin classIdRepo
-
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.
-
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:
identityMovedOrRenamedin interfaceIdentityMovedOrRenamedListener- 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)
-
getSchema
protected org.forgerock.opendj.ldap.schema.Schema getSchema() throws IdRepoException- Throws:
IdRepoException
-
-