use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.
the class AbstractAdvancedGroupMapperTest method addMapperTestGroupToConsumerRealm.
@Before
public void addMapperTestGroupToConsumerRealm() {
GroupRepresentation mapperTestGroup = new GroupRepresentation();
mapperTestGroup.setName(MAPPER_TEST_GROUP_NAME);
mapperTestGroup.setPath(MAPPER_TEST_GROUP_PATH);
adminClient.realm(bc.consumerRealmName()).groups().add(mapperTestGroup);
}
use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.
the class ManyUsersTest method setDefaultGroup.
private void setDefaultGroup(String groupName) {
GroupRepresentation group = new GroupRepresentation();
group.setName(groupName);
Response resp = realmResource().groups().add(group);
String groupId = ApiUtil.getCreatedId(resp);
resp.close();
realmResource().addDefaultGroup(groupId);
}
use of org.keycloak.representations.idm.GroupRepresentation in project ART-TIME by Artezio.
the class KeycloakClientTest method testListGroups.
@Test
public void testListGroups() {
UserRepresentation user = new UserRepresentation();
RealmResource realm = mock(RealmResource.class);
UsersResource usersResource = mock(UsersResource.class);
UserResource userResource = mock(UserResource.class);
String group1 = "Group1";
String group2 = "Group_2";
String userId = "id-user";
user.setId(userId);
expect(realm.users()).andReturn(usersResource);
expect(usersResource.get(userId)).andReturn(userResource);
GroupRepresentation groupRepresentation1 = new GroupRepresentation();
GroupRepresentation groupRepresentation2 = new GroupRepresentation();
groupRepresentation1.setName(group1);
groupRepresentation2.setName(group2);
expect(userResource.groups()).andReturn(Arrays.asList(groupRepresentation1, groupRepresentation2));
replay(realm, usersResource, userResource);
Set<String> actual = keycloakClient.listGroups(user, realm);
verify(realm);
assertFalse(actual.isEmpty());
assertTrue(actual.contains(group1));
assertTrue(actual.contains(group2));
}
use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.
the class GroupResource method addChild.
/**
* Set or create child. This will just set the parent if it exists. Create it and set the parent
* if the group doesn't exist.
*
* @param rep
*/
@POST
@Path("children")
@NoCache
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addChild(GroupRepresentation rep) {
this.auth.groups().requireManage(group);
String groupName = rep.getName();
if (ObjectUtil.isBlank(groupName)) {
return ErrorResponse.error("Group name is missing", Response.Status.BAD_REQUEST);
}
Response.ResponseBuilder builder = Response.status(204);
GroupModel child = null;
if (rep.getId() != null) {
child = realm.getGroupById(rep.getId());
if (child == null) {
throw new NotFoundException("Could not find child by id");
}
realm.moveGroup(child, group);
adminEvent.operation(OperationType.UPDATE);
} else {
child = realm.createGroup(groupName, group);
updateGroup(rep, child);
URI uri = session.getContext().getUri().getBaseUriBuilder().path(session.getContext().getUri().getMatchedURIs().get(2)).path(child.getId()).build();
builder.status(201).location(uri);
rep.setId(child.getId());
adminEvent.operation(OperationType.CREATE);
}
adminEvent.resourcePath(session.getContext().getUri()).representation(rep).success();
GroupRepresentation childRep = ModelToRepresentation.toGroupHierarchy(child, true);
return builder.type(MediaType.APPLICATION_JSON_TYPE).entity(childRep).build();
}
use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.
the class GroupPolicyManagementTest method testGenericConfig.
@Test
public void testGenericConfig() {
AuthorizationResource authorization = getClient().authorization();
GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
representation.setName("Test Generic Config Permission");
representation.setGroupsClaim("groups");
representation.addGroupPath("/Group A");
GroupPoliciesResource policies = authorization.policies().group();
try (Response response = policies.create(representation)) {
GroupPolicyRepresentation created = response.readEntity(GroupPolicyRepresentation.class);
PolicyResource policy = authorization.policies().policy(created.getId());
PolicyRepresentation genericConfig = policy.toRepresentation();
assertNotNull(genericConfig.getConfig());
assertNotNull(genericConfig.getConfig().get("groups"));
GroupRepresentation group = getRealm().groups().groups().stream().filter(groupRepresentation -> groupRepresentation.getName().equals("Group A")).findFirst().get();
assertTrue(genericConfig.getConfig().get("groups").contains(group.getId()));
}
}
Aggregations