Search in sources :

Example 1 with CONTEXT_PATH

use of io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH in project gravitee-access-management by gravitee-io.

the class LogoutEndpoint method generateLogoutCallback.

private Maybe<String> generateLogoutCallback(RoutingContext routingContext, User endUser, Request endpoint) {
    // Single Logout can be done only if the endUser profile contains an IdToken.
    if (endUser.getAdditionalInformation() == null) {
        return Maybe.empty();
    }
    if (!endUser.getAdditionalInformation().containsKey(ConstantKeys.OIDC_PROVIDER_ID_TOKEN_KEY)) {
        return Maybe.empty();
    }
    // Generate a state containing provider id and current query parameter string.
    // This state will be sent back to AM after social logout.
    final String delegatedOpIdToken = (String) endUser.getAdditionalInformation().get(ConstantKeys.OIDC_PROVIDER_ID_TOKEN_KEY);
    final JWT stateJwt = new JWT();
    stateJwt.put("c", endUser.getClient());
    stateJwt.put("p", endUser.getSource());
    stateJwt.put("q", routingContext.request().query());
    // remove state from the request to avoid duplicate state parameter into the external idp logout request
    // this state will be restored after the redirect triggered by the external idp
    routingContext.request().params().remove(io.gravitee.am.common.oauth2.Parameters.STATE);
    return jwtService.encode(stateJwt, certificateManager.defaultCertificateProvider()).map(state -> {
        String redirectUri = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/logout/callback");
        UriBuilder builder = UriBuilder.fromHttpUrl(endpoint.getUri());
        builder.addParameter(Parameters.POST_LOGOUT_REDIRECT_URI, redirectUri);
        builder.addParameter(Parameters.ID_TOKEN_HINT, delegatedOpIdToken);
        builder.addParameter(io.gravitee.am.common.oauth2.Parameters.STATE, state);
        return builder.buildString();
    }).toMaybe();
}
Also used : Client(io.gravitee.am.model.oidc.Client) Authentication(io.gravitee.am.identityprovider.api.Authentication) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) IdentityProviderManager(io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager) UserService(io.gravitee.am.gateway.handler.root.service.user.UserService) ConstantKeys(io.gravitee.am.common.utils.ConstantKeys) JWTService(io.gravitee.am.gateway.handler.common.jwt.JWTService) ClientSyncService(io.gravitee.am.gateway.handler.common.client.ClientSyncService) AsyncResult(io.vertx.core.AsyncResult) User(io.gravitee.am.model.User) SimpleAuthenticationContext(io.gravitee.am.identityprovider.api.SimpleAuthenticationContext) SocialAuthenticationProvider(io.gravitee.am.identityprovider.api.social.SocialAuthenticationProvider) UriBuilder(io.gravitee.am.common.web.UriBuilder) AuthenticationFlowContextService(io.gravitee.am.service.AuthenticationFlowContextService) RequestUtils(io.gravitee.am.gateway.handler.common.vertx.utils.RequestUtils) Logger(org.slf4j.Logger) HttpServerRequest(io.vertx.reactivex.core.http.HttpServerRequest) JWT(io.gravitee.am.common.jwt.JWT) CertificateManager(io.gravitee.am.gateway.handler.common.certificate.CertificateManager) Request(io.gravitee.am.identityprovider.api.common.Request) Domain(io.gravitee.am.model.Domain) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest) Future(io.vertx.core.Future) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) WebClient(io.vertx.reactivex.ext.web.client.WebClient) UserNotFoundException(io.gravitee.am.service.exception.UserNotFoundException) UriBuilderRequest(io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest) MultiMap(io.vertx.reactivex.core.MultiMap) UserToken(io.gravitee.am.gateway.handler.root.service.user.model.UserToken) Parameters(io.gravitee.am.common.oidc.Parameters) EndUserAuthentication(io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication) CONTEXT_PATH(io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest.CONTEXT_PATH) Handler(io.vertx.core.Handler) StringUtils(org.springframework.util.StringUtils) JWT(io.gravitee.am.common.jwt.JWT) UriBuilder(io.gravitee.am.common.web.UriBuilder)

Aggregations

JWT (io.gravitee.am.common.jwt.JWT)1 Parameters (io.gravitee.am.common.oidc.Parameters)1 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)1 UriBuilder (io.gravitee.am.common.web.UriBuilder)1 IdentityProviderManager (io.gravitee.am.gateway.handler.common.auth.idp.IdentityProviderManager)1 EndUserAuthentication (io.gravitee.am.gateway.handler.common.auth.user.EndUserAuthentication)1 CertificateManager (io.gravitee.am.gateway.handler.common.certificate.CertificateManager)1 ClientSyncService (io.gravitee.am.gateway.handler.common.client.ClientSyncService)1 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)1 VertxHttpServerRequest (io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest)1 RequestUtils (io.gravitee.am.gateway.handler.common.vertx.utils.RequestUtils)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 UserService (io.gravitee.am.gateway.handler.root.service.user.UserService)1 UserToken (io.gravitee.am.gateway.handler.root.service.user.model.UserToken)1 Authentication (io.gravitee.am.identityprovider.api.Authentication)1 SimpleAuthenticationContext (io.gravitee.am.identityprovider.api.SimpleAuthenticationContext)1 Request (io.gravitee.am.identityprovider.api.common.Request)1 SocialAuthenticationProvider (io.gravitee.am.identityprovider.api.social.SocialAuthenticationProvider)1 Domain (io.gravitee.am.model.Domain)1