Java Code Examples for org.keycloak.models.utils.KeycloakModelUtils#getRoleFromString()
The following examples show how to use
org.keycloak.models.utils.KeycloakModelUtils#getRoleFromString() .
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: ConditionalRoleAuthenticator.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean matchCondition(AuthenticationFlowContext context) { UserModel user = context.getUser(); RealmModel realm = context.getRealm(); AuthenticatorConfigModel authConfig = context.getAuthenticatorConfig(); if (user != null && authConfig!=null && authConfig.getConfig()!=null) { String requiredRole = authConfig.getConfig().get(ConditionalRoleAuthenticatorFactory.CONDITIONAL_USER_ROLE); RoleModel role = KeycloakModelUtils.getRoleFromString(realm, requiredRole); if (role == null) { logger.errorv("Invalid role name submitted: {0}", requiredRole); return false; } return user.hasRole(role); } return false; }
Example 2
Source File: ClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void importNewUser(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.grantRole(role); } }
Example 3
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 4
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 5
Source File: AdvancedClaimToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void importNewUser(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.grantRole(role); } }
Example 6
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 7
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 8
Source File: AttributeToRoleMapper.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void importNewUser(KeycloakSession session, RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel, BrokeredIdentityContext context) { String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); if (isAttributePresent(mapperModel, context)) { RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName); user.grantRole(role); } }
Example 9
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); } }
Example 10
Source File: HardcodedLDAPRoleStorageMapper.java From keycloak with Apache License 2.0 | 5 votes |
private RoleModel getRole(RealmModel realm) { String roleName = mapperModel.getConfig().getFirst(HardcodedLDAPRoleStorageMapper.ROLE); RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) { logger.warnf("Hardcoded role '%s' configured in mapper '%s' is not available anymore"); } return role; }
Example 11
Source File: HardcodedLDAPRoleStorageMapperFactory.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException { String roleName = config.getConfig().getFirst(HardcodedLDAPRoleStorageMapper.ROLE); if (roleName == null) { throw new ComponentValidationException("Role can't be null"); } RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) { throw new ComponentValidationException("There is no role corresponding to configured value"); } }
Example 12
Source File: ExternalKeycloakRoleToRoleMapper.java From keycloak with Apache License 2.0 | 4 votes |
private RoleModel searchRole(RealmModel realm, IdentityProviderMapperModel mapperModel) { String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName); return role; }
Example 13
Source File: HardcodedRoleMapper.java From keycloak with Apache License 2.0 | 4 votes |
private void grantUserRole(RealmModel realm, UserModel user, IdentityProviderMapperModel mapperModel) { String roleName = mapperModel.getConfig().get(ConfigConstants.ROLE); RoleModel role = KeycloakModelUtils.getRoleFromString(realm, roleName); if (role == null) throw new IdentityBrokerException("Unable to find role: " + roleName); user.grantRole(role); }