in services/src/main/java/org/apache/custos/service/federated/client/keycloak/KeycloakClient.java [1648:1699]
private boolean createGroup(Keycloak client, String realmId, String clientId, GroupRepresentation parentRepresentation) {
if (parentRepresentation.getSubGroups() != null && !parentRepresentation.getSubGroups().isEmpty()) {
List<GroupRepresentation> groupRepresentations = parentRepresentation.getSubGroups();
if (groupRepresentations != null && !groupRepresentations.isEmpty()) {
for (GroupRepresentation representation : groupRepresentations) {
Response createdRes = client.realm(realmId).groups().add(representation);
String id = getCreatedId(createdRes);
if (id != null) {
representation.setId(id);
Response response = client.realm(realmId).groups().group(parentRepresentation.getId()).subGroup(representation);
if (response.getStatus() == HttpStatus.SC_CREATED || response.getStatus() == HttpStatus.SC_NO_CONTENT) {
if (representation.getRealmRoles() != null && !representation.getRealmRoles().isEmpty()) {
List<RoleRepresentation> roleRepresentation = new ArrayList<>();
for (String role : representation.getRealmRoles()) {
RoleResource resource = client.realm(realmId).roles().get(role);
if (resource != null) {
roleRepresentation.add(resource.toRepresentation());
}
}
if (!roleRepresentation.isEmpty()) {
client.realm(realmId).groups().group(id).roles().realmLevel().add(roleRepresentation);
}
}
if (representation.getClientRoles() != null && !representation.getClientRoles().isEmpty()) {
List<RoleRepresentation> clientRepresentations = new ArrayList<>();
ClientRepresentation clientRepresentation =
client.realm(realmId).clients().findByClientId(clientId).get(0);
for (String role : representation.getClientRoles().get(clientId)) {
RoleResource resource = client.realm(realmId).clients().get(clientRepresentation.getId()).roles().get(role);
if (resource != null) {
clientRepresentations.add(resource.toRepresentation());
}
}
if (!clientRepresentations.isEmpty()) {
client.realm(realmId).groups().group(id).roles().
clientLevel(clientRepresentation.getId()).add(clientRepresentations);
}
}
createGroup(client, realmId, clientId, representation);
}
response.close();
}
}
}
}
return true;
}