Search in sources :

Example 1 with IdentityProviderMapperTypeRepresentation

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

the class IdentityProviderResource method getMapperTypes.

/**
 * Get mapper types for identity provider
 */
@GET
@Path("mapper-types")
@NoCache
public Map<String, IdentityProviderMapperTypeRepresentation> getMapperTypes() {
    this.auth.realm().requireViewIdentityProviders();
    if (identityProviderModel == null) {
        throw new javax.ws.rs.NotFoundException();
    }
    KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
    return sessionFactory.getProviderFactoriesStream(IdentityProviderMapper.class).map(IdentityProviderMapper.class::cast).map(mapper -> Arrays.stream(mapper.getCompatibleProviders()).filter(type -> Objects.equals(IdentityProviderMapper.ANY_PROVIDER, type) || Objects.equals(identityProviderModel.getProviderId(), type)).map(type -> {
        IdentityProviderMapperTypeRepresentation rep = new IdentityProviderMapperTypeRepresentation();
        rep.setId(mapper.getId());
        rep.setCategory(mapper.getDisplayCategory());
        rep.setName(mapper.getDisplayType());
        rep.setHelpText(mapper.getHelpText());
        rep.setProperties(mapper.getConfigProperties().stream().map(ModelToRepresentation::toRepresentation).collect(Collectors.toList()));
        return rep;
    }).findFirst().orElse(null)).filter(Objects::nonNull).collect(Collectors.toMap(IdentityProviderMapperTypeRepresentation::getId, Function.identity()));
}
Also used : OperationType(org.keycloak.events.admin.OperationType) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) PathParam(javax.ws.rs.PathParam) Arrays(java.util.Arrays) ResourceType(org.keycloak.events.admin.ResourceType) IdentityProviderFactory(org.keycloak.broker.provider.IdentityProviderFactory) Produces(javax.ws.rs.Produces) IdentityProviderMapperModel(org.keycloak.models.IdentityProviderMapperModel) GET(javax.ws.rs.GET) Logger(org.jboss.logging.Logger) Path(javax.ws.rs.Path) IdentityProviderMapperTypeRepresentation(org.keycloak.representations.idm.IdentityProviderMapperTypeRepresentation) Function(java.util.function.Function) RepresentationToModel(org.keycloak.models.utils.RepresentationToModel) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) MediaType(javax.ws.rs.core.MediaType) UserModel(org.keycloak.models.UserModel) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) AdminPermissionManagement(org.keycloak.services.resources.admin.permissions.AdminPermissionManagement) StripSecretsUtils(org.keycloak.models.utils.StripSecretsUtils) IdentityProvider(org.keycloak.broker.provider.IdentityProvider) IdentityProviderMapper(org.keycloak.broker.provider.IdentityProviderMapper) DELETE(javax.ws.rs.DELETE) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) FederatedIdentityModel(org.keycloak.models.FederatedIdentityModel) AdminPermissions(org.keycloak.services.resources.admin.permissions.AdminPermissions) RealmModel(org.keycloak.models.RealmModel) POST(javax.ws.rs.POST) AdminPermissionEvaluator(org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator) KeycloakSession(org.keycloak.models.KeycloakSession) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ManagementPermissionReference(org.keycloak.representations.idm.ManagementPermissionReference) Objects(java.util.Objects) SocialIdentityProvider(org.keycloak.broker.social.SocialIdentityProvider) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) Stream(java.util.stream.Stream) NoCache(org.jboss.resteasy.annotations.cache.NoCache) Response(javax.ws.rs.core.Response) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) PUT(javax.ws.rs.PUT) ErrorResponse(org.keycloak.services.ErrorResponse) IdentityProviderMapperTypeRepresentation(org.keycloak.representations.idm.IdentityProviderMapperTypeRepresentation) NotFoundException(javax.ws.rs.NotFoundException) KeycloakSessionFactory(org.keycloak.models.KeycloakSessionFactory) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 2 with IdentityProviderMapperTypeRepresentation

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

the class IdentityProviderTest method testMapperTypes.

@Test
public void testMapperTypes() {
    IdentityProviderResource provider;
    Map<String, IdentityProviderMapperTypeRepresentation> mapperTypes;
    create(createRep("google", "google"));
    provider = realm.identityProviders().get("google");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "google-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("facebook", "facebook"));
    provider = realm.identityProviders().get("facebook");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "facebook-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("github", "github"));
    provider = realm.identityProviders().get("github");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "github-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("twitter", "twitter"));
    provider = realm.identityProviders().get("twitter");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "oidc-username-idp-mapper");
    create(createRep("linkedin", "linkedin"));
    provider = realm.identityProviders().get("linkedin");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "linkedin-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("microsoft", "microsoft"));
    provider = realm.identityProviders().get("microsoft");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "microsoft-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("stackoverflow", "stackoverflow"));
    provider = realm.identityProviders().get("stackoverflow");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "stackoverflow-user-attribute-mapper", "oidc-username-idp-mapper");
    create(createRep("keycloak-oidc", "keycloak-oidc"));
    provider = realm.identityProviders().get("keycloak-oidc");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "keycloak-oidc-role-to-role-idp-mapper", "oidc-user-attribute-idp-mapper", "oidc-role-idp-mapper", "oidc-username-idp-mapper", "oidc-advanced-group-idp-mapper", "oidc-advanced-role-idp-mapper");
    create(createRep("oidc", "oidc"));
    provider = realm.identityProviders().get("oidc");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "oidc-user-attribute-idp-mapper", "oidc-role-idp-mapper", "oidc-username-idp-mapper", "oidc-advanced-group-idp-mapper", "oidc-advanced-role-idp-mapper");
    create(createRep("saml", "saml"));
    provider = realm.identityProviders().get("saml");
    mapperTypes = provider.getMapperTypes();
    assertMapperTypes(mapperTypes, "saml-user-attribute-idp-mapper", "saml-role-idp-mapper", "saml-username-idp-mapper", "saml-advanced-role-idp-mapper");
}
Also used : IdentityProviderMapperTypeRepresentation(org.keycloak.representations.idm.IdentityProviderMapperTypeRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Streams (com.google.common.collect.Streams)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 BAD_REQUEST (javax.ws.rs.core.Response.Status.BAD_REQUEST)1