Java Code Examples for org.keycloak.representations.idm.ProtocolMapperRepresentation#setConfig()
The following examples show how to use
org.keycloak.representations.idm.ProtocolMapperRepresentation#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: OpenShiftTokenReviewEndpointTest.java From keycloak with Apache License 2.0 | 6 votes |
@Override public void configureTestRealm(RealmRepresentation testRealm) { ClientRepresentation client = testRealm.getClients().stream().filter(r -> r.getClientId().equals("test-app")).findFirst().get(); List<ProtocolMapperRepresentation> mappers = new LinkedList<>(); ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation(); mapper.setName("groups"); mapper.setProtocolMapper(GroupMembershipMapper.PROVIDER_ID); mapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); Map<String, String> config = new HashMap<>(); config.put("full.path", "false"); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "groups"); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true"); config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "true"); mapper.setConfig(config); mappers.add(mapper); client.setProtocolMappers(mappers); client.setPublicClient(false); client.setClientAuthenticatorType("testsuite-client-dummy"); testRealm.getUsers().add(UserBuilder.create().username("groups-user").password("password").addGroups("/topGroup", "/topGroup/level2group").build()); }
Example 2
Source File: RoleMapperTest.java From keycloak with Apache License 2.0 | 6 votes |
public static ProtocolMapperRepresentation createSamlProtocolMapper(String protocolMapperProviderId, String... configKeyValue) { ProtocolMapperRepresentation res = new ProtocolMapperRepresentation(); res.setProtocol(SamlProtocol.LOGIN_PROTOCOL); res.setName(protocolMapperProviderId + "-" + RoleMapperTest.COUNTER++); res.setProtocolMapper(protocolMapperProviderId); Map<String, String> config = new HashMap<>(); for (int i = 0; i < configKeyValue.length - 1; i += 2) { String key = configKeyValue[i]; String value = configKeyValue[i + 1]; config.put(key, value); } res.setConfig(config); return res; }
Example 3
Source File: ClientMapperSetup.java From keycloak-custom-protocol-mapper-example with Apache License 2.0 | 5 votes |
private ProtocolMapperRepresentation createGroupMapper() { ProtocolMapperRepresentation protocolMapperRepresentation = new ProtocolMapperRepresentation(); protocolMapperRepresentation.setProtocolMapper(GroupMembershipMapper.PROVIDER_ID); protocolMapperRepresentation.setProtocol(PROTOCOL); protocolMapperRepresentation.setName("Group mapper"); Map<String, String> config = new HashMap<>(); putAccessTokenClaim(config); // the name of the property we got from the class GroupMembershipMapper config.put("full.path", "true"); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "groups"); protocolMapperRepresentation.setConfig(config); return protocolMapperRepresentation; }
Example 4
Source File: ClientMapperSetup.java From keycloak-custom-protocol-mapper-example with Apache License 2.0 | 5 votes |
private ProtocolMapperRepresentation createHelloWordMapper() { ProtocolMapperRepresentation protocolMapperRepresentation = new ProtocolMapperRepresentation(); protocolMapperRepresentation.setProtocolMapper(HelloWorldMapper.PROVIDER_ID); protocolMapperRepresentation.setProtocol(PROTOCOL); protocolMapperRepresentation.setName("Hello world mapper"); Map<String, String> config = new HashMap<>(); putAccessTokenClaim(config); config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "example.message"); protocolMapperRepresentation.setConfig(config); return protocolMapperRepresentation; }
Example 5
Source File: ClientScopeTest.java From keycloak with Apache License 2.0 | 5 votes |
@Test public void testUpdateProtocolMappers() { ClientScopeRepresentation scopeRep = new ClientScopeRepresentation(); scopeRep.setName("testUpdateProtocolMappers"); scopeRep.setProtocol("openid-connect"); String scopeId = createClientScope(scopeRep); ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation(); mapper.setName("test"); mapper.setProtocol("openid-connect"); mapper.setProtocolMapper("oidc-usermodel-attribute-mapper"); Map<String, String> m = new HashMap<>(); m.put("user.attribute", "test"); m.put("claim.name", ""); m.put("jsonType.label", ""); mapper.setConfig(m); ProtocolMappersResource protocolMappers = clientScopes().get(scopeId).getProtocolMappers(); Response response = protocolMappers.createMapper(mapper); String mapperId = ApiUtil.getCreatedId(response); mapper = protocolMappers.getMapperById(mapperId); mapper.getConfig().put("claim.name", "claim"); protocolMappers.update(mapperId, mapper); List<ProtocolMapperRepresentation> mappers = protocolMappers.getMappers(); assertEquals(1, mappers.size()); assertEquals(2, mappers.get(0).getConfig().size()); assertEquals("test", mappers.get(0).getConfig().get("user.attribute")); assertEquals("claim", mappers.get(0).getConfig().get("claim.name")); clientScopes().get(scopeId).remove(); }
Example 6
Source File: AbstractProtocolMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
protected ProtocolMapperRepresentation makeMapper(String protocol, String name, String mapperType, Map<String, String> config) { ProtocolMapperRepresentation rep = new ProtocolMapperRepresentation(); rep.setProtocol(protocol); rep.setName(name); rep.setProtocolMapper(mapperType); rep.setConfig(config); return rep; }
Example 7
Source File: OIDCProtocolMappersTest.java From keycloak with Apache License 2.0 | 5 votes |
private ProtocolMapperRepresentation makeMapper(String name, String mapperType, Map<String, String> config) { ProtocolMapperRepresentation rep = new ProtocolMapperRepresentation(); rep.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); rep.setName(name); rep.setProtocolMapper(mapperType); rep.setConfig(config); return rep; }
Example 8
Source File: AbstractBasePhotozExampleAdapterTest.java From keycloak with Apache License 2.0 | 5 votes |
protected void setManageAlbumScopeRequired() { ClientScopeRepresentation clientScope = new ClientScopeRepresentation(); clientScope.setName("manage-albums"); clientScope.setProtocol("openid-connect"); ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation(); mapper.setName("manage-albums"); mapper.setProtocol("openid-connect"); mapper.setProtocolMapper(UserClientRoleMappingMapper.PROVIDER_ID); Map<String, String> config = new HashMap<>(); config.put("access.token.claim", "true"); config.put("id.token.claim", "true"); config.put("userinfo.token.claim", "true"); config.put(ProtocolMapperUtils.USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID, "photoz-restful-api"); mapper.setConfig(config); clientScope.setProtocolMappers(Arrays.asList(mapper)); RealmResource realmResource = realmsResouce().realm(REALM_NAME); ClientScopesResource clientScopes = realmResource.clientScopes(); Response resp = clientScopes.create(clientScope); Assert.assertEquals(201, resp.getStatus()); resp.close(); String clientScopeId = ApiUtil.getCreatedId(resp); ClientResource resourceServer = getClientResource(RESOURCE_SERVER_ID); clientScopes.get(clientScopeId).getScopeMappings().clientLevel(resourceServer.toRepresentation().getId()).add(Arrays.asList(resourceServer.roles().get("manage-albums").toRepresentation())); ClientResource html5ClientApp = getClientResource("photoz-html5-client"); html5ClientApp.addOptionalClientScope(clientScopeId); html5ClientApp.getScopeMappings().realmLevel().add(Arrays.asList(realmResource.roles().get("user").toRepresentation(), realmResource.roles().get("admin").toRepresentation())); ClientRepresentation clientRep = html5ClientApp.toRepresentation(); clientRep.setFullScopeAllowed(false); html5ClientApp.update(clientRep); }
Example 9
Source File: AbstractSAMLServletAdapterTest.java From keycloak with Apache License 2.0 | 5 votes |
protected AutoCloseable createProtocolMapper(ProtocolMappersResource resource, String name, String protocol, String protocolMapper, Map<String, String> config) { ProtocolMapperRepresentation representation = new ProtocolMapperRepresentation(); representation.setName(name); representation.setProtocol(protocol); representation.setProtocolMapper(protocolMapper); representation.setConfig(config); try (Response response = resource.createMapper(representation)) { String createdId = getCreatedId(response); return () -> resource.delete(createdId); } }
Example 10
Source File: SHA256PairwiseSubMapper.java From keycloak with Apache License 2.0 | 5 votes |
public static ProtocolMapperRepresentation createPairwiseMapper(String sectorIdentifierUri, String salt) { Map<String, String> config; ProtocolMapperRepresentation pairwise = new ProtocolMapperRepresentation(); pairwise.setName("pairwise subject identifier"); pairwise.setProtocolMapper(new SHA256PairwiseSubMapper().getId()); pairwise.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL); config = new HashMap<>(); config.put(PairwiseSubMapperHelper.SECTOR_IDENTIFIER_URI, sectorIdentifierUri); if (salt == null) { salt = KeycloakModelUtils.generateId(); } config.put(PairwiseSubMapperHelper.PAIRWISE_SUB_ALGORITHM_SALT, salt); pairwise.setConfig(config); return pairwise; }
Example 11
Source File: ClientMappersOIDCTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void testEditMapper() { //prepare data ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation(); mapper.setName("mapper name"); //mapper.setConsentRequired(true); //mapper.setConsentText("consent text"); mapper.setProtocol("openid-connect"); mapper.setProtocolMapper("oidc-usersessionmodel-note-mapper"); Map<String, String> config = new HashMap<>(); config.put("access.token.claim", "true"); config.put("id.token.claim", "true"); config.put("claim.name", "claim name"); config.put("jsonType.label", "String"); config.put("user.session.note", "session note"); mapper.setConfig(config); //insert data testRealmResource().clients().get(id).getProtocolMappers().createMapper(mapper).close(); //check form clientMapperPage.setId(id); String mapperId = findClientMapperByName(id, "mapper name").getId(); clientMapperPage.setMapperId(mapperId); clientMapperPage.navigateTo(); assertEquals("openid-connect", clientMapperPage.form().getProtocol()); assertEquals(mapperId, clientMapperPage.form().getMapperId()); assertEquals("mapper name", clientMapperPage.form().getName()); assertEquals("User Session Note", clientMapperPage.form().getMapperType()); assertEquals("session note", clientMapperPage.form().getUserSessionNote()); assertEquals("claim name", clientMapperPage.form().getTokenClaimName()); assertEquals("String", clientMapperPage.form().getClaimJSONType()); assertTrue(clientMapperPage.form().isAddToIDToken()); assertTrue(clientMapperPage.form().isAddToAccessToken()); //edit clientMapperPage.form().setAddToAccessToken(false); clientMapperPage.form().save(); assertAlertSuccess(); //check assertTrue(clientMapperPage.form().isAddToIDToken()); assertFalse(clientMapperPage.form().isAddToAccessToken()); ProtocolMapperRepresentation rep = findClientMapperByName(id, "mapper name"); assertEquals("false", rep.getConfig().get(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN)); assertEquals("true", rep.getConfig().get(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN)); }