use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersSAMLTest method testHardcodedAttribute.
@Test
public void testHardcodedAttribute() {
// create
clientMappersPage.mapperTable().createMapper();
setInitialValues("hardcoded attribute");
createClientMappersPage.form().setMapperType(HARDCODED_ATTRIBUTE);
createClientMappersPage.form().setAttributeValue("attribute value");
createClientMappersPage.form().save();
assertAlertSuccess();
// check
ProtocolMapperRepresentation found = findClientMapperByName(id, "hardcoded attribute");
assertNotNull(found);
assertEquals("saml-hardcode-attribute-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("attribute value", config.get("attribute.value"));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersSAMLTest method testRoleName.
@Test
public void testRoleName() {
// create
clientMappersPage.mapperTable().createMapper();
setInitialValues("role name");
createClientMappersPage.form().setMapperType(ROLE_NAME_MAPPER);
createClientMappersPage.form().setRole("offline_access");
createClientMappersPage.form().setNewRole("new role");
createClientMappersPage.form().save();
assertAlertSuccess();
// check
ProtocolMapperRepresentation found = findClientMapperByName(id, "role name");
assertEquals("saml-role-name-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("offline_access", config.get("role"));
assertEquals("new role", config.get("new.role.name"));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ClientMappersSAMLTest method testGroupList.
@Test
public void testGroupList() {
// create
clientMappersPage.mapperTable().createMapper();
setInitialValues("group list");
createClientMappersPage.form().setMapperType(GROUP_LIST);
createClientMappersPage.form().setGroupAttributeName("group attribute name");
createClientMappersPage.form().setSingleGroupAttribute(true);
createClientMappersPage.form().setFullGroupPath(true);
createClientMappersPage.form().save();
assertAlertSuccess();
// check
ProtocolMapperRepresentation found = findClientMapperByName(id, "group list");
assertEquals("saml-group-membership-mapper", found.getProtocolMapper());
Map<String, String> config = found.getConfig();
assertEquals("true", config.get("full.path"));
assertEquals("true", config.get("single"));
assertEquals("group attribute name", config.get("attribute.name"));
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class ProtocolMappersResource method createMapper.
/**
* Create multiple mappers
*/
@Path("add-models")
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public void createMapper(List<ProtocolMapperRepresentation> reps) {
managePermission.require();
ProtocolMapperModel model = null;
for (ProtocolMapperRepresentation rep : reps) {
model = RepresentationToModel.toModel(rep);
validateModel(model);
model = client.addProtocolMapper(model);
}
adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri()).representation(reps).success();
}
use of org.keycloak.representations.idm.ProtocolMapperRepresentation in project keycloak by keycloak.
the class AbstractProtocolMapperTest method testAddAllBuiltinMappers.
protected void testAddAllBuiltinMappers(ProtocolMappersResource resource, String protocolName, String adminEventPath) {
List<ProtocolMapperRepresentation> oldMappers = resource.getMappersPerProtocol(protocolName);
List<ProtocolMapperRepresentation> builtins = builtinMappers.get(protocolName);
List<ProtocolMapperRepresentation> mappersToAdd = mappersToAdd(oldMappers, builtins);
// This is used by admin console to add builtin mappers
resource.createMapper(mappersToAdd);
AdminEventRepresentation adminEvent = assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, adminEventPath + "/add-models", ResourceType.PROTOCOL_MAPPER);
try {
List<ProtocolMapperRepresentation> eventMappers = JsonSerialization.readValue(new ByteArrayInputStream(adminEvent.getRepresentation().getBytes()), new TypeReference<List<ProtocolMapperRepresentation>>() {
});
Assert.assertEquals(eventMappers.size(), mappersToAdd.size());
for (int i = 0; i < mappersToAdd.size(); i++) {
ProtocolMapperRepresentation repExpected = mappersToAdd.get(i);
ProtocolMapperRepresentation repActual = eventMappers.get(i);
assertEqualMappers(repExpected, repActual);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
List<ProtocolMapperRepresentation> newMappers = resource.getMappersPerProtocol(protocolName);
assertEquals(oldMappers.size() + mappersToAdd.size(), newMappers.size());
for (ProtocolMapperRepresentation rep : mappersToAdd) {
assertTrue(containsMapper(newMappers, rep));
}
}
Aggregations