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();
}
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());
}
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"));
}
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
}
}
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();
}
Aggregations