use of org.keycloak.admin.client.resource.GroupsResource in project keycloak by keycloak.
the class GroupPolicyManagementTest method testDeleteGroupAndPolicy.
@Test
public void testDeleteGroupAndPolicy() {
AuthorizationResource authorization = getClient().authorization();
GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
representation.setName(UUID.randomUUID().toString());
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.setGroupsClaim("groups");
representation.addGroupPath("/Group G", true);
assertCreated(authorization, representation);
GroupsResource groups = getRealm().groups();
GroupRepresentation group = groups.groups("Group G", null, null).get(0);
groups.group(group.getId()).remove();
try {
getClient().authorization().policies().group().findByName(representation.getName());
} catch (NotFoundException e) {
}
representation.getGroups().clear();
representation.addGroupPath("/Group H/Group I/Group K");
representation.addGroupPath("/Group F");
assertCreated(authorization, representation);
group = groups.groups("Group K", null, null).get(0);
groups.group(group.getId()).remove();
GroupPolicyRepresentation policy = getClient().authorization().policies().group().findByName(representation.getName());
assertNotNull(policy);
assertEquals(1, policy.getGroups().size());
}
use of org.keycloak.admin.client.resource.GroupsResource in project keycloak by keycloak.
the class Creator method create.
public static Creator<GroupResource> create(RealmResource realmResource, GroupRepresentation rep) {
final GroupsResource groups = realmResource.groups();
try (Response response = groups.add(rep)) {
String createdId = getCreatedId(response);
final GroupResource r = groups.group(createdId);
LOG.debugf("Created group ID %s", createdId);
return new Creator(createdId, r, r::remove);
}
}
use of org.keycloak.admin.client.resource.GroupsResource in project keycloak by keycloak.
the class GroupTest method getGroupsWithBriefRepresentation.
@Test
public void getGroupsWithBriefRepresentation() {
RealmResource realm = adminClient.realms().realm("test");
GroupsResource groupsResource = adminClient.realms().realm("test").groups();
GroupRepresentation group = new GroupRepresentation();
group.setName("groupWithAttribute");
Map<String, List<String>> attributes = new HashMap<String, List<String>>();
attributes.put("attribute1", Arrays.asList("attribute1", "attribute2"));
group.setAttributes(attributes);
group = createGroup(realm, group);
List<GroupRepresentation> groups = groupsResource.groups("groupWithAttribute", 0, 20);
assertFalse(groups.isEmpty());
assertNull(groups.get(0).getAttributes());
}
use of org.keycloak.admin.client.resource.GroupsResource in project keycloak by keycloak.
the class GroupTest method defaultMaxResults.
@Test
public void defaultMaxResults() {
GroupsResource groups = adminClient.realms().realm("test").groups();
try (Response response = groups.add(GroupBuilder.create().name("test").build())) {
String groupId = ApiUtil.getCreatedId(response);
GroupResource group = groups.group(groupId);
UsersResource users = adminClient.realms().realm("test").users();
for (int i = 0; i < 110; i++) {
try (Response r = users.create(UserBuilder.create().username("test-" + i).build())) {
users.get(ApiUtil.getCreatedId(r)).joinGroup(groupId);
}
}
assertEquals(100, group.members(null, null).size());
assertEquals(100, group.members().size());
assertEquals(105, group.members(0, 105).size());
assertEquals(110, group.members(0, 1000).size());
assertEquals(110, group.members(-1, -2).size());
}
}
use of org.keycloak.admin.client.resource.GroupsResource in project keycloak by keycloak.
the class GroupTest method testBriefRepresentationOnGroupMembers.
@Test
public void testBriefRepresentationOnGroupMembers() {
RealmResource realm = adminClient.realms().realm("test");
String groupName = "brief-grouptest-group";
String userName = "brief-grouptest-user";
GroupsResource groups = realm.groups();
try (Response response = groups.add(GroupBuilder.create().name(groupName).build())) {
String groupId = ApiUtil.getCreatedId(response);
GroupResource group = groups.group(groupId);
UsersResource users = realm.users();
UserRepresentation userRepresentation = UserBuilder.create().username(userName).addAttribute("myattribute", "myvalue").build();
Response r = users.create(userRepresentation);
UserResource user = users.get(ApiUtil.getCreatedId(r));
user.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());
group.remove();
user.remove();
}
}
Aggregations