Java Code Examples for org.keycloak.models.ProtocolMapperModel#setProtocolMapper()
The following examples show how to use
org.keycloak.models.ProtocolMapperModel#setProtocolMapper() .
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: GroupMembershipMapper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel create(String name, String tokenClaimName, boolean consentRequired, String consentText, boolean accessToken, boolean idToken) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<String, String>(); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, tokenClaimName); if (accessToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); if (idToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "true"); mapper.setConfig(config); return mapper; }
Example 2
Source File: OIDCAttributeMapperHelper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel createClaimMapper(String name, String userAttribute, String tokenClaimName, String claimType, boolean accessToken, boolean idToken, boolean userinfo, String mapperId) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<String, String>(); config.put(ProtocolMapperUtils.USER_ATTRIBUTE, userAttribute); config.put(TOKEN_CLAIM_NAME, tokenClaimName); config.put(JSON_TYPE, claimType); if (accessToken) config.put(INCLUDE_IN_ACCESS_TOKEN, "true"); if (idToken) config.put(INCLUDE_IN_ID_TOKEN, "true"); if (userinfo) config.put(INCLUDE_IN_USERINFO, "true"); mapper.setConfig(config); return mapper; }
Example 3
Source File: AddressMapper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel createAddressMapper(boolean idToken, boolean accessToken, boolean userInfo) { Map<String, String> config; ProtocolMapperModel address = new ProtocolMapperModel(); address.setName("address"); address.setProtocolMapper(PROVIDER_ID); address.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); config = new HashMap<>(); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, Boolean.toString(accessToken)); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, Boolean.toString(idToken)); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_USERINFO, Boolean.toString(userInfo)); config.put(getModelPropertyName(STREET), STREET); config.put(getModelPropertyName(AddressClaimSet.LOCALITY), AddressClaimSet.LOCALITY); config.put(getModelPropertyName(AddressClaimSet.REGION), AddressClaimSet.REGION); config.put(getModelPropertyName(AddressClaimSet.POSTAL_CODE), AddressClaimSet.POSTAL_CODE); config.put(getModelPropertyName(AddressClaimSet.COUNTRY), AddressClaimSet.COUNTRY); config.put(getModelPropertyName(AddressClaimSet.FORMATTED), AddressClaimSet.FORMATTED); address.setConfig(config); return address; }
Example 4
Source File: AudienceProtocolMapper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel createClaimMapper(String name, String includedClientAudience, String includedCustomAudience, boolean accessToken, boolean idToken) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); if (includedClientAudience != null) { config.put(INCLUDED_CLIENT_AUDIENCE, includedClientAudience); } if (includedCustomAudience != null) { config.put(INCLUDED_CUSTOM_AUDIENCE, includedCustomAudience); } if (accessToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); if (idToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "true"); mapper.setConfig(config); return mapper; }
Example 5
Source File: UserSessionNoteMapper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel createClaimMapper(String name, String userSessionNote, String tokenClaimName, String jsonType, boolean accessToken, boolean idToken) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); config.put(ProtocolMapperUtils.USER_SESSION_NOTE, userSessionNote); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, tokenClaimName); config.put(OIDCAttributeMapperHelper.JSON_TYPE, jsonType); if (accessToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); if (idToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "true"); mapper.setConfig(config); return mapper; }
Example 6
Source File: GroupMembershipMapper.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel create(String name, String samlAttributeName, String nameFormat, String friendlyName, boolean singleAttribute) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(SamlProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<String, String>(); config.put(AttributeStatementHelper.SAML_ATTRIBUTE_NAME, samlAttributeName); if (friendlyName != null) { config.put(AttributeStatementHelper.FRIENDLY_NAME, friendlyName); } if (nameFormat != null) { config.put(AttributeStatementHelper.SAML_ATTRIBUTE_NAMEFORMAT, nameFormat); } config.put(SINGLE_GROUP_ATTRIBUTE, Boolean.toString(singleAttribute)); mapper.setConfig(config); return mapper; }
Example 7
Source File: HardcodedRole.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel create(String name, String role) { String mapperId = PROVIDER_ID; ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(SamlProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); config.put(ROLE_ATTRIBUTE, role); mapper.setConfig(config); return mapper; }
Example 8
Source File: ClientAdapter.java From keycloak with Apache License 2.0 | 5 votes |
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) { ProtocolMapperModel mapping = new ProtocolMapperModel(); mapping.setId(entity.getId()); mapping.setName(entity.getName()); mapping.setProtocol(entity.getProtocol()); mapping.setProtocolMapper(entity.getProtocolMapper()); Map<String, String> config = new HashMap<String, String>(); if (entity.getConfig() != null) config.putAll(entity.getConfig()); mapping.setConfig(config); return mapping; }
Example 9
Source File: ClientScopeAdapter.java From keycloak with Apache License 2.0 | 5 votes |
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) { ProtocolMapperModel mapping = new ProtocolMapperModel(); mapping.setId(entity.getId()); mapping.setName(entity.getName()); mapping.setProtocol(entity.getProtocol()); mapping.setProtocolMapper(entity.getProtocolMapper()); Map<String, String> config = new HashMap<String, String>(); if (entity.getConfig() != null) config.putAll(entity.getConfig()); mapping.setConfig(config); return mapping; }
Example 10
Source File: UserStorageConsentTest.java From keycloak with Apache License 2.0 | 5 votes |
public static void setupConsent(KeycloakSession session) { RealmModel realm = session.realms().getRealmByName("demo"); ClientModel product = session.realms().getClientByClientId("product-portal", realm); product.setConsentRequired(true); ClientScopeModel clientScope = realm.addClientScope("clientScope"); clientScope.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); System.err.println("client scope protocol mappers size: " + clientScope.getProtocolMappers().size()); for (ProtocolMapperModel mapper : product.getProtocolMappers()) { if (mapper.getProtocol().equals(OIDCLoginProtocol.LOGIN_PROTOCOL)) { if (mapper.getName().equals(OIDCLoginProtocolFactory.USERNAME) || mapper.getName().equals(OIDCLoginProtocolFactory.EMAIL) || mapper.getName().equals(OIDCLoginProtocolFactory.GIVEN_NAME) ) { ProtocolMapperModel copy = new ProtocolMapperModel(); copy.setName(mapper.getName()); copy.setProtocol(mapper.getProtocol()); Map<String, String> config = new HashMap<>(); config.putAll(mapper.getConfig()); copy.setConfig(config); copy.setProtocolMapper(mapper.getProtocolMapper()); clientScope.addProtocolMapper(copy); } } product.removeProtocolMapper(mapper); } product.addClientScope(clientScope, true); }
Example 11
Source File: VirtualClientModelGenerator.java From keycloak-extension-playground with Apache License 2.0 | 5 votes |
private static Set<ProtocolMapperModel> createDefaultProtocolMappers() { Set<ProtocolMapperModel> mappers = new LinkedHashSet<>(); ProtocolMapperModel clientIdMapper = UserSessionNoteMapper.createClaimMapper( ServiceAccountConstants.CLIENT_ID_PROTOCOL_MAPPER, ServiceAccountConstants.CLIENT_ID, ServiceAccountConstants.CLIENT_ID, "String", true, true); clientIdMapper.setId(KeycloakModelUtils.generateId()); mappers.add(clientIdMapper); ProtocolMapperModel dynamicMapperModel = new ProtocolMapperModel(); dynamicMapperModel.setName(DynamicClaimMapper.PROVIDER_ID); dynamicMapperModel.setId(KeycloakModelUtils.generateId()); dynamicMapperModel.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); dynamicMapperModel.setProtocolMapper(DynamicClaimMapper.PROVIDER_ID); Map<String, String> config = new HashMap<>(); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "false"); dynamicMapperModel.setConfig(config); mappers.add(dynamicMapperModel); return mappers; }
Example 12
Source File: AllowedWebOriginsProtocolMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel createClaimMapper(String name) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); mapper.setConfig(Collections.emptyMap()); return mapper; }
Example 13
Source File: RoleNameMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel create(String name, String role, String newName) { String mapperId = PROVIDER_ID; ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); config.put(ROLE_CONFIG, role); config.put(NEW_ROLE_NAME, newName); mapper.setConfig(config); return mapper; }
Example 14
Source File: HardcodedRole.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel create(String name, String role) { String mapperId = PROVIDER_ID; ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); config.put(ROLE_CONFIG, role); mapper.setConfig(config); return mapper; }
Example 15
Source File: RoleNameMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel create(String name, String role, String newName) { String mapperId = PROVIDER_ID; ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(SamlProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<String, String>(); config.put(ROLE_CONFIG, role); config.put(NEW_ROLE_NAME, newName); mapper.setConfig(config); return mapper; }
Example 16
Source File: FullNameMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel create(String name, boolean accessToken, boolean idToken, boolean userInfo) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); if (accessToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); if (idToken) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "true"); if (userInfo) config.put(OIDCAttributeMapperHelper.INCLUDE_IN_USERINFO, "true"); mapper.setConfig(config); return mapper; }
Example 17
Source File: AudienceResolveProtocolMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel createClaimMapper(String name) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); mapper.setConfig(Collections.emptyMap()); return mapper; }
Example 18
Source File: MigrateTo9_0_0.java From keycloak with Apache License 2.0 | 5 votes |
protected void addAccountConsoleClient(RealmModel realm) { if (realm.getClientByClientId(Constants.ACCOUNT_CONSOLE_CLIENT_ID) == null) { ClientModel client = KeycloakModelUtils.createClient(realm, Constants.ACCOUNT_CONSOLE_CLIENT_ID); client.setName("${client_" + Constants.ACCOUNT_CONSOLE_CLIENT_ID + "}"); client.setEnabled(true); client.setFullScopeAllowed(false); client.setPublicClient(true); client.setDirectAccessGrantsEnabled(false); client.setRootUrl(Constants.AUTH_BASE_URL_PROP); String baseUrl = "/realms/" + realm.getName() + "/account/"; client.setBaseUrl(baseUrl); client.addRedirectUri(baseUrl + "*"); client.setProtocol("openid-connect"); RoleModel role = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).getRole(AccountRoles.MANAGE_ACCOUNT); if (role != null) client.addScopeMapping(role); ProtocolMapperModel audienceMapper = new ProtocolMapperModel(); audienceMapper.setName("audience resolve"); audienceMapper.setProtocol("openid-connect"); audienceMapper.setProtocolMapper("oidc-audience-resolve-mapper"); client.addProtocolMapper(audienceMapper); } }
Example 19
Source File: CASAttributeMapperHelper.java From keycloak-protocol-cas with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel createClaimMapper(String name, String tokenClaimName, String claimType, String mapperId) { ProtocolMapperModel mapper = new ProtocolMapperModel(); mapper.setName(name); mapper.setProtocolMapper(mapperId); mapper.setProtocol(CASLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<String, String>(); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, tokenClaimName); config.put(OIDCAttributeMapperHelper.JSON_TYPE, claimType); mapper.setConfig(config); return mapper; }
Example 20
Source File: RealmManager.java From keycloak with Apache License 2.0 | 4 votes |
private void setupAccountManagement(RealmModel realm) { ClientModel accountClient = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); if (accountClient == null) { accountClient = KeycloakModelUtils.createClient(realm, Constants.ACCOUNT_MANAGEMENT_CLIENT_ID); accountClient.setName("${client_" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "}"); accountClient.setEnabled(true); accountClient.setAlwaysDisplayInConsole(false); accountClient.setFullScopeAllowed(false); accountClient.setRootUrl(Constants.AUTH_BASE_URL_PROP); String baseUrl = "/realms/" + realm.getName() + "/account/"; accountClient.setBaseUrl(baseUrl); accountClient.addRedirectUri(baseUrl + "*"); accountClient.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); for (String role : AccountRoles.ALL) { accountClient.addDefaultRole(role); RoleModel roleModel = accountClient.getRole(role); roleModel.setDescription("${role_" + role + "}"); } RoleModel manageAccountLinks = accountClient.addRole(AccountRoles.MANAGE_ACCOUNT_LINKS); manageAccountLinks.setDescription("${role_" + AccountRoles.MANAGE_ACCOUNT_LINKS + "}"); RoleModel manageAccount = accountClient.getRole(AccountRoles.MANAGE_ACCOUNT); manageAccount.addCompositeRole(manageAccountLinks); RoleModel viewAppRole = accountClient.addRole(AccountRoles.VIEW_APPLICATIONS); viewAppRole.setDescription("${role_" + AccountRoles.VIEW_APPLICATIONS + "}"); RoleModel viewConsentRole = accountClient.addRole(AccountRoles.VIEW_CONSENT); viewConsentRole.setDescription("${role_" + AccountRoles.VIEW_CONSENT + "}"); RoleModel manageConsentRole = accountClient.addRole(AccountRoles.MANAGE_CONSENT); manageConsentRole.setDescription("${role_" + AccountRoles.MANAGE_CONSENT + "}"); manageConsentRole.addCompositeRole(viewConsentRole); ClientModel accountConsoleClient = realm.getClientByClientId(Constants.ACCOUNT_CONSOLE_CLIENT_ID); if (accountConsoleClient == null) { accountConsoleClient = KeycloakModelUtils.createClient(realm, Constants.ACCOUNT_CONSOLE_CLIENT_ID); accountConsoleClient.setName("${client_" + Constants.ACCOUNT_CONSOLE_CLIENT_ID + "}"); accountConsoleClient.setEnabled(true); accountConsoleClient.setAlwaysDisplayInConsole(false); accountConsoleClient.setFullScopeAllowed(false); accountConsoleClient.setPublicClient(true); accountConsoleClient.setDirectAccessGrantsEnabled(false); accountConsoleClient.setRootUrl(Constants.AUTH_BASE_URL_PROP); accountConsoleClient.setBaseUrl(baseUrl); accountConsoleClient.addRedirectUri(baseUrl + "*"); accountConsoleClient.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); accountConsoleClient.addScopeMapping(accountClient.getRole(AccountRoles.MANAGE_ACCOUNT)); ProtocolMapperModel audienceMapper = new ProtocolMapperModel(); audienceMapper.setName(OIDCLoginProtocolFactory.AUDIENCE_RESOLVE); audienceMapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); audienceMapper.setProtocolMapper(AudienceResolveProtocolMapper.PROVIDER_ID); accountConsoleClient.addProtocolMapper(audienceMapper); accountConsoleClient.setAttribute(OIDCConfigAttributes.PKCE_CODE_CHALLENGE_METHOD, "S256"); } } }