Berg
May 3, 2024, 2:17pm
1
Hello,
I am populating my OR instances using the REST API.
One of the things is adding auto-provisioning configurations.
The manager log shows that only users with super admin role can do this.
I create the user that can access the API in the KeyCloakSetup script.
I’m able to create all rights such as ClientRole.READ_
ASSETS, ClientRole.WRITE_ASSETS etc. (as found in the demo keycloaksetup scripts) , but am unable to find how i can mark it as super admin, any tips?
Thanks in advance
Berg
May 3, 2024, 3:25pm
2
To answer my own question again:
The command is: keycloakProvider.isMasterRealmAdmin(#username #.getId())
As the super admin possibility seems only an option for the master realm.
1 Like
Berg
May 13, 2024, 3:04pm
3
Coming back to this topic, the fix above does not seem to work, it seems it is a read only variable.
Still looking for a solution, trying to avoid manual setup steps at all cost
The exceptions that gets thrown:
manager/src/main/java/org/openremote/manager/provisioning/ProvisioningResourceImpl.java
@Override
public long createProvisioningConfig(ProvisioningConfig<?, ?> provisioningConfig) {
if (!isSuper User()) {
throw new ForbiddenException(“Only super admin can create provisioning configurations”);
}
provisioningConfig = provisioningService.merge(provisioningConfig);
return provisioningConfig.getId();
Rich
May 13, 2024, 7:42pm
4
Super admin means has realm role admin
and is a user in the master
realm; you can alter realm roles like this:
.setUsername("serviceuser2");
serviceUser2 = keycloakProvider.createUpdateUser(realmBuilding.getName(), serviceUser2, UniqueIdentifierGenerator.generateId("serviceuser2test"), true);
keycloakProvider.updateUserRoles(
realmBuilding.getName(),
serviceUser2.getId(),
Constants.KEYCLOAK_CLIENT_ID,
Stream.of(ClientRole.READ_ASSETS, ClientRole.WRITE_ASSETS, ClientRole.WRITE_ATTRIBUTES).map(ClientRole::getValue).toArray(String[]::new)
);
// ################################ Make users restricted ###################################
ManagerIdentityProvider identityProvider = identityService.getIdentityProvider();
identityProvider.updateUserRealmRoles(realmBuilding.getName(), testuser3Id, identityProvider.addRealmRoles(realmBuilding.getName(), testuser3Id, RESTRICTED_USER_REALM_ROLE));
identityProvider.updateUserRealmRoles(realmBuilding.getName(), buildingUserId, identityProvider.addRealmRoles(realmBuilding.getName(), buildingUserId, RESTRICTED_USER_REALM_ROLE));
identityProvider.updateUserRealmRoles(realmBuilding.getName(), serviceUser2.getId(), identityProvider.addRealmRoles(realmBuilding.getName(), serviceUser2.getId(), RESTRICTED_USER_REALM_ROLE));
}
}
You can use the Constants.MASTER_REALM_ADMIN_USER
string for the admin role.
Hope this helps
Berg
May 14, 2024, 9:29am
5
That’s it rich, thanks!
ManagerIdentityProvider identityProvider = identityService.getIdentityProvider();
identityProvider.updateUserRealmRoles(realmMaster.getName(), serviceuser.getid(), identityProvider.addRealmRoles(realmMaster.getName(), serviceuser.getid(), Constants.MASTER_REALM_ADMIN_USER));
system
Closed
June 13, 2024, 9:30am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.