Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEYCLOAK-2704 #2492

Merged
merged 1 commit into from Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -29,6 +29,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;

public interface UsersResource {

Expand All @@ -51,6 +52,11 @@ List<UserRepresentation> search(@QueryParam("search") String search,
@Consumes(MediaType.APPLICATION_JSON)
Response create(UserRepresentation userRepresentation);

@Path("count")
@GET
@Produces(MediaType.APPLICATION_JSON)
Map<String, Integer> count();

@Path("{id}")
UserResource get(@PathParam("id") String id);

Expand Down
Expand Up @@ -681,6 +681,16 @@ public List<UserRepresentation> getUsers(@QueryParam("search") String search,
return results;
}

@Path("count")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Integer> getUsersCount() {
auth.requireView();

return Collections.singletonMap("count", session.users().getUsersCount(realm));
}

@Path("{id}/role-mappings")
public RoleMapperResource getRoleMappings(@PathParam("id") String id) {

Expand Down
Expand Up @@ -231,6 +231,14 @@ public void search() {
assertEquals(9, users.size());
}

@Test
public void count() {
createUsers();

Integer count = realm.users().count().get("count");
assertEquals(9, count.intValue());
}

@Test
public void searchPaginated() {
createUsers();
Expand Down