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 javax.ws.rs.core.HttpHeaders` | `headers`
    `protected RealmModel` | `realm`
    `protected KeycloakSession` | `session`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UsersResource(RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `javax.ws.rs.core.Response` | `createUser(UserRepresentation rep)` Create a new user Username must be unique.
    `Stream<UserRepresentation>` | `getUsers(String search, String last, String first, String email, String username, Boolean emailVerified, String idpAlias, String idpUserId, Integer firstResult, Integer maxResults, Boolean enabled, Boolean briefRepresentation, Boolean exact)` Get users Returns a stream of users, filtered according to query parameters
    `Integer` | `getUsersCount(String search, String last, String first, String email, Boolean emailVerified, String username)` Returns the number of users that match the given criteria.
    `UserResource` | `user(String id)` Get representation of the user
    `UserProfileResource` | `userProfile()` Get representation of the user

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

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

- - ### Field Detail

    - #### realm

          protected RealmModel realm

    - #### clientConnection

          @Context
          protected ClientConnection clientConnection

    - #### session

          @Context
          protected KeycloakSession session

    - #### headers

          @Context
          protected javax.ws.rs.core.HttpHeaders headers

  - ### Constructor Detail

    - #### UsersResource

          public UsersResource(RealmModel realm,
                               AdminPermissionEvaluator auth,
                               AdminEventBuilder adminEvent)

  - ### Method Detail

    - #### createUser

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

      Create a new user Username must be unique.
      Parameters:
        `rep` -
      Returns:

    - #### user

          @Path(value="{id}")
          public UserResource user(@PathParam(value="id")
                                                       String id)

      Get representation of the user
      Parameters:
        `id` - User id
      Returns:

    - #### getUsers

          @GET
           @Produces(value="application/json")
          public Stream<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="emailVerified")
                                                                                               Boolean emailVerified,
                                                                                               @QueryParam(value="idpAlias")
                                                                                               String idpAlias,
                                                                                               @QueryParam(value="idpUserId")
                                                                                               String idpUserId,
                                                                                               @QueryParam(value="first")
                                                                                               Integer firstResult,
                                                                                               @QueryParam(value="max")
                                                                                               Integer maxResults,
                                                                                               @QueryParam(value="enabled")
                                                                                               Boolean enabled,
                                                                                               @QueryParam(value="briefRepresentation")
                                                                                               Boolean briefRepresentation,
                                                                                               @QueryParam(value="exact")
                                                                                               Boolean exact)

      Get users Returns a stream of users, filtered according to query parameters
      Parameters:
        `search` - A String contained in username, first or last name, or email
        `last` - A String contained in lastName, or the complete lastName, if param "exact" is true
        `first` - A String contained in firstName, or the complete firstName, if param "exact" is true
        `email` - A String contained in email, or the complete email, if param "exact" is true
        `username` - A String contained in username, or the complete username, if param "exact" is true
        `emailVerified` - whether the email has been verified
        `idpAlias` - The alias of an Identity Provider linked to the user
        `idpUserId` - The userId at an Identity Provider linked to the user
        `firstResult` - Pagination offset
        `maxResults` - Maximum results size (defaults to 100)
        `enabled` - Boolean representing if user is enabled or not
        `briefRepresentation` - Boolean which defines whether brief representations are returned (default: false)
        `exact` - Boolean which defines whether the params "last", "first", "email" and "username" must match exactly
      Returns:
        a non-null `Stream` of users

    - #### getUsersCount

          @Path(value="count")
           @GET
           @Produces(value="application/json")
          public Integer getUsersCount(@QueryParam(value="search")
                                                                                                       String search,
                                                                                                       @QueryParam(value="lastName")
                                                                                                       String last,
                                                                                                       @QueryParam(value="firstName")
                                                                                                       String first,
                                                                                                       @QueryParam(value="email")
                                                                                                       String email,
                                                                                                       @QueryParam(value="emailVerified")
                                                                                                       Boolean emailVerified,
                                                                                                       @QueryParam(value="username")
                                                                                                       String username)

      Returns the number of users that match the given criteria. It can be called in three different ways. 1. Don't specify any criteria and pass `null`. The number of all users within that realm will be returned.

      2. If `search` is specified other criteria such as `last` will be ignored even though you set them. The `search` string will be matched against the first and last name, the username and the email of a user.

      3. If `search` is unspecified but any of `last`, `first`, `email` or `username` those criteria are matched against their respective fields on a user entity. Combined with a logical and.

      Parameters:
        `search` - arbitrary search string for all the fields below
        `last` - last name filter
        `first` - first name filter
        `email` - email filter
        `username` - username filter
      Returns:
        the number of users that match the given criteria

    - #### userProfile

          @Path(value="profile")
          public UserProfileResource userProfile()

      Get representation of the user
      Parameters:
        `id` - User id
      Returns:

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