Search in sources :

Example 6 with IdentityProviderMapperRepresentation

use of org.keycloak.representations.idm.IdentityProviderMapperRepresentation in project keycloak by keycloak.

the class KcOidcBrokerTest method createAdditionalMapperWithCustomSyncMode.

@Override
protected void createAdditionalMapperWithCustomSyncMode(IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation friendlyManagerMapper = new IdentityProviderMapperRepresentation();
    friendlyManagerMapper.setName("friendly-manager-role-mapper");
    friendlyManagerMapper.setIdentityProviderMapper(ExternalKeycloakRoleToRoleMapper.PROVIDER_ID);
    friendlyManagerMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put("external.role", ROLE_FRIENDLY_MANAGER).put("role", ROLE_FRIENDLY_MANAGER).build());
    friendlyManagerMapper.setIdentityProviderAlias(bc.getIDPAlias());
    RealmResource realm = adminClient.realm(bc.consumerRealmName());
    IdentityProviderResource idpResource = realm.identityProviders().get(bc.getIDPAlias());
    idpResource.addMapper(friendlyManagerMapper).close();
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) RealmResource(org.keycloak.admin.client.resource.RealmResource)

Example 7 with IdentityProviderMapperRepresentation

use of org.keycloak.representations.idm.IdentityProviderMapperRepresentation in project keycloak by keycloak.

the class IdentityProviderTest method testDeleteProtocolMappersAfterDeleteIdentityProvider.

// KEYCLOAK-7872
@Test
public void testDeleteProtocolMappersAfterDeleteIdentityProvider() {
    create(createRep("google3", "google"));
    IdentityProviderResource provider = realm.identityProviders().get("google3");
    IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation();
    mapper.setIdentityProviderAlias("google3");
    mapper.setName("my_mapper");
    mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper");
    Map<String, String> config = new HashMap<>();
    config.put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString());
    config.put("role", "offline_access");
    mapper.setConfig(config);
    Response response = provider.addMapper(mapper);
    List<IdentityProviderMapperRepresentation> mappers = provider.getMappers();
    assertThat(mappers, hasSize(1));
    assertAdminEvents.clear();
    provider.remove();
    assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.identityProviderPath("google3"), ResourceType.IDENTITY_PROVIDER);
    create(createRep("google3", "google"));
    IdentityProviderResource newProvider = realm.identityProviders().get("google3");
    assertThat(newProvider.getMappers(), empty());
}
Also used : Response(javax.ws.rs.core.Response) IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with IdentityProviderMapperRepresentation

use of org.keycloak.representations.idm.IdentityProviderMapperRepresentation in project keycloak by keycloak.

the class IdentityProviderTest method testUpdateProtocolMappers.

// KEYCLOAK-4962
@Test
public void testUpdateProtocolMappers() {
    create(createRep("google2", "google"));
    IdentityProviderResource provider = realm.identityProviders().get("google2");
    IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation();
    mapper.setIdentityProviderAlias("google2");
    mapper.setName("my_mapper");
    mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper");
    Map<String, String> config = new HashMap<>();
    config.put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString());
    config.put("role", "");
    mapper.setConfig(config);
    Response response = provider.addMapper(mapper);
    String mapperId = ApiUtil.getCreatedId(response);
    List<IdentityProviderMapperRepresentation> mappers = provider.getMappers();
    assertEquals(1, mappers.size());
    assertEquals(1, mappers.get(0).getConfig().size());
    mapper = provider.getMapperById(mapperId);
    mapper.getConfig().put("role", "offline_access");
    provider.update(mapperId, mapper);
    mappers = provider.getMappers();
    assertEquals("INHERIT", mappers.get(0).getConfig().get(IdentityProviderMapperModel.SYNC_MODE));
    assertEquals(1, mappers.size());
    assertEquals(2, mappers.get(0).getConfig().size());
    assertEquals("offline_access", mappers.get(0).getConfig().get("role"));
}
Also used : Response(javax.ws.rs.core.Response) IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 9 with IdentityProviderMapperRepresentation

use of org.keycloak.representations.idm.IdentityProviderMapperRepresentation in project keycloak by keycloak.

the class IdentityProviderTest method testMappers.

@Test
public void testMappers() {
    create(createRep("google", "google"));
    IdentityProviderResource provider = realm.identityProviders().get("google");
    IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation();
    mapper.setIdentityProviderAlias("google");
    mapper.setName("my_mapper");
    mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper");
    Map<String, String> config = new HashMap<>();
    config.put("role", "offline_access");
    config.put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString());
    mapper.setConfig(config);
    // createRep and add mapper
    Response response = provider.addMapper(mapper);
    String id = ApiUtil.getCreatedId(response);
    Assert.assertNotNull(id);
    response.close();
    assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.identityProviderMapperPath("google", id), mapper, ResourceType.IDENTITY_PROVIDER_MAPPER);
    // list mappers
    List<IdentityProviderMapperRepresentation> mappers = provider.getMappers();
    Assert.assertEquals("mappers count", 1, mappers.size());
    Assert.assertEquals("newly created mapper id", id, mappers.get(0).getId());
    // get mapper
    mapper = provider.getMapperById(id);
    Assert.assertEquals("INHERIT", mappers.get(0).getConfig().get(IdentityProviderMapperModel.SYNC_MODE));
    Assert.assertNotNull("mapperById not null", mapper);
    Assert.assertEquals("mapper id", id, mapper.getId());
    Assert.assertNotNull("mapper.config exists", mapper.getConfig());
    Assert.assertEquals("config retained", "offline_access", mapper.getConfig().get("role"));
    // add duplicate mapper
    Response error = provider.addMapper(mapper);
    Assert.assertEquals("mapper unique name", 400, error.getStatus());
    error.close();
    // update mapper
    mapper.getConfig().put("role", "master-realm.manage-realm");
    provider.update(id, mapper);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.identityProviderMapperPath("google", id), mapper, ResourceType.IDENTITY_PROVIDER_MAPPER);
    mapper = provider.getMapperById(id);
    Assert.assertNotNull("mapperById not null", mapper);
    Assert.assertEquals("config changed", "master-realm.manage-realm", mapper.getConfig().get("role"));
    // delete mapper
    provider.delete(id);
    assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.identityProviderMapperPath("google", id), ResourceType.IDENTITY_PROVIDER_MAPPER);
    try {
        provider.getMapperById(id);
        Assert.fail("Should fail with NotFoundException");
    } catch (NotFoundException e) {
    // Expected
    }
}
Also used : Response(javax.ws.rs.core.Response) IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 10 with IdentityProviderMapperRepresentation

use of org.keycloak.representations.idm.IdentityProviderMapperRepresentation in project keycloak by keycloak.

the class OidcClaimToRoleMapperTest method createClaimToRoleMapper.

protected void createClaimToRoleMapper(IdentityProviderRepresentation idp, String claimValue, IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation claimToRoleMapper = new IdentityProviderMapperRepresentation();
    claimToRoleMapper.setName("claim-to-role-mapper");
    claimToRoleMapper.setIdentityProviderMapper(ClaimToRoleMapper.PROVIDER_ID);
    claimToRoleMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(ClaimToRoleMapper.CLAIM, OidcClaimToRoleMapperTest.CLAIM).put(ClaimToRoleMapper.CLAIM_VALUE, claimValue).put(ConfigConstants.ROLE, CLIENT_ROLE_MAPPER_REPRESENTATION).build());
    IdentityProviderResource idpResource = realm.identityProviders().get(idp.getAlias());
    claimToRoleMapper.setIdentityProviderAlias(bc.getIDPAlias());
    idpResource.addMapper(claimToRoleMapper).close();
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource)

Aggregations

IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)34 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)25 Test (org.junit.Test)9 RealmResource (org.keycloak.admin.client.resource.RealmResource)7 Response (javax.ws.rs.core.Response)6 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)5 Closeable (java.io.Closeable)3 HashMap (java.util.HashMap)3 StringInputStream (org.apache.tools.ant.filters.StringInputStream)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EntityDescriptorType (org.keycloak.dom.saml.v2.metadata.EntityDescriptorType)3 SPSSODescriptorType (org.keycloak.dom.saml.v2.metadata.SPSSODescriptorType)3 SAMLParser (org.keycloak.saml.processing.core.parsers.saml.SAMLParser)3 IdentityProviderAttributeUpdater (org.keycloak.testsuite.updaters.IdentityProviderAttributeUpdater)3 Before (org.junit.Before)2 NotFoundException (javax.ws.rs.NotFoundException)1 MultipartFormDataOutput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)1 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)1 AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)1 AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)1