Search in sources :

Example 41 with ProtocolMapperRepresentation

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

Example 42 with ProtocolMapperRepresentation

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

Example 43 with ProtocolMapperRepresentation

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

Example 44 with ProtocolMapperRepresentation

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

Example 45 with ProtocolMapperRepresentation

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

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