Search in sources :

Example 41 with GroupRepresentation

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);
}
Also used : GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) Before(org.junit.Before)

Example 42 with GroupRepresentation

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);
}
Also used : Response(javax.ws.rs.core.Response) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation)

Example 43 with GroupRepresentation

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));
}
Also used : GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) UserResource(org.keycloak.admin.client.resource.UserResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 44 with GroupRepresentation

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();
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(org.keycloak.services.ErrorResponse) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) GroupModel(org.keycloak.models.GroupModel) NotFoundException(javax.ws.rs.NotFoundException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 45 with GroupRepresentation

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()));
    }
}
Also used : Response(javax.ws.rs.core.Response) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) PolicyResource(org.keycloak.admin.client.resource.PolicyResource) GroupPolicyResource(org.keycloak.admin.client.resource.GroupPolicyResource) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) GroupPoliciesResource(org.keycloak.admin.client.resource.GroupPoliciesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Aggregations

GroupRepresentation (org.keycloak.representations.idm.GroupRepresentation)81 Test (org.junit.Test)62 RealmResource (org.keycloak.admin.client.resource.RealmResource)36 Response (javax.ws.rs.core.Response)24 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)23 List (java.util.List)17 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)17 ProtocolMappersResource (org.keycloak.admin.client.resource.ProtocolMappersResource)14 UserResource (org.keycloak.admin.client.resource.UserResource)13 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 IDToken (org.keycloak.representations.IDToken)10 OAuthClient (org.keycloak.testsuite.util.OAuthClient)10 LinkedList (java.util.LinkedList)8 Before (org.junit.Before)8 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)7 Map (java.util.Map)6 NotFoundException (javax.ws.rs.NotFoundException)6 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)6