org.keycloak.services.resources.admin

## Class UsersResource

- java.lang.Object
- - org.keycloak.services.resources.admin.UsersResource

-     public class UsersResource
      extends Object

  Base resource for managing users
  Version:
    $Revision: 1 $
  Author:
    Bill Burke

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ClientConnection` | `clientConnection`
    `protected static org.jboss.logging.Logger` | `logger`
    `protected RealmModel` | `realm`
    `protected KeycloakSession` | `session`
    `protected javax.ws.rs.core.UriInfo` | `uriInfo`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UsersResource(RealmModel realm, RealmAuth auth, TokenManager tokenManager)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRealmRoleMappings(String username, List<RoleRepresentation> roles)` Add realm-level role mappings
    `javax.ws.rs.core.Response` | `addSocialLink(String username, String provider, SocialLinkRepresentation rep)`
    `javax.ws.rs.core.Response` | `createUser(javax.ws.rs.core.UriInfo uriInfo, UserRepresentation rep)` Create a new user.
    `void` | `deleteRealmRoleMappings(String username, List<RoleRepresentation> roles)` Delete realm-level role mappings
    `javax.ws.rs.core.Response` | `deleteUser(String username)` delete this user
    `List<RoleRepresentation>` | `getAvailableRealmRoleMappings(String username)` Realm-level roles that can be mapped to this user
    `List<RoleRepresentation>` | `getCompositeRealmRoleMappings(String username)` Effective realm-level role mappings for this user.
    `List<RoleRepresentation>` | `getRealmRoleMappings(String username)` Get realm-level role mappings for this user
    `MappingsRepresentation` | `getRoleMappings(String username)` Get role mappings for this user
    `List<UserSessionRepresentation>` | `getSessions(String username)` List set of sessions associated with this user.
    `List<SocialLinkRepresentation>` | `getSocialLinks(String username)` List set of social logins associated with this user.
    `UserRepresentation` | `getUser(String username)` Get represenation of the user
    `UserApplicationRoleMappingsResource` | `getUserApplicationRoleMappingsResource(String username, String appName)`
    `UserApplicationRoleMappingsResource` | `getUserApplicationRoleMappingsResourceById(String username, String appId)`
    `List<UserRepresentation>` | `getUsers(String search, String last, String first, String email, String username, Integer firstResult, Integer maxResults)` Query list of users.
    `void` | `logout(String username)` Remove all user sessions associated with this user.
    `void` | `removeSocialLink(String username, String provider)`
    `void` | `removeTotp(String username)`
    `void` | `resetPassword(String username, CredentialRepresentation pass)` Set up a temporary password for this user.
    `javax.ws.rs.core.Response` | `resetPasswordEmail(String username, String redirectUri, String clientId)` Send an email to the user with a link they can click to reset their password.
    `javax.ws.rs.core.Response` | `updateUser(String username, UserRepresentation rep)` Update the user

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

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

- - ### Field Detail

    - #### logger

          protected static final org.jboss.logging.Logger logger

    - #### realm

          protected RealmModel realm

    - #### clientConnection

          @Context
          protected ClientConnection clientConnection

    - #### uriInfo

          @Context
          protected javax.ws.rs.core.UriInfo uriInfo

    - #### session

          @Context
          protected KeycloakSession session

  - ### Constructor Detail

    - #### UsersResource

          public UsersResource(RealmModel realm,
                       RealmAuth auth,
                       TokenManager tokenManager)

  - ### Method Detail

    - #### updateUser

          @Path(value="{username}")
          @PUT
          @Consumes(value="application/json")
          public javax.ws.rs.core.Response updateUser(@PathParam(value="username")
                                                               String username,
                                                               UserRepresentation rep)

      Update the user
      Parameters:
        `username` - user name (not id!)
        `rep` -
      Returns:

    - #### createUser

          @POST
          @Consumes(value="application/json")
          public javax.ws.rs.core.Response createUser(@Context
                                                           javax.ws.rs.core.UriInfo uriInfo,
                                                           UserRepresentation rep)

      Create a new user. Must be a unique username!
      Parameters:
        `uriInfo` -
        `rep` -
      Returns:

    - #### getUser

          @Path(value="{username}")
          @GET
          @Produces(value="application/json")
          public UserRepresentation getUser(@PathParam(value="username")
                                                     String username)

      Get represenation of the user
      Parameters:
        `username` - username (not id!)
      Returns:

    - #### getSessions

          @Path(value="{username}/sessions")
          @GET
          @Produces(value="application/json")
          public List<UserSessionRepresentation> getSessions(@PathParam(value="username")
                                                                      String username)

      List set of sessions associated with this user.
      Parameters:
        `username` -
      Returns:

    - #### getSocialLinks

          @Path(value="{username}/social-links")
          @GET
          @Produces(value="application/json")
          public List<SocialLinkRepresentation> getSocialLinks(@PathParam(value="username")
                                                                        String username)

      List set of social logins associated with this user.
      Parameters:
        `username` -
      Returns:

    - #### addSocialLink

          @Path(value="{username}/social-links/{provider}")
          @POST
          public javax.ws.rs.core.Response addSocialLink(@PathParam(value="username")
                                                          String username,
                                                          @PathParam(value="provider")
                                                          String provider,
                                                          SocialLinkRepresentation rep)

    - #### removeSocialLink

          @Path(value="{username}/social-links/{provider}")
          @DELETE
          public void removeSocialLink(@PathParam(value="username")
                                          String username,
                                          @PathParam(value="provider")
                                          String provider)

    - #### logout

          @Path(value="{username}/logout")
          @POST
          public void logout(@PathParam(value="username")
                              String username)

      Remove all user sessions associated with this user. And, for all applications that have an admin URL, tell them to invalidate the sessions for this particular user.
      Parameters:
        `username` - username (not id!)

    - #### deleteUser

          @Path(value="{username}")
          @DELETE
          public javax.ws.rs.core.Response deleteUser(@PathParam(value="username")
                                                         String username)

      delete this user
      Parameters:
        `username` - username (not id!)

    - #### getUsers

          @GET
          @Produces(value="application/json")
          public List<UserRepresentation> getUsers(@QueryParam(value="search")
                                                       String search,
                                                       @QueryParam(value="lastName")
                                                       String last,
                                                       @QueryParam(value="firstName")
                                                       String first,
                                                       @QueryParam(value="email")
                                                       String email,
                                                       @QueryParam(value="username")
                                                       String username,
                                                       @QueryParam(value="first")
                                                       Integer firstResult,
                                                       @QueryParam(value="max")
                                                       Integer maxResults)

      Query list of users. May pass in query criteria
      Parameters:
        `search` - string contained in username, first or last name, or email
        `last` -
        `first` -
        `email` -
        `username` -
      Returns:

    - #### getRoleMappings

          @Path(value="{username}/role-mappings")
          @GET
          @Produces(value="application/json")
          public MappingsRepresentation getRoleMappings(@PathParam(value="username")
                                                                 String username)

      Get role mappings for this user
      Parameters:
        `username` - username (not id!)
      Returns:

    - #### getRealmRoleMappings

          @Path(value="{username}/role-mappings/realm")
          @GET
          @Produces(value="application/json")
          public List<RoleRepresentation> getRealmRoleMappings(@PathParam(value="username")
                                                                        String username)

      Get realm-level role mappings for this user
      Parameters:
        `username` - username (not id!)
      Returns:

    - #### getCompositeRealmRoleMappings

          @Path(value="{username}/role-mappings/realm/composite")
          @GET
          @Produces(value="application/json")
          public List<RoleRepresentation> getCompositeRealmRoleMappings(@PathParam(value="username")
                                                                                 String username)

      Effective realm-level role mappings for this user. Will recurse all composite roles to get this list.
      Parameters:
        `username` - username (not id!)
      Returns:

    - #### getAvailableRealmRoleMappings

          @Path(value="{username}/role-mappings/realm/available")
          @GET
          @Produces(value="application/json")
          public List<RoleRepresentation> getAvailableRealmRoleMappings(@PathParam(value="username")
                                                                                 String username)

      Realm-level roles that can be mapped to this user
      Parameters:
        `username` - username (not id!)
      Returns:

    - #### addRealmRoleMappings

          @Path(value="{username}/role-mappings/realm")
          @POST
          @Consumes(value="application/json")
          public void addRealmRoleMappings(@PathParam(value="username")
                                                     String username,
                                                     List<RoleRepresentation> roles)

      Add realm-level role mappings
      Parameters:
        `username` - username (not id!)
        `roles` -

    - #### deleteRealmRoleMappings

          @Path(value="{username}/role-mappings/realm")
          @DELETE
          @Consumes(value="application/json")
          public void deleteRealmRoleMappings(@PathParam(value="username")
                                                          String username,
                                                          List<RoleRepresentation> roles)

      Delete realm-level role mappings
      Parameters:
        `username` - username (not id!)
        `roles` -

    - #### getUserApplicationRoleMappingsResource

          @Path(value="{username}/role-mappings/applications/{app}")
          public UserApplicationRoleMappingsResource getUserApplicationRoleMappingsResource(@PathParam(value="username")
                                                                                        String username,
                                                                                        @PathParam(value="app")
                                                                                        String appName)

    - #### getUserApplicationRoleMappingsResourceById

          @Path(value="{username}/role-mappings/applications-by-id/{appId}")
          public UserApplicationRoleMappingsResource getUserApplicationRoleMappingsResourceById(@PathParam(value="username")
                                                                                            String username,
                                                                                            @PathParam(value="appId")
                                                                                            String appId)

    - #### resetPassword

          @Path(value="{username}/reset-password")
          @PUT
          @Consumes(value="application/json")
          public void resetPassword(@PathParam(value="username")
                                             String username,
                                             CredentialRepresentation pass)

      Set up a temporary password for this user. User will have to reset this temporary password when they log in next.
      Parameters:
        `username` - username (not id!)
        `pass` - temporary password

    - #### removeTotp

          @Path(value="{username}/remove-totp")
          @PUT
          @Consumes(value="application/json")
          public void removeTotp(@PathParam(value="username")
                                          String username)

      Parameters:
        `username` - username (not id!)

    - #### resetPasswordEmail

          @Path(value="{username}/reset-password-email")
          @PUT
          @Consumes(value="application/json")
          public javax.ws.rs.core.Response resetPasswordEmail(@PathParam(value="username")
                                                                       String username,
                                                                       @QueryParam(value="redirect_uri")
                                                                       String redirectUri,
                                                                       @QueryParam(value="client_id")
                                                                       String clientId)

      Send an email to the user with a link they can click to reset their password. The redirectUri and clientId parameters are optional. The default for the redirect is the account application.
      Parameters:
        `username` - username (not id!)
        `redirectUri` - redirect uri
        `clientId` - client id
      Returns:

Copyright © 2015. All Rights Reserved.