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 Description protected ClientConnection
clientConnection
protected javax.ws.rs.core.HttpHeaders
headers
protected RealmModel
realm
protected KeycloakSession
session
-
Constructor Summary
Constructors Constructor Description UsersResource(KeycloakSession session, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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, String searchQuery)
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, Boolean enabled)
Returns the number of users that match the given criteria.UserResource
user(String id)
Get representation of the userUserProfileResource
userProfile()
Get representation of the user
-
-
-
Field Detail
-
realm
protected final RealmModel realm
-
clientConnection
protected final ClientConnection clientConnection
-
session
protected final KeycloakSession session
-
headers
protected final javax.ws.rs.core.HttpHeaders headers
-
-
Constructor Detail
-
UsersResource
public UsersResource(KeycloakSession session, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent)
-
-
Method Detail
-
createUser
@POST @Consumes("application/json") public javax.ws.rs.core.Response createUser(UserRepresentation rep)
Create a new user Username must be unique.- Parameters:
rep
-- Returns:
-
user
@Path("{id}") public UserResource user(@PathParam("id") String id)
Get representation of the user- Parameters:
id
- User id- Returns:
-
getUsers
@GET @Produces("application/json") public Stream<UserRepresentation> getUsers(@QueryParam("search") String search, @QueryParam("lastName") String last, @QueryParam("firstName") String first, @QueryParam("email") String email, @QueryParam("username") String username, @QueryParam("emailVerified") Boolean emailVerified, @QueryParam("idpAlias") String idpAlias, @QueryParam("idpUserId") String idpUserId, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults, @QueryParam("enabled") Boolean enabled, @QueryParam("briefRepresentation") Boolean briefRepresentation, @QueryParam("exact") Boolean exact, @QueryParam("q") String searchQuery)
Get users Returns a stream of users, filtered according to query parameters.- Parameters:
search
- A String contained in username, first or last name, or emaillast
- A String contained in lastName, or the complete lastName, if param "exact" is truefirst
- A String contained in firstName, or the complete firstName, if param "exact" is trueemail
- A String contained in email, or the complete email, if param "exact" is trueusername
- A String contained in username, or the complete username, if param "exact" is trueemailVerified
- whether the email has been verifiedidpAlias
- The alias of an Identity Provider linked to the useridpUserId
- The userId at an Identity Provider linked to the userfirstResult
- Pagination offsetmaxResults
- Maximum results size (defaults to 100)enabled
- Boolean representing if user is enabled or notbriefRepresentation
- Boolean which defines whether brief representations are returned (default: false)exact
- Boolean which defines whether the params "last", "first", "email" and "username" must match exactlysearchQuery
- A query to search for custom attributes, in the format 'key1:value2 key2:value2'- Returns:
- a non-null
Stream
of users
-
getUsersCount
@Path("count") @GET @Produces("application/json") public Integer getUsersCount(@QueryParam("search") String search, @QueryParam("lastName") String last, @QueryParam("firstName") String first, @QueryParam("email") String email, @QueryParam("emailVerified") Boolean emailVerified, @QueryParam("username") String username, @QueryParam("enabled") Boolean enabled)
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 passnull
. The number of all users within that realm will be returned.2. If
search
is specified other criteria such aslast
will be ignored even though you set them. Thesearch
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 oflast
,first
,email
orusername
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 belowlast
- last name filterfirst
- first name filteremail
- email filterusername
- username filterenabled
- Boolean representing if user is enabled or not- Returns:
- the number of users that match the given criteria
-
userProfile
@Path("profile") public UserProfileResource userProfile()
Get representation of the user- Parameters:
id
- User id- Returns:
-
-