Java Code Examples for org.keycloak.models.ProtocolMapperModel#setConfig()
The following examples show how to use
org.keycloak.models.ProtocolMapperModel#setConfig() .
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: HardcodedClaim.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperModel create(String name, String hardcodedName, String hardcodedValue, String claimType, 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(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, hardcodedName); config.put(CLAIM_VALUE, hardcodedValue); config.put(OIDCAttributeMapperHelper.JSON_TYPE, claimType); 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: 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 7
Source File: ClientScopeAdapter.java From keycloak with Apache License 2.0 | 6 votes |
@Override public Set<ProtocolMapperModel> getProtocolMappers() { Set<ProtocolMapperModel> mappings = new HashSet<ProtocolMapperModel>(); for (ProtocolMapperEntity entity : this.entity.getProtocolMappers()) { 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); mappings.add(mapping); } return mappings; }
Example 8
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 9
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 10
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 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: 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 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: 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 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: RepresentationToModel.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperModel toModel(ProtocolMapperRepresentation rep) { ProtocolMapperModel model = new ProtocolMapperModel(); model.setId(rep.getId()); model.setName(rep.getName()); model.setProtocol(rep.getProtocol()); model.setProtocolMapper(rep.getProtocolMapper()); model.setConfig(removeEmptyString(rep.getConfig())); return model; }
Example 18
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 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: HelloWorldMapperTest.java From keycloak-custom-protocol-mapper-example with Apache License 2.0 | 4 votes |
private AccessToken transformAccessToken(UserSessionModel userSessionModel) { final ProtocolMapperModel mappingModel = new ProtocolMapperModel(); mappingModel.setConfig(createConfig()); return new HelloWorldMapper().transformAccessToken(new AccessToken(), mappingModel, null, userSessionModel, null); }