org.keycloak.models.mongo.keycloak.adapters

## Class MongoUserProvider

- java.lang.Object
- - org.keycloak.models.mongo.keycloak.adapters.MongoUserProvider

- All Implemented Interfaces:
    UserProvider, Provider, UserCredentialValidatorProvider, UserLookupProvider, UserQueryProvider, UserRegistrationProvider

      public class MongoUserProvider
      extends Object
      implements UserProvider

  Author:
    Marek Posolda

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MongoUserProvider(KeycloakSession session, MongoStoreInvocationContext invocationContext)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addConsent(RealmModel realm, UserModel user, UserConsentModel consent)`
    `void` | `addFederatedIdentity(RealmModel realm, UserModel user, FederatedIdentityModel identity)`
    `UserModel` | `addUser(RealmModel realm, String username)`
    `UserAdapter` | `addUser(RealmModel realm, String id, String username, boolean addDefaultRoles, boolean addDefaultRequiredActions)` only used for local storage
    `protected UserAdapter` | `addUserEntity(RealmModel realm, String id, String username)`
    `void` | `close()`
    `protected List<UserModel>` | `convertUserEntities(RealmModel realm, List<MongoUserEntity> userEntities)`
    `UserConsentModel` | `getConsentByClient(RealmModel realm, UserModel user, String clientId)`
    `List<UserConsentModel>` | `getConsents(RealmModel realm, UserModel user)`
    `Set<FederatedIdentityModel>` | `getFederatedIdentities(UserModel userModel, RealmModel realm)`
    `FederatedIdentityModel` | `getFederatedIdentity(UserModel user, String socialProvider, RealmModel realm)`
    `List<UserModel>` | `getGroupMembers(RealmModel realm, GroupModel group)`
    `List<UserModel>` | `getGroupMembers(RealmModel realm, GroupModel group, int firstResult, int maxResults)`
    `protected MongoStore` | `getMongoStore()`
    `UserModel` | `getServiceAccount(ClientModel client)`
    `UserModel` | `getUserByEmail(String email, RealmModel realm)`
    `UserModel` | `getUserByFederatedIdentity(FederatedIdentityModel socialLink, RealmModel realm)`
    `UserAdapter` | `getUserById(String id, RealmModel realm)`
    `UserModel` | `getUserByUsername(String username, RealmModel realm)`
    `List<UserModel>` | `getUsers(RealmModel realm)`
    `List<UserModel>` | `getUsers(RealmModel realm, boolean includeServiceAccounts)`
    `List<UserModel>` | `getUsers(RealmModel realm, int firstResult, int maxResults)`
    `List<UserModel>` | `getUsers(RealmModel realm, int firstResult, int maxResults, boolean includeServiceAccounts)`
    `int` | `getUsersCount(RealmModel realm)`
    `void` | `grantToAllUsers(RealmModel realm, RoleModel role)`
    `void` | `preRemove(ProtocolMapperModel protocolMapper)`
    `void` | `preRemove(RealmModel realm)`
    `void` | `preRemove(RealmModel realm, ClientModel client)`
    `void` | `preRemove(RealmModel realm, ComponentModel component)`
    `void` | `preRemove(RealmModel realm, GroupModel group)`
    `void` | `preRemove(RealmModel realm, RoleModel role)`
    `void` | `preRemove(RealmModel realm, UserFederationProviderModel link)`
    `boolean` | `removeFederatedIdentity(RealmModel realm, UserModel userModel, String socialProvider)`
    `boolean` | `removeUser(RealmModel realm, UserModel user)`
    `boolean` | `revokeConsentForClient(RealmModel realm, UserModel user, String clientId)`
    `List<UserModel>` | `searchForUser(Map<String,String> attributes, RealmModel realm)` Search for user by parameter.
    `List<UserModel>` | `searchForUser(Map<String,String> attributes, RealmModel realm, int firstResult, int maxResults)` Search for user by parameter.
    `List<UserModel>` | `searchForUser(String search, RealmModel realm)` Search for users with username, email or first + last name that is like search string.
    `List<UserModel>` | `searchForUser(String search, RealmModel realm, int firstResult, int maxResults)` Search for users with username, email or first + last name that is like search string.
    `List<UserModel>` | `searchForUserByUserAttribute(String attrName, String attrValue, RealmModel realm)`
    `void` | `updateConsent(RealmModel realm, UserModel user, UserConsentModel consent)`
    `void` | `updateFederatedIdentity(RealmModel realm, UserModel federatedUser, FederatedIdentityModel federatedIdentityModel)`
    `CredentialValidationOutput` | `validCredentials(KeycloakSession session, RealmModel realm, UserCredentialModel... input)`
    `boolean` | `validCredentials(KeycloakSession session, RealmModel realm, UserModel user, List<UserCredentialModel> input)`
    `boolean` | `validCredentials(KeycloakSession session, RealmModel realm, UserModel user, UserCredentialModel... input)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MongoUserProvider

          public MongoUserProvider(KeycloakSession session,
                                   MongoStoreInvocationContext invocationContext)

  - ### Method Detail

    - #### close

          public void close()

      Specified by:
        `close` in interface `UserProvider`
      Specified by:
        `close` in interface `Provider`

    - #### getUserById

          public UserAdapter getUserById(String id,
                                         RealmModel realm)

      Specified by:
        `getUserById` in interface `UserLookupProvider`

    - #### getUserByUsername

          public UserModel getUserByUsername(String username,
                                             RealmModel realm)

      Specified by:
        `getUserByUsername` in interface `UserLookupProvider`

    - #### getUserByEmail

          public UserModel getUserByEmail(String email,
                                          RealmModel realm)

      Specified by:
        `getUserByEmail` in interface `UserLookupProvider`

    - #### getGroupMembers

          public List<UserModel> getGroupMembers(RealmModel realm,
                                                 GroupModel group,
                                                 int firstResult,
                                                 int maxResults)

      Specified by:
        `getGroupMembers` in interface `UserQueryProvider`

    - #### getMongoStore

          protected MongoStore getMongoStore()

    - #### getGroupMembers

          public List<UserModel> getGroupMembers(RealmModel realm,
                                                 GroupModel group)

      Specified by:
        `getGroupMembers` in interface `UserQueryProvider`

    - #### getUserByFederatedIdentity

          public UserModel getUserByFederatedIdentity(FederatedIdentityModel socialLink,
                                                      RealmModel realm)

      Specified by:
        `getUserByFederatedIdentity` in interface `UserProvider`

    - #### getServiceAccount

          public UserModel getServiceAccount(ClientModel client)

      Specified by:
        `getServiceAccount` in interface `UserProvider`

    - #### convertUserEntities

          protected List<UserModel> convertUserEntities(RealmModel realm,
                                                        List<MongoUserEntity> userEntities)

    - #### getUsers

          public List<UserModel> getUsers(RealmModel realm)

      Specified by:
        `getUsers` in interface `UserQueryProvider`

    - #### getUsers

          public List<UserModel> getUsers(RealmModel realm,
                                          int firstResult,
                                          int maxResults)

      Specified by:
        `getUsers` in interface `UserQueryProvider`

    - #### getUsers

          public List<UserModel> getUsers(RealmModel realm,
                                          boolean includeServiceAccounts)

      Specified by:
        `getUsers` in interface `UserProvider`

    - #### getUsersCount

          public int getUsersCount(RealmModel realm)

      Specified by:
        `getUsersCount` in interface `UserQueryProvider`

    - #### getUsers

          public List<UserModel> getUsers(RealmModel realm,
                                          int firstResult,
                                          int maxResults,
                                          boolean includeServiceAccounts)

      Specified by:
        `getUsers` in interface `UserProvider`

    - #### searchForUser

          public List<UserModel> searchForUser(String search,
                                               RealmModel realm)

      Description copied from interface: `UserQueryProvider`
      Search for users with username, email or first + last name that is like search string. 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:
        `searchForUser` in interface `UserQueryProvider`
      Returns:

    - #### searchForUser

          public List<UserModel> searchForUser(String search,
                                               RealmModel realm,
                                               int firstResult,
                                               int maxResults)

      Description copied from interface: `UserQueryProvider`
      Search for users with username, email or first + last name that is like search string. 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:
        `searchForUser` in interface `UserQueryProvider`
      Returns:

    - #### searchForUser

          public List<UserModel> searchForUser(Map<String,String> attributes,
                                               RealmModel realm)

      Description copied from interface: `UserQueryProvider`
      Search for user by parameter. Valid parameters are: "first" - first name "last" - last name "email" - email "username" - username 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 REST API when querying users.
      Specified by:
        `searchForUser` in interface `UserQueryProvider`
      Returns:

    - #### searchForUser

          public List<UserModel> searchForUser(Map<String,String> attributes,
                                               RealmModel realm,
                                               int firstResult,
                                               int maxResults)

      Description copied from interface: `UserQueryProvider`
      Search for user by parameter. Valid parameters are: "first" - first name "last" - last name "email" - email "username" - username If possible, implementations should treat the parameter values as patterns i.e. in RDMBS terms use LIKE. This method is used by the REST API when querying users.
      Specified by:
        `searchForUser` in interface `UserQueryProvider`
      Returns:

    - #### searchForUserByUserAttribute

          public List<UserModel> searchForUserByUserAttribute(String attrName,
                                                              String attrValue,
                                                              RealmModel realm)

      Specified by:
        `searchForUserByUserAttribute` in interface `UserQueryProvider`

    - #### getFederatedIdentities

          public Set<FederatedIdentityModel> getFederatedIdentities(UserModel userModel,
                                                                    RealmModel realm)

      Specified by:
        `getFederatedIdentities` in interface `UserProvider`

    - #### getFederatedIdentity

          public FederatedIdentityModel getFederatedIdentity(UserModel user,
                                                             String socialProvider,
                                                             RealmModel realm)

      Specified by:
        `getFederatedIdentity` in interface `UserProvider`

    - #### addUser

          public UserAdapter addUser(RealmModel realm,
                                     String id,
                                     String username,
                                     boolean addDefaultRoles,
                                     boolean addDefaultRequiredActions)

      Description copied from interface: `UserProvider`
      only used for local storage
      Specified by:
        `addUser` in interface `UserProvider`
      Returns:

    - #### addUserEntity

          protected UserAdapter addUserEntity(RealmModel realm,
                                              String id,
                                              String username)

    - #### removeUser

          public boolean removeUser(RealmModel realm,
                                    UserModel user)

      Specified by:
        `removeUser` in interface `UserRegistrationProvider`

    - #### addFederatedIdentity

          public void addFederatedIdentity(RealmModel realm,
                                           UserModel user,
                                           FederatedIdentityModel identity)

      Specified by:
        `addFederatedIdentity` in interface `UserProvider`

    - #### updateFederatedIdentity

          public void updateFederatedIdentity(RealmModel realm,
                                              UserModel federatedUser,
                                              FederatedIdentityModel federatedIdentityModel)

      Specified by:
        `updateFederatedIdentity` in interface `UserProvider`

    - #### removeFederatedIdentity

          public boolean removeFederatedIdentity(RealmModel realm,
                                                 UserModel userModel,
                                                 String socialProvider)

      Specified by:
        `removeFederatedIdentity` in interface `UserProvider`

    - #### addUser

          public UserModel addUser(RealmModel realm,
                                   String username)

      Specified by:
        `addUser` in interface `UserRegistrationProvider`

    - #### grantToAllUsers

          public void grantToAllUsers(RealmModel realm,
                                      RoleModel role)

      Specified by:
        `grantToAllUsers` in interface `UserRegistrationProvider`

    - #### preRemove

          public void preRemove(RealmModel realm)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### preRemove

          public void preRemove(RealmModel realm,
                                UserFederationProviderModel link)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### preRemove

          public void preRemove(RealmModel realm,
                                ClientModel client)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### preRemove

          public void preRemove(ProtocolMapperModel protocolMapper)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### preRemove

          public void preRemove(RealmModel realm,
                                GroupModel group)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### preRemove

          public void preRemove(RealmModel realm,
                                RoleModel role)

      Specified by:
        `preRemove` in interface `UserProvider`

    - #### validCredentials

          public boolean validCredentials(KeycloakSession session,
                                          RealmModel realm,
                                          UserModel user,
                                          List<UserCredentialModel> input)

      Specified by:
        `validCredentials` in interface `UserCredentialValidatorProvider`

    - #### validCredentials

          public boolean validCredentials(KeycloakSession session,
                                          RealmModel realm,
                                          UserModel user,
                                          UserCredentialModel... input)

      Specified by:
        `validCredentials` in interface `UserProvider`

    - #### validCredentials

          public CredentialValidationOutput validCredentials(KeycloakSession session,
                                                             RealmModel realm,
                                                             UserCredentialModel... input)

      Specified by:
        `validCredentials` in interface `UserProvider`

    - #### addConsent

          public void addConsent(RealmModel realm,
                                 UserModel user,
                                 UserConsentModel consent)

      Specified by:
        `addConsent` in interface `UserProvider`

    - #### getConsentByClient

          public UserConsentModel getConsentByClient(RealmModel realm,
                                                     UserModel user,
                                                     String clientId)

      Specified by:
        `getConsentByClient` in interface `UserProvider`

    - #### getConsents

          public List<UserConsentModel> getConsents(RealmModel realm,
                                                    UserModel user)

      Specified by:
        `getConsents` in interface `UserProvider`

    - #### updateConsent

          public void updateConsent(RealmModel realm,
                                    UserModel user,
                                    UserConsentModel consent)

      Specified by:
        `updateConsent` in interface `UserProvider`

    - #### revokeConsentForClient

          public boolean revokeConsentForClient(RealmModel realm,
                                                UserModel user,
                                                String clientId)

      Specified by:
        `revokeConsentForClient` in interface `UserProvider`

    - #### preRemove

          public void preRemove(RealmModel realm,
                                ComponentModel component)

      Specified by:
        `preRemove` in interface `UserProvider`

Copyright © 2016 JBoss by Red Hat. All rights reserved.