use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersOIDCTest method testHardcodedRole.
@Test
public void testHardcodedRole() {
// create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded role");
createClientMappersPage.form().setMapperType(HARDCODED_ROLE);
createClientMappersPage.form().selectRole(REALM_ROLE, "offline_access", null);
createClientMappersPage.form().save();
assertAlertSuccess();
// check
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded role");
assertNotNull(found);
assertEquals("oidc-hardcoded-role-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("offline_access", config.get("role"));
// edit
createClientMappersPage.form().selectRole(CLIENT_ROLE, "view-profile", "account");
createClientMappersPage.form().save();
assertAlertSuccess();
// check
config = findClientMapperByName(id, "hardcoded role").getConfig();
assertEquals("account.view-profile", config.get("role"));
// delete
clientMapperPage.setMapperId(found.getId());
clientMapperPage.delete();
assertAlertSuccess();
// check
assertNull(findClientMapperByName(id, "hardcoded role"));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersOIDCTest method testUpdateTokenClaimName.
@Test
public void testUpdateTokenClaimName() {
clientMappersPage.mapperTable().createMapper();
createClientMappersPage.form().setName("test");
createClientMappersPage.form().setMapperType(USER_ATTRIBUTE);
createClientMappersPage.form().setTokenClaimName("test");
createClientMappersPage.form().save();
assertAlertSuccess();
createClientMappersPage.form().setTokenClaimName("test2");
createClientMappersPage.form().save();
assertAlertSuccess();
ProtocolMapperRepresentation mapper = testRealmResource().clients().get(id).getProtocolMappers().getMappers().stream().filter(m -> m.getName().equals("test")).findFirst().get();
assertThat(mapper.getConfig().get("claim.name"), is(equalTo("test2")));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersOIDCTest method testEditMapper.
@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));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersOIDCTest method isMapperPresent.
private boolean isMapperPresent(String name) {
List<ProtocolMapperRepresentation> mappers = testRealmResource().clients().get(id).getProtocolMappers().getMappers();
boolean found = false;
for (ProtocolMapperRepresentation mapper : mappers) {
if (name.equals(mapper.getName())) {
found = true;
}
}
return found;
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersSAMLTest method testUserProperty.
@Test
public void testUserProperty() {
// create
clientMappersPage.mapperTable().createMapper();
setInitialValues("user property");
createClientMappersPage.form().setMapperType(USER_PROPERTY);
createClientMappersPage.form().save();
assertAlertSuccess();
// check
ProtocolMapperRepresentation found = findClientMapperByName(id, "user property");
assertEquals("saml-user-property-mapper", found.getProtocolMapper());
}
Aggregations