Search in sources :

Example 21 with IdentityProviderMapperRepresentation

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

the class KcSamlBrokerTest method createIdentityProviderMappers.

@Override
protected Iterable<IdentityProviderMapperRepresentation> createIdentityProviderMappers(IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation attrMapper1 = new IdentityProviderMapperRepresentation();
    attrMapper1.setName("manager-role-mapper");
    attrMapper1.setIdentityProviderMapper(AttributeToRoleMapper.PROVIDER_ID);
    attrMapper1.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(UserAttributeMapper.ATTRIBUTE_NAME, "Role").put(ATTRIBUTE_VALUE, ROLE_MANAGER).put("role", ROLE_MANAGER).build());
    IdentityProviderMapperRepresentation attrMapper2 = new IdentityProviderMapperRepresentation();
    attrMapper2.setName("user-role-mapper");
    attrMapper2.setIdentityProviderMapper(AttributeToRoleMapper.PROVIDER_ID);
    attrMapper2.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(UserAttributeMapper.ATTRIBUTE_NAME, "Role").put(ATTRIBUTE_VALUE, ROLE_USER).put("role", ROLE_USER).build());
    IdentityProviderMapperRepresentation attrMapper3 = new IdentityProviderMapperRepresentation();
    attrMapper3.setName("friendly-mapper");
    attrMapper3.setIdentityProviderMapper(AttributeToRoleMapper.PROVIDER_ID);
    attrMapper3.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(UserAttributeMapper.ATTRIBUTE_FRIENDLY_NAME, KcSamlBrokerConfiguration.ATTRIBUTE_TO_MAP_FRIENDLY_NAME).put(ATTRIBUTE_VALUE, ROLE_FRIENDLY_MANAGER).put("role", ROLE_FRIENDLY_MANAGER).build());
    IdentityProviderMapperRepresentation attrMapper4 = new IdentityProviderMapperRepresentation();
    attrMapper4.setName("user-role-dot-guide-mapper");
    attrMapper4.setIdentityProviderMapper(AttributeToRoleMapper.PROVIDER_ID);
    attrMapper4.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(UserAttributeMapper.ATTRIBUTE_NAME, "Role").put(ATTRIBUTE_VALUE, ROLE_USER_DOT_GUIDE).put("role", ROLE_USER_DOT_GUIDE).build());
    IdentityProviderMapperRepresentation attrMapper5 = new IdentityProviderMapperRepresentation();
    attrMapper5.setName("empty-attribute-to-role-mapper");
    attrMapper5.setIdentityProviderMapper(AttributeToRoleMapper.PROVIDER_ID);
    attrMapper5.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(UserAttributeMapper.ATTRIBUTE_NAME, EMPTY_ATTRIBUTE_NAME).put(ATTRIBUTE_VALUE, "").put("role", EMPTY_ATTRIBUTE_ROLE).build());
    return Arrays.asList(attrMapper1, attrMapper2, attrMapper3, attrMapper4, attrMapper5);
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation)

Example 22 with IdentityProviderMapperRepresentation

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

the class HardcodedRoleMapperTest method createMapperInIdp.

@Override
protected void createMapperInIdp(IdentityProviderRepresentation idp, IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation advancedClaimToRoleMapper = new IdentityProviderMapperRepresentation();
    advancedClaimToRoleMapper.setName("oidc-hardcoded-role-mapper");
    advancedClaimToRoleMapper.setIdentityProviderMapper(HardcodedRoleMapper.PROVIDER_ID);
    advancedClaimToRoleMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(ConfigConstants.ROLE, CLIENT_ROLE_MAPPER_REPRESENTATION).build());
    IdentityProviderResource idpResource = realm.identityProviders().get(idp.getAlias());
    advancedClaimToRoleMapper.setIdentityProviderAlias(bc.getIDPAlias());
    idpResource.addMapper(advancedClaimToRoleMapper).close();
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource)

Example 23 with IdentityProviderMapperRepresentation

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

the class HardcodedUserAttributeMapperTest method createMapperInIdp.

protected void createMapperInIdp(IdentityProviderRepresentation idp, IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation advancedClaimToRoleMapper = new IdentityProviderMapperRepresentation();
    advancedClaimToRoleMapper.setName("hardcoded-attribute-mapper");
    advancedClaimToRoleMapper.setIdentityProviderMapper(HardcodedAttributeMapper.PROVIDER_ID);
    advancedClaimToRoleMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put(HardcodedAttributeMapper.ATTRIBUTE, USER_ATTRIBUTE).put(HardcodedAttributeMapper.ATTRIBUTE_VALUE, USER_ATTRIBUTE_VALUE).build());
    IdentityProviderResource idpResource = realm.identityProviders().get(idp.getAlias());
    advancedClaimToRoleMapper.setIdentityProviderAlias(bc.getIDPAlias());
    idpResource.addMapper(advancedClaimToRoleMapper).close();
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource)

Example 24 with IdentityProviderMapperRepresentation

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

the class KcOidcBrokerTest method loginFetchingUserFromUserEndpointWithClaimMapper.

/**
 * Refers to in old test suite: org.keycloak.testsuite.broker.OIDCBrokerUserPropertyTest
 */
@Test
public void loginFetchingUserFromUserEndpointWithClaimMapper() {
    RealmResource realm = realmsResouce().realm(bc.providerRealmName());
    ClientsResource clients = realm.clients();
    ClientRepresentation brokerApp = clients.findByClientId("brokerapp").get(0);
    IdentityProviderResource identityProviderResource = getIdentityProviderResource();
    clients.get(brokerApp.getId()).getProtocolMappers().createMapper(createHardcodedClaim("hard-coded", "hard-coded", "hard-coded", "String", true, true)).close();
    IdentityProviderMapperRepresentation hardCodedSessionNoteMapper = new IdentityProviderMapperRepresentation();
    hardCodedSessionNoteMapper.setName("hard-coded");
    hardCodedSessionNoteMapper.setIdentityProviderAlias(bc.getIDPAlias());
    hardCodedSessionNoteMapper.setIdentityProviderMapper(UserAttributeMapper.PROVIDER_ID);
    hardCodedSessionNoteMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString()).put(UserAttributeMapper.USER_ATTRIBUTE, "hard-coded").put(UserAttributeMapper.CLAIM, "hard-coded").build());
    identityProviderResource.addMapper(hardCodedSessionNoteMapper).close();
    loginFetchingUserFromUserEndpoint();
    UserRepresentation user = getFederatedIdentity();
    Assert.assertEquals(1, user.getAttributes().size());
    Assert.assertEquals("hard-coded", user.getAttributes().get("hard-coded").get(0));
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) RealmResource(org.keycloak.admin.client.resource.RealmResource) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 25 with IdentityProviderMapperRepresentation

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

the class KcOidcBrokerTest method createIdentityProviderMappers.

@Override
protected Iterable<IdentityProviderMapperRepresentation> createIdentityProviderMappers(IdentityProviderMapperSyncMode syncMode) {
    IdentityProviderMapperRepresentation attrMapper1 = new IdentityProviderMapperRepresentation();
    attrMapper1.setName("manager-role-mapper");
    attrMapper1.setIdentityProviderMapper(ExternalKeycloakRoleToRoleMapper.PROVIDER_ID);
    attrMapper1.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put("external.role", ROLE_MANAGER).put("role", ROLE_MANAGER).build());
    IdentityProviderMapperRepresentation attrMapper2 = new IdentityProviderMapperRepresentation();
    attrMapper2.setName("user-role-mapper");
    attrMapper2.setIdentityProviderMapper(ExternalKeycloakRoleToRoleMapper.PROVIDER_ID);
    attrMapper2.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, syncMode.toString()).put("external.role", ROLE_USER).put("role", ROLE_USER).build());
    return Lists.newArrayList(attrMapper1, attrMapper2);
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation)

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