Assigning roles with the admin client is rather tricky. I just finished
migrating a test where I had to assign all kinds of roles. I think
you'll probably find what you are looking for:
Hi,
I am trying to create admin user for a specific realm
programmatically, I am able to create the user, however I can't assign
the realm client roles to it.
For example in the UI I would go to the user 'Role Mappings' choose
the realm client role and move the required roles from the Available
section to the Assigned.
When I try to it programmatically I am getting 404, my code is below,
note that I am getting 404 on the last line -
adminUserClientRole.listAvailable())
createUserAndPsw(keyCloakClient, *"master"*, user);
RealmResource realm = keyCloakClient.realm(*"master"*);
UserResource userResource = realm.users().get(user.getKeyCloakId());
RoleMappingResource roles = userResource.roles();
RoleScopeResource adminUserClientRole = roles.clientLevel(tenantId +
*"-realm"*);
adminUserClientRole.add(adminUserClientRole.listAvailable());
Any advice will be appreciated.
Thanks,
Haim.
The information contained in this message is proprietary to the
sender, protected from disclosure, and may be privileged. The
information is intended to be conveyed only to the designated
recipient(s) of the message. If the reader of this message is not the
intended recipient, you are hereby notified that any dissemination,
use, distribution or copying of this communication is strictly
prohibited and may be unlawful. If you have received this
communication in error, please notify us immediately by replying to
the message and deleting it from your computer. Thank you.
_______________________________________________
keycloak-user mailing list
keycloak-user(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user