Java Code Examples for org.keycloak.models.UserModel#deleteRoleMapping()
The following examples show how to use
org.keycloak.models.UserModel#deleteRoleMapping() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerRunOnServerUtil.java From keycloak with Apache License 2.0 | 5 votes |
static RunOnServer revokeReadTokenRole(String username) { return session -> { RealmModel realm = session.getContext().getRealm(); ClientModel brokerClient = realm.getClientByClientId(Constants.BROKER_SERVICE_CLIENT_ID); RoleModel readTokenRole = brokerClient.getRole(Constants.READ_TOKEN_ROLE); UserModel user = session.users().getUserByUsername(username, realm); user.deleteRoleMapping(readTokenRole); }; }
Example 2
Source File: ClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUserLegacy(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); if (!hasClaimValue(mapperModel, context)) { RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName); user.deleteRoleMapping(role); } }
Example 3
Source File: ClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { 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 (!hasClaimValue(mapperModel, context)) { user.deleteRoleMapping(role); } else { user.grantRole(role); } }
Example 4
Source File: AdvancedClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUserLegacy(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); if (!hasAllClaimValues(mapperModel, context)) { RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName); user.deleteRoleMapping(role); } }
Example 5
Source File: AdvancedClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { 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 (!hasAllClaimValues(mapperModel, context)) { user.deleteRoleMapping(role); } else { user.grantRole(role); } }
Example 6
Source File: ExternalKeycloakRoleToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { if (hasRole(realm, mapperModel, context)) { user.grantRole(searchRole(realm, mapperModel)); } else { user.deleteRoleMapping(searchRole(realm, mapperModel)); } }
Example 7
Source File: AttributeToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void updateBrokeredUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { 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)) { user.deleteRoleMapping(role); }else{ user.grantRole(role); } }