Search in sources :

Example 6 with IdentityProviderFactory

use of org.keycloak.broker.provider.IdentityProviderFactory in project keycloak by keycloak.

the class IdentityProvidersResource method importFrom.

/**
 * Import identity provider from uploaded JSON file
 *
 * @param input
 * @return
 * @throws IOException
 */
@POST
@Path("import-config")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, String> importFrom(MultipartFormDataInput input) throws IOException {
    this.auth.realm().requireManageIdentityProviders();
    Map<String, List<InputPart>> formDataMap = input.getFormDataMap();
    if (!(formDataMap.containsKey("providerId") && formDataMap.containsKey("file"))) {
        throw new BadRequestException();
    }
    String providerId = formDataMap.get("providerId").get(0).getBodyAsString();
    InputPart file = formDataMap.get("file").get(0);
    InputStream inputStream = file.getBody(InputStream.class, null);
    IdentityProviderFactory providerFactory = getProviderFactorytById(providerId);
    Map<String, String> config = providerFactory.parseConfig(session, inputStream);
    return config;
}
Also used : InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) InputStream(java.io.InputStream) BadRequestException(javax.ws.rs.BadRequestException) List(java.util.List) IdentityProviderFactory(org.keycloak.broker.provider.IdentityProviderFactory) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

IdentityProviderFactory (org.keycloak.broker.provider.IdentityProviderFactory)6 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)3 IdentityProvider (org.keycloak.broker.provider.IdentityProvider)3 IdentityProviderModel (org.keycloak.models.IdentityProviderModel)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 BadRequestException (javax.ws.rs.BadRequestException)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2 NoCache (org.jboss.resteasy.annotations.cache.NoCache)2 OAuthErrorException (org.keycloak.OAuthErrorException)2 SocialIdentityProvider (org.keycloak.broker.social.SocialIdentityProvider)2 AuthenticationSessionModel (org.keycloak.sessions.AuthenticationSessionModel)2 RootAuthenticationSessionModel (org.keycloak.sessions.RootAuthenticationSessionModel)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 Map (java.util.Map)1