Hi All,
Need help on the following scenario.
Been doing some POC for our keycloak user management project and having problems passing
my unit test as when I create 3 level subgroups, my Keycloak Server hangs.
Sample Junit Test code:
======================================================
createSubGroups(
keycloak, "REALM1", CASHIER_GROUP,
"CLIENT_1");
createSubGroups(
keycloak, "REALM1", DUTY_MANAGER_GROUP,
"CLIENT_1");
createSubGroups(
keycloak, "REALM1", DUTY_MANAGER_GROUP,
"CLIENT_2");
createSubGroups(
keycloak, "REALM1", CASHIER_GROUP,
"CLIENT_2");
====================================
private static void createSubGroups(Keycloak keycloak, String realmName, String
groupName,
String realmClient){
GroupRepresentation parentSub = null;
boolean found = false;
for (GroupRepresentation group:
keycloak.realm(realmName).groups().groups()){
for (GroupRepresentation sub: group.getSubGroups()){
if (sub.getName().equals(groupName))
{
parentSub = sub;
found = true;
break;
}
}
if (found) break;
}
GroupResource parentSubResource =
keycloak.realm(realmName).groups().group(parentSub.getId());
GroupRepresentation subGroup1 = new GroupRepresentation();
subGroup1.setName(groupName + "-" + realmClient);
subGroup1.setPath("/Group_1/" + groupName);
parentSubResource.subGroup(subGroup1);
}
========== Target Output Below ======
Groups
Group_1
DUTY_MANAGER
DUTY_MANAGER_Client_1
DUTY_MANAGER_Client_2
CASHIER
CASHIER_Client_1
CASHIER_Client_2
=================================
My code will only work properly for the first 2 calls of the method. On the 3rd call, it
will somehow hang on the loop.
Am not able to debug nor step through in Junit.
It will only produce the following:
Groups
Group_1
DUTY_MANAGER
DUTY_MANAGER_Client_1
CASHIER
CASHIER_Client_1
I also tried of instead using a loop I use the getGroupByPath from the realmResource but
still the same issue.
The only thing left for me is to call the Restful Service directly from my code.
Any suggestions will be very much appreciated.
Thanks
Rodel