Search in sources :

Example 1 with CLIENT_CONTEXT_KEY

use of io.gravitee.am.common.utils.ConstantKeys.CLIENT_CONTEXT_KEY in project gravitee-access-management by gravitee-io.

the class LoginSocialAuthenticationHandler method handle.

@Override
public void handle(RoutingContext routingContext) {
    final Client client = routingContext.get(CLIENT_CONTEXT_KEY);
    // fetch client identity providers
    getSocialIdentityProviders(client.getIdentityProviders(), identityProvidersResultHandler -> {
        if (identityProvidersResultHandler.failed()) {
            logger.error("Unable to fetch client social identity providers", identityProvidersResultHandler.cause());
            routingContext.fail(new InvalidRequestException("Unable to fetch client social identity providers"));
        }
        List<IdentityProvider> socialIdentityProviders = identityProvidersResultHandler.result();
        // no social provider, continue
        if (socialIdentityProviders == null || socialIdentityProviders.isEmpty()) {
            routingContext.next();
            return;
        }
        // client enable social connect
        // get social identity providers information to correctly build the login page
        enhanceSocialIdentityProviders(socialIdentityProviders, routingContext, resultHandler -> {
            if (resultHandler.failed()) {
                logger.error("Unable to enhance client social identity providers", resultHandler.cause());
                routingContext.fail(new InvalidRequestException("Unable to enhance client social identity providers"));
            }
            // put social providers in context data
            final List<SocialProviderData> socialProviderData = resultHandler.result();
            if (socialProviderData != null) {
                List<SocialProviderData> filteredSocialProviderData = socialProviderData.stream().filter(providerData -> providerData.getIdentityProvider() != null && providerData.getAuthorizeUrl() != null).collect(Collectors.toList());
                List<IdentityProvider> providers = filteredSocialProviderData.stream().map(SocialProviderData::getIdentityProvider).collect(Collectors.toList());
                Map<String, String> authorizeUrls = filteredSocialProviderData.stream().collect(Collectors.toMap(o -> o.getIdentityProvider().getId(), SocialProviderData::getAuthorizeUrl));
                // backwards compatibility
                routingContext.put(OAUTH2_PROVIDER_CONTEXT_KEY, providers);
                routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, providers);
                routingContext.put(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY, authorizeUrls);
            }
            // continue
            routingContext.next();
        });
    });
}
Also used : java.util(java.util) Client(io.gravitee.am.model.oidc.Client) ACTION_KEY(io.gravitee.am.common.utils.ConstantKeys.ACTION_KEY) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) IdentityProviderManager(io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager) IdentityProvider(io.gravitee.am.model.IdentityProvider) ApplicationIdentityProvider(io.gravitee.am.model.idp.ApplicationIdentityProvider) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) JWTService(io.gravitee.am.gateway.handler.common.jwt.JWTService) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) SocialAuthenticationProvider(io.gravitee.am.identityprovider.api.social.SocialAuthenticationProvider) UriBuilder(io.gravitee.am.common.web.UriBuilder) Logger(org.slf4j.Logger) JWT(io.gravitee.am.common.jwt.JWT) CertificateManager(io.gravitee.am.gateway.handler.common.certificate.CertificateManager) Request(io.gravitee.am.identityprovider.api.common.Request) Future(io.vertx.core.Future) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) Collectors(java.util.stream.Collectors) UriBuilderRequest(io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest) HttpMethod(io.gravitee.common.http.HttpMethod) CLIENT_CONTEXT_KEY(io.gravitee.am.common.utils.ConstantKeys.CLIENT_CONTEXT_KEY) CONTEXT_PATH(io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH) Handler(io.vertx.core.Handler) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) IdentityProvider(io.gravitee.am.model.IdentityProvider) ApplicationIdentityProvider(io.gravitee.am.model.idp.ApplicationIdentityProvider) Client(io.gravitee.am.model.oidc.Client)

Aggregations

InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 JWT (io.gravitee.am.common.jwt.JWT)1 ACTION_KEY (io.gravitee.am.common.utils.ConstantKeys.ACTION_KEY)1 CLIENT_CONTEXT_KEY (io.gravitee.am.common.utils.ConstantKeys.CLIENT_CONTEXT_KEY)1 UriBuilder (io.gravitee.am.common.web.UriBuilder)1 IdentityProviderManager (io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager)1 CertificateManager (io.gravitee.am.gateway.handler.common.certificate.CertificateManager)1 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)1 UriBuilderRequest (io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest)1 CONTEXT_PATH (io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH)1 Request (io.gravitee.am.identityprovider.api.common.Request)1 SocialAuthenticationProvider (io.gravitee.am.identityprovider.api.social.SocialAuthenticationProvider)1 IdentityProvider (io.gravitee.am.model.IdentityProvider)1 ApplicationIdentityProvider (io.gravitee.am.model.idp.ApplicationIdentityProvider)1 Client (io.gravitee.am.model.oidc.Client)1 HttpMethod (io.gravitee.common.http.HttpMethod)1 Maybe (io.reactivex.Maybe)1 Observable (io.reactivex.Observable)1 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1