Search in sources :

Example 46 with ProtocolMapperRepresentation

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"));
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) Test(org.junit.Test)

Example 47 with ProtocolMapperRepresentation

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"));
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) Test(org.junit.Test)

Example 48 with ProtocolMapperRepresentation

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"));
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) Test(org.junit.Test)

Example 49 with ProtocolMapperRepresentation

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();
}
Also used : ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 50 with ProtocolMapperRepresentation

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));
    }
}
Also used : AdminEventRepresentation(org.keycloak.representations.idm.AdminEventRepresentation) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Aggregations

ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)107 Test (org.junit.Test)68 HashMap (java.util.HashMap)30 Response (javax.ws.rs.core.Response)30 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)27 Map (java.util.Map)23 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)20 ClientResource (org.keycloak.admin.client.resource.ClientResource)19 OAuthClient (org.keycloak.testsuite.util.OAuthClient)17 RealmResource (org.keycloak.admin.client.resource.RealmResource)14 List (java.util.List)13 ProtocolMappersResource (org.keycloak.admin.client.resource.ProtocolMappersResource)12 IDToken (org.keycloak.representations.IDToken)12 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)11 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)11 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)10 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)8 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)7 AccessToken (org.keycloak.representations.AccessToken)7