Role mapper should check if an update is needed for the role

Closes #43698

Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
This commit is contained in:
Alexander Schwartz 2025-10-28 18:53:06 +01:00 committed by GitHub
parent 5ad8f1a026
commit 8f8dabab55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,9 +62,15 @@ public abstract class AbstractAttributeToRoleMapper extends AbstractIdentityProv
if (!context.hasMapperGrantedRole(roleName)) {
if (this.applies(mapperModel, context)) {
context.addMapperGrantedRole(roleName);
user.grantRole(role);
if ((!role.isClientRole() && user.getRealmRoleMappingsStream().noneMatch(r -> r.equals(role)))
|| (role.isClientRole() && user.getClientRoleMappingsStream(session.clients().getClientById(realm, role.getContainerId())).noneMatch(r -> r.equals(role)))) {
user.grantRole(role);
}
} else {
user.deleteRoleMapping(role);
if ((!role.isClientRole() && user.getRealmRoleMappingsStream().anyMatch(r -> r.equals(role)))
|| (role.isClientRole() && user.getClientRoleMappingsStream(session.clients().getClientById(realm, role.getContainerId())).anyMatch(r -> r.equals(role)))) {
user.deleteRoleMapping(role);
}
}
}
}