[KEYCLOAK-10419] Added briefRepresentation parameter support to the admin client interface
And added a aquillian test for it.
This commit is contained in:
parent
a2099cff39
commit
7518692c0d
3 changed files with 55 additions and 2 deletions
|
@ -117,6 +117,7 @@ public interface GroupResource {
|
|||
@Path("/members")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<UserRepresentation> members();
|
||||
|
||||
/**
|
||||
* Get users
|
||||
* <p/>
|
||||
|
@ -132,4 +133,24 @@ public interface GroupResource {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<UserRepresentation> members(@QueryParam("first") Integer firstResult,
|
||||
@QueryParam("max") Integer maxResults);
|
||||
|
||||
/**
|
||||
* Get users
|
||||
* <p/>
|
||||
* Returns a list of users, filtered according to query parameters
|
||||
*
|
||||
* @param firstResult Pagination offset
|
||||
* @param maxResults Pagination size
|
||||
* @param briefRepresentation Only return basic information (only guaranteed to return id, username, created, first and last name,
|
||||
* email, enabled state, email verification state, federation link, and access.
|
||||
* Note that it means that namely user attributes, required actions, and not before are not returned.)
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@NoCache
|
||||
@Path("/members")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<UserRepresentation> members(@QueryParam("first") Integer firstResult,
|
||||
@QueryParam("max") Integer maxResults,
|
||||
@QueryParam("briefRepresentation") Boolean briefRepresentation);
|
||||
}
|
||||
|
|
|
@ -207,8 +207,7 @@ public class GroupResource {
|
|||
@QueryParam("max") Integer maxResults,
|
||||
@QueryParam("briefRepresentation") Boolean briefRepresentation) {
|
||||
this.auth.groups().requireViewMembers(group);
|
||||
|
||||
|
||||
|
||||
firstResult = firstResult != null ? firstResult : 0;
|
||||
maxResults = maxResults != null ? maxResults : Constants.DEFAULT_MAX_RESULTS;
|
||||
boolean briefRepresentationB = briefRepresentation != null && briefRepresentation;
|
||||
|
|
|
@ -27,6 +27,8 @@ import org.keycloak.admin.client.resource.UsersResource;
|
|||
import org.keycloak.events.admin.OperationType;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.utils.RepresentationToModel;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
|
@ -723,4 +725,35 @@ public class GroupTest extends AbstractGroupTest {
|
|||
assertEquals(new Long(allGroups.size()), realm.groups().count(true).get("count"));
|
||||
assertEquals(new Long(allGroups.size() + 1), realm.groups().count(false).get("count"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBriefRepresentationOnGroupMembers() {
|
||||
String groupName = "group-" + UUID.randomUUID();
|
||||
|
||||
GroupsResource groups = adminClient.realms().realm("test").groups();
|
||||
try (Response response = groups.add(GroupBuilder.create().name(groupName).build())) {
|
||||
String groupId = ApiUtil.getCreatedId(response);
|
||||
|
||||
GroupResource group = groups.group(groupId);
|
||||
|
||||
UsersResource users = adminClient.realms().realm("test").users();
|
||||
String userName = "user-" + UUID.randomUUID();
|
||||
|
||||
UserRepresentation userRepresentation = UserBuilder.create()
|
||||
.username(userName)
|
||||
.addAttribute("myattribute", "myvalue")
|
||||
.build();
|
||||
|
||||
Response r = users.create(userRepresentation);
|
||||
users.get(ApiUtil.getCreatedId(r)).joinGroup(groupId);
|
||||
|
||||
UserRepresentation defaultRepresentation = group.members(null, null).get(0);
|
||||
UserRepresentation fullRepresentation = group.members(null, null, false).get(0);
|
||||
UserRepresentation briefRepresentation = group.members(null, null, true).get(0);
|
||||
|
||||
assertEquals("full group member representation includes attributes", fullRepresentation.getAttributes(), userRepresentation.getAttributes());
|
||||
assertEquals("default group member representation is full", defaultRepresentation.getAttributes(), userRepresentation.getAttributes());
|
||||
assertNull("brief group member representation omits attributes", briefRepresentation.getAttributes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue