Package org.keycloak.storage.ldap
Class LDAPStorageProvider
- java.lang.Object
- 
- org.keycloak.storage.ldap.LDAPStorageProvider
 
- 
- All Implemented Interfaces:
- CredentialAuthentication,- CredentialInputUpdater,- CredentialInputValidator,- Provider,- ImportedUserValidation,- UserLookupProvider,- UserQueryProvider,- UserRegistrationProvider,- UserStorageProvider
 
 public class LDAPStorageProvider extends Object implements UserStorageProvider, CredentialInputValidator, CredentialInputUpdater, CredentialAuthentication, UserLookupProvider, UserRegistrationProvider, UserQueryProvider, ImportedUserValidation - Version:
- $Revision: 1 $
- Author:
- Marek Posolda, Bill Burke
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.keycloak.credential.CredentialInputUpdaterCredentialInputUpdater.Streams
 - 
Nested classes/interfaces inherited from interface org.keycloak.storage.user.UserLookupProviderUserLookupProvider.Streams
 - 
Nested classes/interfaces inherited from interface org.keycloak.storage.user.UserQueryProviderUserQueryProvider.Streams
 - 
Nested classes/interfaces inherited from interface org.keycloak.storage.UserStorageProviderUserStorageProvider.EditMode
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected UserStorageProvider.EditModeeditModeprotected LDAPStorageProviderFactoryfactoryprotected LDAPProviderKerberosConfigkerberosConfigprotected LDAPIdentityStoreldapIdentityStoreprotected LDAPStorageMapperManagermapperManagerprotected UserStorageProviderModelmodelprotected KeycloakSessionsessionprotected Set<String>supportedCredentialTypesprotected PasswordUpdateCallbackupdaterprotected LDAPStorageUserManageruserManager
 - 
Constructor SummaryConstructors Constructor Description LDAPStorageProvider(LDAPStorageProviderFactory factory, KeycloakSession session, ComponentModel model, LDAPIdentityStore ldapIdentityStore)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description UserModeladdUser(RealmModel realm, String username)All storage providers that implement this interface will be looped through.CredentialValidationOutputauthenticate(RealmModel realm, CredentialInput cred)voidclose()voiddisableCredentialType(RealmModel realm, UserModel user, String credentialType)protected UserModelfindOrCreateAuthenticatedUser(RealmModel realm, String username)Called after successful kerberos authenticationStream<String>getDisableableCredentialTypesStream(RealmModel realm, UserModel user)Obtains the set of credential types that can be disabled viadisableCredentialType.UserStorageProvider.EditModegetEditMode()Stream<UserModel>getGroupMembersStream(RealmModel realm, GroupModel group, Integer firstResult, Integer maxResults)Obtains users that belong to a specific group.LDAPIdentityStoregetLdapIdentityStore()LDAPStorageMapperManagergetMapperManager()UserStorageProviderModelgetModel()Stream<UserModel>getRoleMembersStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults)Searches for users that have the specified role.KeycloakSessiongetSession()Set<String>getSupportedCredentialTypes()UserModelgetUserByEmail(RealmModel realm, String email)Returns a user with the given email belonging to the realmUserModelgetUserById(RealmModel realm, String id)Returns a user with the given id belonging to the realmUserModelgetUserByUsername(RealmModel realm, String username)Exact search for a user by its username.LDAPStorageUserManagergetUserManager()intgetUsersCount(RealmModel realm)Returns the number of users, without consider any service account.Stream<UserModel>getUsersStream(RealmModel realm)Searches all users in the realm.Stream<UserModel>getUsersStream(RealmModel realm, Integer firstResult, Integer maxResults)Searches all users in the realm, starting from thefirstResultand containing at mostmaxResults.protected UserModelimportUserFromLDAP(KeycloakSession session, RealmModel realm, LDAPObject ldapUser)booleanisConfiguredFor(RealmModel realm, UserModel user, String credentialType)booleanisValid(RealmModel realm, UserModel user, CredentialInput input)Tests whether a credential is validprotected LDAPObjectloadAndValidateUser(RealmModel realm, UserModel local)LDAPObjectloadLDAPUserByUsername(RealmModel realm, String username)LDAPObjectloadLDAPUserByUuid(RealmModel realm, String uuid)List<UserModel>loadUsersByUsernames(List<String> usernames, RealmModel realm)voidpreRemove(RealmModel realm)Callback when a realm is removed.voidpreRemove(RealmModel realm, GroupModel group)Callback when a group is removed.voidpreRemove(RealmModel realm, RoleModel role)Callback when a role is removed.protected UserModelproxy(RealmModel realm, UserModel local, LDAPObject ldapObject, boolean newUser)protected LDAPObjectqueryByEmail(RealmModel realm, String email)booleanremoveUser(RealmModel realm, UserModel user)Called if user originated from this provider.Stream<UserModel>searchForUserByUserAttributeStream(RealmModel realm, String attrName, String attrValue)Searches for users that have a specific attribute with a specific value.Stream<UserModel>searchForUserStream(RealmModel realm, String search, Integer firstResult, Integer maxResults)Searches for users whose username, email, first name or last name contain any of the strings insearchseparated by whitespace.Stream<UserModel>searchForUserStream(RealmModel realm, Map<String,String> params, Integer firstResult, Integer maxResults)Searches for user by parameter.protected List<LDAPObject>searchLDAP(RealmModel realm, Map<String,String> attributes)voidsetUpdater(PasswordUpdateCallback updater)booleansupportsCredentialAuthenticationFor(String type)booleansupportsCredentialType(String credentialType)booleansynchronizeRegistrations()booleanupdateCredential(RealmModel realm, UserModel user, CredentialInput input)UserModelvalidate(RealmModel realm, UserModel local)If this method returns null, then the user in local storage will be removedbooleanvalidPassword(RealmModel realm, UserModel user, String password)- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.storage.user.UserLookupProvidergetUserByCredential
 - 
Methods inherited from interface org.keycloak.storage.user.UserQueryProvidergetGroupMembersStream, getRoleMembersStream, getUsersCount, getUsersCount, getUsersCount, getUsersCount, getUsersCount, getUsersCount, searchForUserStream, searchForUserStream
 
- 
 
- 
- 
- 
Field Detail- 
factoryprotected LDAPStorageProviderFactory factory 
 - 
sessionprotected KeycloakSession session 
 - 
modelprotected UserStorageProviderModel model 
 - 
ldapIdentityStoreprotected LDAPIdentityStore ldapIdentityStore 
 - 
editModeprotected UserStorageProvider.EditMode editMode 
 - 
kerberosConfigprotected LDAPProviderKerberosConfig kerberosConfig 
 - 
updaterprotected PasswordUpdateCallback updater 
 - 
mapperManagerprotected LDAPStorageMapperManager mapperManager 
 - 
userManagerprotected LDAPStorageUserManager userManager 
 
- 
 - 
Constructor Detail- 
LDAPStorageProviderpublic LDAPStorageProvider(LDAPStorageProviderFactory factory, KeycloakSession session, ComponentModel model, LDAPIdentityStore ldapIdentityStore) 
 
- 
 - 
Method Detail- 
setUpdaterpublic void setUpdater(PasswordUpdateCallback updater) 
 - 
getSessionpublic KeycloakSession getSession() 
 - 
getLdapIdentityStorepublic LDAPIdentityStore getLdapIdentityStore() 
 - 
getEditModepublic UserStorageProvider.EditMode getEditMode() 
 - 
getModelpublic UserStorageProviderModel getModel() 
 - 
getMapperManagerpublic LDAPStorageMapperManager getMapperManager() 
 - 
getUserManagerpublic LDAPStorageUserManager getUserManager() 
 - 
validatepublic UserModel validate(RealmModel realm, UserModel local) Description copied from interface:ImportedUserValidationIf this method returns null, then the user in local storage will be removed- Specified by:
- validatein interface- ImportedUserValidation
- Returns:
- null if user no longer valid
 
 - 
proxyprotected UserModel proxy(RealmModel realm, UserModel local, LDAPObject ldapObject, boolean newUser) 
 - 
supportsCredentialAuthenticationForpublic boolean supportsCredentialAuthenticationFor(String type) - Specified by:
- supportsCredentialAuthenticationForin interface- CredentialAuthentication
 
 - 
searchForUserByUserAttributeStreampublic Stream<UserModel> searchForUserByUserAttributeStream(RealmModel realm, String attrName, String attrValue) Description copied from interface:UserQueryProviderSearches for users that have a specific attribute with a specific value.- Specified by:
- searchForUserByUserAttributeStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- attrName- the attribute name.
- attrValue- the attribute value.
- Returns:
- a non-null Streamof users that match the search criteria.
 
 - 
synchronizeRegistrationspublic boolean synchronizeRegistrations() 
 - 
addUserpublic UserModel addUser(RealmModel realm, String username) Description copied from interface:UserRegistrationProviderAll storage providers that implement this interface will be looped through. If this method returns null, then the next storage provider's addUser() method will be called. If no storage providers handle the add, then the user will be created in local storage. Returning null is useful when you want optional support for adding users. For example, our LDAP provider can enable and disable the ability to add users.- Specified by:
- addUserin interface- UserRegistrationProvider
- Parameters:
- realm- a reference to the realm
- username- a username the created user will be assigned
- Returns:
- a model of created user
 
 - 
removeUserpublic boolean removeUser(RealmModel realm, UserModel user) Description copied from interface:UserRegistrationProviderCalled if user originated from this provider. If a local user is linked to this provider, this method will be called before local storage's removeUser() method is invoked. If you are using an import strategy, and this is a local user linked to this provider, this method will be called before local storage's removeUser() method is invoked. Also, you DO NOT need to remove the imported user. The runtime will handle this for you.- Specified by:
- removeUserin interface- UserRegistrationProvider
- Parameters:
- realm- a reference to the realm
- user- a reference to the user that is removed
- Returns:
- true if the user was removed, false otherwise
 
 - 
getUserByIdpublic UserModel getUserById(RealmModel realm, String id) Description copied from interface:UserLookupProviderReturns a user with the given id belonging to the realm- Specified by:
- getUserByIdin interface- UserLookupProvider
- Parameters:
- realm- the realm model
- id- id of the user
- Returns:
- found user model, or nullif no such user exists
 
 - 
getUsersCountpublic int getUsersCount(RealmModel realm) Description copied from interface:UserQueryProviderReturns the number of users, without consider any service account.- Specified by:
- getUsersCountin interface- UserQueryProvider
- Parameters:
- realm- the realm
- Returns:
- the number of users
 
 - 
getUsersStreampublic Stream<UserModel> getUsersStream(RealmModel realm) Description copied from interface:UserQueryProviderSearches all users in the realm.- Specified by:
- getUsersStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- Returns:
- a non-null Streamof users.
 
 - 
getUsersStreampublic Stream<UserModel> getUsersStream(RealmModel realm, Integer firstResult, Integer maxResults) Description copied from interface:UserQueryProviderSearches all users in the realm, starting from thefirstResultand containing at mostmaxResults.- Specified by:
- getUsersStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- firstResult- first result to return. Ignored if negative or- null.
- maxResults- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof users.
 
 - 
searchForUserStreampublic Stream<UserModel> searchForUserStream(RealmModel realm, String search, Integer firstResult, Integer maxResults) Description copied from interface:UserQueryProviderSearches for users whose username, email, first name or last name contain any of the strings insearchseparated by whitespace. If possible, implementations should treat the parameter values as partial match patterns (i.e. in RDMBS terms use LIKE). This method is used by the admin console search box- Specified by:
- searchForUserStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- search- case insensitive list of string separated by whitespaces.
- firstResult- first result to return. Ignored if negative, zero, or- null.
- maxResults- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof users that match the search criteria.
 
 - 
searchForUserStreampublic Stream<UserModel> searchForUserStream(RealmModel realm, Map<String,String> params, Integer firstResult, Integer maxResults) Description copied from interface:UserQueryProviderSearches for user by parameter. If possible, implementations should treat the parameter values as partial match patterns (i.e. in RDMBS terms use LIKE). Valid parameters are:- UserModel.FIRST_NAME- first name (case insensitive string)
- UserModel.LAST_NAME- last name (case insensitive string)
- UserModel.EMAIL- email (case insensitive string)
- UserModel.USERNAME- username (case insensitive string)
- UserModel.EMAIL_VERIFIED- search only for users with verified/non-verified email (true/false)
- UserModel.ENABLED- search only for enabled/disabled users (true/false)
- UserModel.IDP_ALIAS- search only for users that have a federated identity from idp with the given alias configured (case sensitive string)
- UserModel.IDP_USER_ID- search for users with federated identity with the given userId (case sensitive string)
 - Specified by:
- searchForUserStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- params- a map containing the search parameters.
- firstResult- first result to return. Ignored if negative, zero, or- null.
- maxResults- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof users that match the search criteria.
 
 - 
getGroupMembersStreampublic Stream<UserModel> getGroupMembersStream(RealmModel realm, GroupModel group, Integer firstResult, Integer maxResults) Description copied from interface:UserQueryProviderObtains users that belong to a specific group.- Specified by:
- getGroupMembersStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- group- a reference to the group.
- firstResult- first result to return. Ignored if negative, zero, or- null.
- maxResults- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof users that belong to the group.
 
 - 
getRoleMembersStreampublic Stream<UserModel> getRoleMembersStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults) Description copied from interface:UserQueryProviderSearches for users that have the specified role.- Specified by:
- getRoleMembersStreamin interface- UserQueryProvider
- Parameters:
- realm- a reference to the realm.
- role- a reference to the role.
- firstResult- first result to return. Ignored if negative or- null.
- maxResults- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof users that have the specified role.
 
 - 
loadUsersByUsernamespublic List<UserModel> loadUsersByUsernames(List<String> usernames, RealmModel realm) 
 - 
searchLDAPprotected List<LDAPObject> searchLDAP(RealmModel realm, Map<String,String> attributes) 
 - 
loadAndValidateUserprotected LDAPObject loadAndValidateUser(RealmModel realm, UserModel local) - Parameters:
- local-
- Returns:
- ldapUser corresponding to local user or null if user is no longer in LDAP
 
 - 
getUserByUsernamepublic UserModel getUserByUsername(RealmModel realm, String username) Description copied from interface:UserLookupProviderExact search for a user by its username. Returns a user with the given username belonging to the realm- Specified by:
- getUserByUsernamein interface- UserLookupProvider
- Parameters:
- realm- the realm model
- username- (case-sensitivity is controlled by storage)
- Returns:
- found user model, or nullif no such user exists
 
 - 
importUserFromLDAPprotected UserModel importUserFromLDAP(KeycloakSession session, RealmModel realm, LDAPObject ldapUser) 
 - 
queryByEmailprotected LDAPObject queryByEmail(RealmModel realm, String email) 
 - 
getUserByEmailpublic UserModel getUserByEmail(RealmModel realm, String email) Description copied from interface:UserLookupProviderReturns a user with the given email belonging to the realm- Specified by:
- getUserByEmailin interface- UserLookupProvider
- Parameters:
- realm- the realm model
- email- email address
- Returns:
- found user model, or nullif no such user exists
 
 - 
preRemovepublic void preRemove(RealmModel realm) Description copied from interface:UserStorageProviderCallback when a realm is removed. Implement this if, for example, you want to do some cleanup in your user storage when a realm is removed- Specified by:
- preRemovein interface- UserStorageProvider
 
 - 
preRemovepublic void preRemove(RealmModel realm, RoleModel role) Description copied from interface:UserStorageProviderCallback when a role is removed. Allows you to do things like remove a user role mapping in your external store if appropriate- Specified by:
- preRemovein interface- UserStorageProvider
 
 - 
preRemovepublic void preRemove(RealmModel realm, GroupModel group) Description copied from interface:UserStorageProviderCallback when a group is removed. Allows you to do things like remove a user group mapping in your external store if appropriate- Specified by:
- preRemovein interface- UserStorageProvider
 
 - 
validPasswordpublic boolean validPassword(RealmModel realm, UserModel user, String password) 
 - 
updateCredentialpublic boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) - Specified by:
- updateCredentialin interface- CredentialInputUpdater
 
 - 
disableCredentialTypepublic void disableCredentialType(RealmModel realm, UserModel user, String credentialType) - Specified by:
- disableCredentialTypein interface- CredentialInputUpdater
 
 - 
getDisableableCredentialTypesStreampublic Stream<String> getDisableableCredentialTypesStream(RealmModel realm, UserModel user) Description copied from interface:CredentialInputUpdaterObtains the set of credential types that can be disabled viadisableCredentialType.- Specified by:
- getDisableableCredentialTypesStreamin interface- CredentialInputUpdater
- Parameters:
- realm- a reference to the realm.
- user- the user whose credentials are being searched.
- Returns:
- a non-null Streamof credential types.
 
 - 
supportsCredentialTypepublic boolean supportsCredentialType(String credentialType) - Specified by:
- supportsCredentialTypein interface- CredentialInputUpdater
- Specified by:
- supportsCredentialTypein interface- CredentialInputValidator
 
 - 
isConfiguredForpublic boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) - Specified by:
- isConfiguredForin interface- CredentialInputValidator
 
 - 
isValidpublic boolean isValid(RealmModel realm, UserModel user, CredentialInput input) Description copied from interface:CredentialInputValidatorTests whether a credential is valid- Specified by:
- isValidin interface- CredentialInputValidator
- Parameters:
- realm- The realm in which to which the credential belongs to
- user- The user for which to test the credential
- input- the credential details to verify
- Returns:
- true if the passed secret is correct
 
 - 
authenticatepublic CredentialValidationOutput authenticate(RealmModel realm, CredentialInput cred) - Specified by:
- authenticatein interface- CredentialAuthentication
 
 - 
findOrCreateAuthenticatedUserprotected UserModel findOrCreateAuthenticatedUser(RealmModel realm, String username) Called after successful kerberos authentication- Parameters:
- realm- realm
- username- username without realm prefix
- Returns:
- finded or newly created user
 
 - 
loadLDAPUserByUsernamepublic LDAPObject loadLDAPUserByUsername(RealmModel realm, String username) 
 - 
loadLDAPUserByUuidpublic LDAPObject loadLDAPUserByUuid(RealmModel realm, String uuid) 
 
- 
 
-