KEYCLOAK-2704

User count missing in REST admin endpoint
This commit is contained in:
Stian Thorgersen 2016-04-05 07:48:20 +02:00
parent cee8fee504
commit 48551d362a
3 changed files with 24 additions and 0 deletions

View file

@ -29,6 +29,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
import java.util.Map;
public interface UsersResource { public interface UsersResource {
@ -51,6 +52,11 @@ public interface UsersResource {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
Response create(UserRepresentation userRepresentation); Response create(UserRepresentation userRepresentation);
@Path("count")
@GET
@Produces(MediaType.APPLICATION_JSON)
Map<String, Integer> count();
@Path("{id}") @Path("{id}")
UserResource get(@PathParam("id") String id); UserResource get(@PathParam("id") String id);

View file

@ -681,6 +681,16 @@ public class UsersResource {
return results; 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") @Path("{id}/role-mappings")
public RoleMapperResource getRoleMappings(@PathParam("id") String id) { public RoleMapperResource getRoleMappings(@PathParam("id") String id) {

View file

@ -231,6 +231,14 @@ public class UserTest extends AbstractClientTest {
assertEquals(9, users.size()); assertEquals(9, users.size());
} }
@Test
public void count() {
createUsers();
Integer count = realm.users().count().get("count");
assertEquals(9, count.intValue());
}
@Test @Test
public void searchPaginated() { public void searchPaginated() {
createUsers(); createUsers();