Search in sources :

Example 56 with GroupRepresentation

use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.

the class UserAttributesTest method createUserWithGroups.

@Test
public void createUserWithGroups() {
    GroupRepresentation newGroup = new GroupRepresentation();
    newGroup.setName("mygroup");
    // navigate to Groups creation page
    groupsPage.navigateTo();
    assertCurrentUrlEquals(groupsPage);
    groupsPage.table().addGroup();
    assertCurrentUrlStartsWith(createGroupPage);
    // create the group
    createGroupPage.form().setValues(newGroup);
    createGroupPage.form().save();
    assertAlertSuccess();
    // navigate to Users creation page
    usersPage.navigateTo();
    RealmRepresentation representation = testRealmResource().toRepresentation();
    representation.setRegistrationEmailAsUsername(true);
    testRealmResource().update(representation);
    newTestRealmUser.setEmail("test-with-groups@keycloak.org");
    newTestRealmUser.setGroups(Arrays.asList("mygroup"));
    createUser(newTestRealmUser);
    assertAlertSuccess();
}
Also used : GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Test(org.junit.Test)

Example 57 with GroupRepresentation

use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.

the class CustomAuthFlowOTPTest method getOrCreateOTPRoleInGroup.

private GroupRepresentation getOrCreateOTPRoleInGroup() {
    GroupRepresentation group = new GroupRepresentation();
    group.setName("otp_group");
    RoleRepresentation role = getOrCreateOTPRole();
    testRealmResource().groups().add(group);
    // obtain id
    GroupRepresentation groupRep = testRealmResource().groups().groups("otp_group", 0, 1).get(0);
    testRealmResource().groups().group(groupRep.getId()).roles().realmLevel().add(Arrays.asList(role));
    // reread
    return testRealmResource().groups().groups("otp_group", 0, 1).get(0);
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation)

Example 58 with GroupRepresentation

use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.

the class GroupInvalidationClusterTest method testEntityUpdates.

@Override
protected GroupRepresentation testEntityUpdates(GroupRepresentation group, boolean backendFailover) {
    // groupname
    group.setName(group.getName() + "_updated");
    group = updateEntityOnCurrentFailNode(group, "name");
    verifyEntityUpdateDuringFailover(group, backendFailover);
    // attributes - add new
    group.getAttributes().put("attr3", Arrays.asList(new String[] { "attr3 value" }));
    group = updateEntityOnCurrentFailNode(group, "attributes - adding");
    verifyEntityUpdateDuringFailover(group, backendFailover);
    // attributes - remove
    group.getAttributes().remove("attr3");
    group = updateEntityOnCurrentFailNode(group, "attributes - removing");
    verifyEntityUpdateDuringFailover(group, backendFailover);
    // attributes - update 1
    group.getAttributes().get("attr1").set(0, group.getAttributes().get("attr1").get(0) + " - updated");
    group = updateEntityOnCurrentFailNode(group, "attributes");
    verifyEntityUpdateDuringFailover(group, backendFailover);
    // attributes - update 2
    group.getAttributes().get("attr2").set(1, group.getAttributes().get("attr2").get(1) + " - updated");
    group = updateEntityOnCurrentFailNode(group, "attributes");
    verifyEntityUpdateDuringFailover(group, backendFailover);
    // move
    log.info("Updating Group parent on " + getCurrentFailNode());
    GroupRepresentation parentGroup = new GroupRepresentation();
    parentGroup.setName("parent");
    parentGroup = createEntityOnCurrentFailNode(parentGroup);
    assertEquals("/" + parentGroup.getName(), parentGroup.getPath());
    Response r = entityResourceOnCurrentFailNode(parentGroup).subGroup(group);
    r.close();
    parentGroup = readEntityOnCurrentFailNode(parentGroup);
    group = readEntityOnCurrentFailNode(group);
    assertTrue(ApiUtil.groupContainsSubgroup(parentGroup, group));
    assertEquals(parentGroup.getPath() + "/" + group.getName(), group.getPath());
    verifyEntityUpdateDuringFailover(group, backendFailover);
    parentGroup = readEntityOnCurrentFailNode(parentGroup);
    // Add new child
    GroupRepresentation childGroup2 = GroupBuilder.create().name("childGroup2").build();
    r = entityResourceOnCurrentFailNode(parentGroup).subGroup(childGroup2);
    String childGroup2Id = ApiUtil.getCreatedId(r);
    childGroup2.setId(childGroup2Id);
    parentGroup = readEntityOnCurrentFailNode(parentGroup);
    verifyEntityUpdateDuringFailover(parentGroup, backendFailover);
    // Verify same child groups on both nodes
    GroupRepresentation parentGroupOnOtherNode = readEntityOnCurrentFailNode(parentGroup);
    assertNames(parentGroup.getSubGroups(), group.getName(), "childGroup2");
    assertNames(parentGroupOnOtherNode.getSubGroups(), group.getName(), "childGroup2");
    // Remove childGroup2
    deleteEntityOnCurrentFailNode(childGroup2);
    return group;
}
Also used : Response(javax.ws.rs.core.Response) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation)

Example 59 with GroupRepresentation

use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.

the class GroupInvalidationClusterTest method createTestEntityRepresentation.

@Override
protected GroupRepresentation createTestEntityRepresentation() {
    GroupRepresentation group = new GroupRepresentation();
    group.setName("group_" + RandomStringUtils.randomAlphabetic(5));
    group.setAttributes(new HashMap<String, List<String>>());
    group.getAttributes().put("attr1", Arrays.asList(new String[] { "attr1 value" }));
    group.getAttributes().put("attr2", Arrays.asList(new String[] { "attr2 value", "attr2 value2" }));
    return group;
}
Also used : GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) List(java.util.List)

Example 60 with GroupRepresentation

use of org.keycloak.representations.idm.GroupRepresentation in project keycloak by keycloak.

the class PermissionsTest method groups.

@Test
public void groups() {
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().groups();
        }
    }, Resource.USER, false);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            GroupRepresentation group = new GroupRepresentation();
            group.setName("mygroup");
            response.set(realm.groups().add(group));
        }
    }, Resource.USER, true);
    GroupRepresentation group = adminClient.realms().realm(REALM_NAME).getGroupByPath("mygroup");
    ClientRepresentation realmAccessClient = adminClient.realms().realm(REALM_NAME).clients().findByClientId(Constants.REALM_MANAGEMENT_CLIENT_ID).get(0);
    // this should throw forbidden as "create-client" role isn't enough
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            clients.get(AdminRoles.CREATE_CLIENT).realm(REALM_NAME).groups().groups();
        }
    }, clients.get(AdminRoles.CREATE_CLIENT), false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).toRepresentation();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).update(group);
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).members(0, 100);
        }
    }, Resource.USER, false);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            GroupRepresentation subgroup = new GroupRepresentation();
            subgroup.setName("sub");
            response.set(realm.groups().group(group.getId()).subGroup(subgroup));
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().getAll();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().realmLevel().listAll();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().realmLevel().listEffective();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().realmLevel().listAvailable();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().realmLevel().add(Collections.<RoleRepresentation>emptyList());
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().realmLevel().remove(Collections.<RoleRepresentation>emptyList());
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().clientLevel(realmAccessClient.getId()).listAll();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().clientLevel(realmAccessClient.getId()).listEffective();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().clientLevel(realmAccessClient.getId()).listAvailable();
        }
    }, Resource.USER, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().clientLevel(realmAccessClient.getId()).add(Collections.<RoleRepresentation>emptyList());
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).roles().clientLevel(realmAccessClient.getId()).remove(Collections.<RoleRepresentation>emptyList());
        }
    }, Resource.USER, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.groups().group(group.getId()).remove();
            group.setId(null);
            realm.groups().add(group);
            GroupRepresentation temp = realm.getGroupByPath("mygroup");
            group.setId(temp.getId());
        }
    }, Resource.USER, true);
}
Also used : Response(javax.ws.rs.core.Response) RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) 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