Java Code Examples for org.keycloak.representations.idm.GroupRepresentation#getSubGroups()

The following examples show how to use org.keycloak.representations.idm.GroupRepresentation#getSubGroups() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupImportService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private boolean isGroupEqual(GroupRepresentation existingGroup, GroupRepresentation patchedGroup) {
    if (!CloneUtil.deepEquals(existingGroup, patchedGroup, "subGroups")) {
        return false;
    }

    List<GroupRepresentation> importedSubGroups = patchedGroup.getSubGroups();
    List<GroupRepresentation> existingSubGroups = existingGroup.getSubGroups();

    if (importedSubGroups.isEmpty() && existingSubGroups.isEmpty()) {
        return true;
    }

    if (importedSubGroups.size() != existingSubGroups.size()) {
        return false;
    }

    return areSubGroupsEqual(existingSubGroups, importedSubGroups);
}
 
Example 2
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(26)
void shouldUpdateRealmUpdateGroupAddClientRolesFromSecondClient() {
    doImport("26_update_realm_update_group_delete_add_client_roles_from_second_client.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));

    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(2));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_second_client_role")));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 3
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(27)
void shouldUpdateRealmUpdateGroupRemoveClient() {
    doImport("27_update_realm_update_group_delete_remove_client.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));


    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 4
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(37)
void shouldUpdateRealmUpdateGroupAddSecondClientRoleToSubGroup() {
    doImport("37_update_realm_update_group_add_second_client_role_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), contains("my_second_realm_role"));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(1));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role", "my_second_client_role")));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 5
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(34)
void shouldUpdateRealmUpdateGroupAddSecondRealmRoleToSubGroup() {
    doImport("34_update_realm_update_group_add_second_role_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), containsInAnyOrder("my_realm_role", "my_second_realm_role"));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 6
Source File: PartialExportTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void compileGroups(Set<String> found, GroupRepresentation g) {
    found.add(g.getPath());
    if (g.getSubGroups() != null) {
        for (GroupRepresentation s: g.getSubGroups()) {
            compileGroups(found, s);
        }
    }
}
 
Example 7
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(22)
void shouldUpdateRealmUpdateGroupDeleteRealmRole() {
    doImport("22_update_realm_update_group_delete_realm_role.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_second_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 8
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(21)
void shouldUpdateRealmUpdateGroupAddSecondRealmRole() {
    doImport("21_update_realm_update_group_add_scond_realm_role.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(), hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), containsInAnyOrder("my_realm_role", "my_second_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 9
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(20)
void shouldUpdateRealmUpdateGroupDeleteAttributeValue() {
    doImport("20_update_realm_update_group_delete_attribute_value.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(), hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));

    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 10
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(19)
void shouldUpdateRealmUpdateGroupDeleteAttribute() {
    doImport("19_update_realm_update_group_delete_attribute.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(), hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value", "my second added attribute second value")));

    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 11
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(18)
void shouldUpdateRealmUpdateGroupChangeAttributeKey() {
    doImport("18_update_realm_update_group_change_attribute_key.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes is null", updatedGroup.getAttributes(), aMapWithSize(2));
    assertThat("attributes is null", updatedGroup.getAttributes(), hasEntry(is("my added attribute"), containsInAnyOrder("my added attribute value", "my added attribute second value")));
    assertThat("attributes is null", updatedGroup.getAttributes(), hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value", "my second added attribute second value")));

    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 12
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(29)
void shouldUpdateRealmUpdateGroupAddAttributeValueToSubGroup() {
    doImport("29_update_realm_update_group_add_attribute_value_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my subgroup attribute"), containsInAnyOrder("my subgroup attribute value", "my subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 13
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(16)
void shouldUpdateRealmUpdateGroupAddSecondAttribute() {
    doImport("16_update_realm_update_group_add_second_attribute.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));
    assertThat("attributes is null", updatedGroup.getAttributes(), aMapWithSize(2));
    assertThat("attributes is null", updatedGroup.getAttributes(), hasEntry(is("my added attribute"), containsInAnyOrder("my added attribute value", "my added attribute second value")));
    assertThat("attributes is null", updatedGroup.getAttributes(), hasEntry(is("my second added attribute"), containsInAnyOrder("my second added attribute value", "my second added attribute second value")));

    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 14
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(36)
void shouldUpdateRealmUpdateGroupAddClientRoleToSubGroup() {
    doImport("36_update_realm_update_group_add_client_role_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), contains("my_second_realm_role"));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(1));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 15
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(28)
void shouldUpdateRealmUpdateGroupAddAttributeToSubGroup() {
    doImport("28_update_realm_update_group_add_attribute_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my subgroup attribute"), containsInAnyOrder("my subgroup attribute value")));

    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 16
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(12)
void shouldUpdateRealmUpdateGroupAddSubgroup() {
    doImport("12_update_realm_update_group_add_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));
    assertThat("attributes is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes is null", updatedGroup.getAttributes(), hasEntry(is("my added attribute"), containsInAnyOrder("my added attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), contains("my_realm_role"));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_client_role")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 17
Source File: GroupImportService.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void updateSubGroups(String realm, String parentGroupId, List<GroupRepresentation> subGroups) {
    GroupRepresentation existingGroup = groupRepository.getGroupById(realm, parentGroupId);
    List<GroupRepresentation> existingSubGroups = existingGroup.getSubGroups();

    deleteAllSubGroupsMissingInImport(realm, subGroups, existingSubGroups);

    for (GroupRepresentation subGroup : subGroups) {
        if (hasGroupWithName(existingSubGroups, subGroup.getName())) {
            updateSubGroupIfNecessary(realm, parentGroupId, subGroup);
        } else {
            addSubGroup(realm, parentGroupId, subGroup);
        }
    }
}
 
Example 18
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
@Test
@Order(31)
void shouldUpdateRealmUpdateGroupRemoveAttributeValueFromSubGroup() {
    doImport("31_update_realm_update_group_remove_attribute_value_from_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));
    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(2));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my subgroup attribute"), containsInAnyOrder("my subgroup attribute second value")));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(0));
    assertThat("subgroup's subgroups is null", subGroup.getSubGroups(), hasSize(0));
}
 
Example 19
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 4 votes vote down vote up
@Test
@Order(41)
void shouldUpdateRealmUpdateGroupAddSubGroupToSubGroup() {
    doImport("41_update_realm_update_group_add_subgroup_to_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), contains("my_second_realm_role"));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(1));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_second_client_role")));

    List<GroupRepresentation> innerSubGroups = subGroup.getSubGroups();
    assertThat("inner subgroups is empty", innerSubGroups, hasSize(1));

    GroupRepresentation innerSubGroup = innerSubGroups.get(0);
    assertThat("inner subgroup is null", innerSubGroup, notNullValue());
    assertThat("subgroup's name not equal", innerSubGroup.getName(), is("My inner SubGroup"));
    assertThat("subgroup's path not equal", innerSubGroup.getPath(), is("/My Group/My SubGroup/My inner SubGroup"));
    assertThat("subgroup's attributes is null", innerSubGroup.getAttributes(), aMapWithSize(0));
    assertThat("subgroup's realm roles is null", innerSubGroup.getRealmRoles(), hasSize(0));
    assertThat("subgroup's client roles is null", innerSubGroup.getClientRoles(), aMapWithSize(0));
}
 
Example 20
Source File: ImportGroupsIT.java    From keycloak-config-cli with Apache License 2.0 4 votes vote down vote up
@Test
@Order(44)
void shouldUpdateRealmUpdateGroupDeleteSubGroupInSubGroup() {
    doImport("44_update_realm_update_group_delete_subgroup_in_subgroup.json");

    RealmRepresentation createdRealm = keycloakProvider.get().realm(REALM_NAME).toRepresentation();
    assertThat(createdRealm.getRealm(), is(REALM_NAME));
    assertThat(createdRealm.isEnabled(), is(true));

    GroupRepresentation updatedGroup = loadGroup("/My Group");
    assertThat("name not equal", updatedGroup.getName(), is("My Group"));
    assertThat("path not equal", updatedGroup.getPath(), is("/My Group"));

    assertThat("attributes roles is null", updatedGroup.getAttributes(), aMapWithSize(1));
    assertThat("attributes roles is null", updatedGroup.getAttributes(),
            hasEntry(is("my changed attribute"), containsInAnyOrder("my changed attribute value")));
    assertThat("realm roles is null", updatedGroup.getRealmRoles(), hasSize(0));
    assertThat("client roles is null", updatedGroup.getClientRoles(), aMapWithSize(1));
    assertThat("client roles is null", updatedGroup.getClientRoles(), hasEntry(is("second-moped-client"), containsInAnyOrder("my_client_role_of_second-moped-client", "my_second_client_role_of_second-moped-client")));

    List<GroupRepresentation> subGroups = updatedGroup.getSubGroups();
    assertThat("subgroups is empty", subGroups, hasSize(1));

    GroupRepresentation subGroup = subGroups.get(0);
    assertThat("subgroup is null", subGroup, notNullValue());
    assertThat("subgroup's name not equal", subGroup.getName(), is("My SubGroup"));
    assertThat("subgroup's path not equal", subGroup.getPath(), is("/My Group/My SubGroup"));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), aMapWithSize(1));
    assertThat("subgroup's attributes is null", subGroup.getAttributes(), hasEntry(is("my second subgroup attribute"), containsInAnyOrder("my second subgroup attribute value", "my second subgroup attribute second value")));
    assertThat("subgroup's realm roles is null", subGroup.getRealmRoles(), contains("my_second_realm_role"));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), aMapWithSize(1));
    assertThat("subgroup's client roles is null", subGroup.getClientRoles(), hasEntry(is("moped-client"), containsInAnyOrder("my_second_client_role")));


    List<GroupRepresentation> innerSubGroups = subGroup.getSubGroups();
    assertThat("inner subgroups is empty", innerSubGroups, hasSize(1));

    GroupRepresentation innerSubGroup = innerSubGroups.stream()
            .filter(s -> Objects.equals(s.getName(), "My second inner SubGroup"))
            .findFirst()
            .orElse(null);
    assertThat("inner subgroup is null", innerSubGroup, notNullValue());
    assertThat("inner subgroup's name not equal", innerSubGroup.getName(), is("My second inner SubGroup"));
    assertThat("inner subgroup's path not equal", innerSubGroup.getPath(), is("/My Group/My SubGroup/My second inner SubGroup"));
    assertThat("inner subgroup's attributes is null", innerSubGroup.getAttributes(), aMapWithSize(0));
    assertThat("inner subgroup's realm roles is null", innerSubGroup.getRealmRoles(), hasSize(0));
    assertThat("inner subgroup's client roles is null", innerSubGroup.getClientRoles(), aMapWithSize(0));
    assertThat("inner subgroup's subgroups is null", innerSubGroup.getSubGroups(), hasSize(0));
}