Exclude a user with realm-management role from keycloak's password policy - keycloak

I have a user with Client Roles realm-management in a realm which contains password policy.
I want to exclude this user from the password policy since I use this user to do some operation fetch the roles get all the user via Java API and I don't want all the operation to be drop when the password needs to be updated.
I tried to use the admin user from the master realms but I did not get any result
Any ideas?

When you create a realm in keycloak with password policy and you want to exclude the admin user from this policy do this follow these steps :
When a user creates new realm e.g "FooRealm" keycloak adds sibling client inside the master realm with a suffix -realm, in this case, we will see FooRealm-realm
Inside this client, FooRealm-realm do those changes (settings tab)
access type = confidential
Standard Flow Enables = ON
Direct Access Grants Enables = ON
Create user inside the master realm, In user details, go to: Role Mappings >> Clients Roles and from the drop down menu select the sibling client
(FooRealm-realm) and make sure it is own all the roles inside
Now To fetch all the user from the Slave realm FooRealm
Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl("http://localhost/auth")
.realm("master")
.grantType(OAuth2Constants.PASSWORD)
.clientId(FooRealm-realm)
.clientSecret("7f0080cf-xxxx-xxxxx-9115-xxxxxxxxxx")
.username("sysadmin")
.password("x123456")
.build();
RealmResource realmResource = keycloak.realm("FooRealm");
realmResource.users().list(0, 1000);

Related

Keycloak: Prevent client from logging in specific user

Is it possible in keycloak to prevent the account client from logging in a specific user? I have a user that is only supposed to log in via the admin-cli endpoints, but it is in the same realm as the account client.
You can try to remove the
default-roles-<realm-name> role
for this user. This will remove the effective roles for the account client role

WSO2 Api Manager Keycloak Claims

I've successfully configured Keycloak as identity server for WSO2 api manager and I need am able to login to keycloak and, with the bearer, call a WSO2 defined rest API.
Now I need to make WSO2 send to the backend, also claims based on keycloak user's information, like role, group or property.
WSO2 apim 4.1.0 and Keycloak 19
You can't group information from access token's claims but you can get client role, realm role, user name, username and client name.
User group or group member can get by separate API call.
You need to start this order
create realm -> create client -> add realm role -> add client role -> add user (with credential) -> assign realm role to user -> assign client role to user
Then
get access toke for user with grant_type is "password"
decode access token by jwt.io
Finally can map between Keycloak settings and token's claims
You needs to understand how to access the resource by Role Based Access Control in Keycloak.
Here is good explain for Resources, scopes, permissions and policies in keycloak

Is it possible to configure user in realm with rights to read/modify roles and users

Is it possible to configure in keycloak realm (but not in a master realm) to give users access to admin api.
I want to be able as a keycloak user to configure other user roles/scopes etc.
It will be done from fronted service so it cannot be done using service account.
Is it possible to configure in keycloak realm (but not in a master
realm) to give users access to admin api.
Yes, for that you need to:
(Old Keycloak UI)
Go to the target Realm;
Go to users and click on the user to add the roles;
Switch to the tab Role Mappings
On the Client Roles dropdown menu select realm-management
and assign the roles accordingly.
(New Keycloak UI)
Go to the target Realm;
Go to users and click on the user to add the roles;
Click on Assign role
In Search by role name type the desired role
Select the role and assign it

BPM Process for User Group (keycloak)

I've just integrated keycloak with jBPM. Now I can login to jBPM console with keycloak user's credentials and get related roles.
I created some User Groups in keyClock console and mapped some users along with those
User Groups in keyClock console. But I don't have any User Groups in jBPM that I mapped to my user in Keycloak console.
I have created (BPM) process with human task assigned to User Group (entered name of User Group created in Keycloak). This task was unavailable for the user that had this User Group in keycloak mapping.
How to map users to a group using keyCloak that reflects in jBPM?
Actually a role in Keycloak is a group in jBPM.
Create roles in keyCloak (desired user groups in jBPM) and assign those roles to users.
Now processes for specified User Groups (in jBPM) will be visible to users with corresponding roles in keyCloak server.
Note : You may need to create a default role user in keyCloak server that will be mapped to default jBPM user role.

How to define more fine-grained permissions or custom logic for built-in roles in Keycloak

Keycloak provides some built-in roles to manage keycloak itself. These roles are defined in the realm-management client of every non-master realm. As example, I can define a user which has the permissions to manage users. But now this user can change all the roles of all the users. The user can even change the role of itself.
In our application we need a hierarchical role structure in the following way. We have a root, admin and some other specific application roles. The root role should be able to manage the keycloak customer realm as also some application specific functionality. The admin role should have the permissions to manage users and also some application specific functionality.
I have tried to model that in keycloak the following way. I have two realm roles root and admin as also some client (my-app) roles root, admin, edit and view. The realm roles are composite roles which use their counterpart in the client (root -> may-app.root, admin -> my-app.admin).
Now, the issues is that the admin user can change it's role to root. How can I restrict the permissions of the admin user to allow only to manage user or roles that are on the same level or below? Is their such built-in functionality or should I provide my own UI on top of the Keycloak REST API?