Java Code Examples for io.vertx.reactivex.ext.web.RoutingContext#clearUser()

The following examples show how to use io.vertx.reactivex.ext.web.RoutingContext#clearUser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogoutEndpoint.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private void invalidateSession(RoutingContext routingContext, Handler<AsyncResult<User>> handler) {
    io.gravitee.am.model.User endUser = null;
    // clear context and session
    if (routingContext.user() != null) {
        endUser = ((io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) routingContext.user().getDelegate()).getUser();
        // audit event
        report(endUser, routingContext.request());
        // clear user
        routingContext.clearUser();
    }

    if (routingContext.session() != null) {
        routingContext.session().destroy();
    }

    handler.handle(Future.succeededFuture(endUser));
}
 
Example 2
Source File: UserConsentFailureHandler.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
    if (context.failed()) {
        // logout the user
        // but keep the session intact with the original OAuth 2.0 authorization request in order to replay the whole login process
        context.clearUser();

        // handle exception
        Throwable throwable = context.failure();
        if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            handleException(context, policyChainException.key(), policyChainException.getMessage());
        } else {
            handleException(context, "internal_server_error", "Unexpected error");
        }
    }
}
 
Example 3
Source File: AuthorizationRequestParseParametersHandler.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
void parsePromptParameter(RoutingContext context) {
    String prompt = context.request().getParam(Parameters.PROMPT);

    if (prompt != null) {
        // retrieve prompt values (prompt parameter is a space delimited, case sensitive list of ASCII string values)
        // https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
        List<String> promptValues = Arrays.asList(prompt.split("\\s+"));

        // The Authorization Server MUST NOT display any authentication or consent user interface pages.
        // An error is returned if an End-User is not already authenticated.
        if (promptValues.contains("none") && context.user() == null) {
            throw new LoginRequiredException("Login required");
        }

        // The Authentication Request contains the prompt parameter with the value login.
        // In this case, the Authorization Server MUST reauthenticate the End-User even if the End-User is already authenticated.
        if (promptValues.contains("login") && context.user() != null) {
            if (!returnFromLoginPage(context)) {
                context.clearUser();
            }
        }
    }
}
 
Example 4
Source File: BaseSecurityResource.java    From redpipe with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/logout")
public Response logout(@Context UriInfo uriInfo, @Context RoutingContext ctx, @Context AppGlobals globals) {
	ctx.clearUser();
	UriBuilder builder = uriInfo.getBaseUriBuilder();
	URI rootUri = builder.path(globals.getMainClass()).build();
	return Response.status(Status.FOUND).location(rootUri).build();
}
 
Example 5
Source File: AbstractAuthorizationRequestParametersHandler.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
protected void parseMaxAgeParameter(RoutingContext context) {
    // if user is already authenticated and if the last login date is greater than the max age parameter,
    // the OP MUST attempt to actively re-authenticate the End-User.
    User authenticatedUser = context.user();
    if (authenticatedUser == null || !(authenticatedUser.getDelegate() instanceof io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User)) {
        // user not authenticated, continue
        return;
    }

    String maxAge = context.request().getParam(Parameters.MAX_AGE);
    if (maxAge == null || !maxAge.matches("-?\\d+")) {
        // none or invalid max age, continue
        return;
    }

    io.gravitee.am.model.User endUser = ((io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) authenticatedUser.getDelegate()).getUser();
    Date loggedAt = endUser.getLoggedAt();
    if (loggedAt == null) {
        // user has no last login date, continue
        return;
    }

    // check the elapsed user session duration
    long elapsedLoginTime = (System.currentTimeMillis() - loggedAt.getTime()) / 1000L;
    Long maxAgeValue = Long.valueOf(maxAge);
    if (maxAgeValue < elapsedLoginTime) {
        // check if the user doesn't come from the login page
        if (!returnFromLoginPage(context)) {
            // should we logout the user or just force it to go to the login page ?
            context.clearUser();

            // check prompt parameter in case the user set 'none' option
            parsePromptParameter(context);
        }
    }
}