grant the new role from the saml token if it exist
grant the user with the new role from the saml token if it is a realm role in keycloak
This commit is contained in:
parent
dcaac76b4b
commit
a119a46495
1 changed files with 4 additions and 2 deletions
|
@ -139,10 +139,12 @@ public class AttributeToRoleMapper extends AbstractIdentityProviderMapper {
|
||||||
@Override
|
@Override
|
||||||
public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) {
|
public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) {
|
||||||
String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE);
|
String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE);
|
||||||
|
RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName);
|
||||||
|
if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName);
|
||||||
if (!isAttributePresent(mapperModel, context)) {
|
if (!isAttributePresent(mapperModel, context)) {
|
||||||
RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName);
|
|
||||||
if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName);
|
|
||||||
user.deleteRoleMapping(role);
|
user.deleteRoleMapping(role);
|
||||||
|
}else{
|
||||||
|
user.grantRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue