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

The following examples show how to use io.vertx.reactivex.ext.web.RoutingContext#failed() . 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: LoginCallbackFailureHandler.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        if (throwable instanceof OAuth2Exception
                || throwable instanceof AbstractManagementException
                || throwable instanceof AuthenticationException) {
            redirectToLoginPage(routingContext, throwable);
        } else {
            logger.error(throwable.getMessage(), throwable);
            if (routingContext.statusCode() != -1) {
                routingContext
                        .response()
                        .setStatusCode(routingContext.statusCode())
                        .end();
            } else {
                routingContext
                        .response()
                        .setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
                        .end();
            }
        }
    }
}
 
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: ErrorHandler.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        // management exception (resource not found, server error, ...)
        if (throwable instanceof AbstractManagementException) {
            AbstractManagementException technicalManagementException = (AbstractManagementException) throwable;
            handleException(routingContext, technicalManagementException.getHttpStatusCode(), technicalManagementException.getMessage(), null);
        // oauth2 exception (token invalid exception)
        } else if (throwable instanceof OAuth2Exception) {
            OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
            handleException(routingContext, oAuth2Exception.getHttpStatusCode(), oAuth2Exception.getMessage(), null);
        } else if (throwable instanceof SCIMException) {
            SCIMException scimException = (SCIMException) throwable;
            handleException(routingContext, scimException.getHttpStatusCode(), scimException.getMessage(), scimException.getScimType());
        } else if (throwable instanceof HttpStatusException) {
            if (401 == ((HttpStatusException) throwable).getStatusCode()) {
                UnauthorizedException unauthorizedException = new UnauthorizedException();
                handleException(routingContext, unauthorizedException.getHttpStatusCode(), unauthorizedException.getMessage(), null);
            }
        } else if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            handleException(routingContext, policyChainException.statusCode(), policyChainException.key() + " : " + policyChainException.getMessage(), null);
        } else {
            logger.error(throwable.getMessage(), throwable);
            if (routingContext.statusCode() != -1) {
                routingContext
                        .response()
                        .setStatusCode(routingContext.statusCode())
                        .end();
            } else {
                routingContext
                        .response()
                        .setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
                        .end();
            }
        }
    }
}
 
Example 4
Source File: ErrorHandler.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        // management exception (resource not found, server error, ...)
        if (throwable instanceof AbstractManagementException) {
            AbstractManagementException technicalManagementException = (AbstractManagementException) throwable;
            handleException(routingContext, "technical_error", technicalManagementException.getMessage());
            // oauth2 exception (token invalid exception)
        } else if (throwable instanceof OAuth2Exception) {
            OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
            handleException(routingContext, oAuth2Exception.getOAuth2ErrorCode(), oAuth2Exception.getMessage());
        } else if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            handleException(routingContext, policyChainException.key(), policyChainException.getMessage());
        } else if (throwable instanceof HttpStatusException) {
            HttpStatusException httpStatusException = (HttpStatusException) throwable;
            handleException(routingContext, httpStatusException.getMessage(), httpStatusException.getPayload());
        } else {
            logger.error("An exception occurs while handling incoming request", throwable);
            if (routingContext.statusCode() != -1) {
                routingContext
                        .response()
                        .setStatusCode(routingContext.statusCode())
                        .end();
            } else {
                routingContext
                        .response()
                        .setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
                        .end();
            }
        }
    }
}
 
Example 5
Source File: ErrorHandler.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        // management exception (resource not found, server error, ...)
        if (throwable instanceof AbstractManagementException) {
            AbstractManagementException technicalManagementException = (AbstractManagementException) throwable;
            handleException(routingContext, technicalManagementException.getHttpStatusCode(), technicalManagementException.getMessage());
            // oauth2 exception (token invalid exception)
        } else if (throwable instanceof OAuth2Exception) {
            OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
            handleException(routingContext, oAuth2Exception.getHttpStatusCode(), oAuth2Exception.getMessage());
        } else if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            handleException(routingContext, policyChainException.statusCode(), policyChainException.key() + " : " + policyChainException.getMessage());
        } else if (throwable instanceof HttpStatusException) {
            HttpStatusException httpStatusException = (HttpStatusException) throwable;
            handleException(routingContext, httpStatusException.getStatusCode(), httpStatusException.getPayload());
        } else {
            logger.error(throwable.getMessage(), throwable);
            if (routingContext.statusCode() != -1) {
                routingContext
                        .response()
                        .setStatusCode(routingContext.statusCode())
                        .end();
            } else {
                routingContext
                        .response()
                        .setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
                        .end();
            }
        }
    }
}
 
Example 6
Source File: AuthorizationRequestFailureHandler.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        try {
            AuthorizationRequest request = resolveInitialAuthorizeRequest(routingContext);
            Client client = routingContext.get(CLIENT_CONTEXT_KEY);
            String defaultErrorURL = UriBuilderRequest.resolveProxyRequest(routingContext.request(), defaultErrorPath, null);
            Throwable throwable = routingContext.failure();
            if (throwable instanceof OAuth2Exception) {
                OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
                // Manage exception
                processOAuth2Exception(request, oAuth2Exception, client, defaultErrorURL, h -> {
                    if (h.failed()) {
                        logger.error("An errors has occurred while handling authorization error response", h.cause());
                        routingContext.response().setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end();
                        return;
                    }
                    // redirect user to the error page with error code and description
                    doRedirect(routingContext.response(), h.result());
                });
            } else if (throwable instanceof HttpStatusException) {
                // in case of http status exception, go to the default error page
                request.setRedirectUri(defaultErrorURL);
                HttpStatusException httpStatusException = (HttpStatusException) throwable;
                doRedirect(routingContext.response(), buildRedirectUri(httpStatusException.getMessage(), httpStatusException.getPayload(), request));
            } else {
                logger.error("An exception has occurred while handling authorization request", throwable);
                if (routingContext.statusCode() != -1) {
                    routingContext
                            .response()
                            .setStatusCode(routingContext.statusCode())
                            .end();
                } else {
                    routingContext
                            .response()
                            .setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
                            .end();
                }
            }
        } catch (Exception e) {
            logger.error("Unable to handle authorization error response", e);
            doRedirect(routingContext.response(), defaultErrorPath);
        } finally {
            // clean session
            cleanSession(routingContext);
        }
    }
}