Search in sources :

Example 1 with ExceptionErrorPage

use of org.apache.wicket.markup.html.pages.ExceptionErrorPage in project syncope by apache.

the class SyncopeConsoleRequestCycleListener method onException.

@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
    LOG.error("Exception found", e);
    PageParameters errorParameters = new PageParameters();
    IRequestablePage errorPage = null;
    if (instanceOf(e, UnauthorizedInstantiationException.class) != null) {
        errorParameters.add("errorMessage", MISSING_AUTHORIZATION);
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, AccessControlException.class) != null) {
        if (instanceOf(e, AccessControlException.class).getMessage().contains("expired")) {
            errorParameters.add("errorMessage", PAGE_EXPIRED);
        } else {
            errorParameters.add("errorMessage", MISSING_AUTHORIZATION_CORE);
        }
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, PageExpiredException.class) != null || !SyncopeConsoleSession.get().isSignedIn()) {
        errorParameters.add("errorMessage", PAGE_EXPIRED);
        errorPage = new Login(errorParameters);
    } else if (instanceOf(e, BadRequestException.class) != null || instanceOf(e, WebServiceException.class) != null || instanceOf(e, SyncopeClientException.class) != null) {
        errorParameters.add("errorMessage", REST);
        errorPage = new Login(errorParameters);
    } else {
        Throwable cause = instanceOf(e, ForbiddenException.class);
        if (cause == null) {
            // redirect to default Wicket error page
            errorPage = new ExceptionErrorPage(e, null);
        } else {
            errorParameters.add("errorMessage", cause.getMessage());
            errorPage = new Login(errorParameters);
        }
    }
    if (errorPage instanceof Login) {
        try {
            SyncopeConsoleSession.get().cleanup();
            SyncopeConsoleSession.get().invalidateNow();
        } catch (Throwable t) {
            // ignore
            LOG.debug("Unexpected error while forcing logout after error", t);
        }
    }
    return new RenderPageRequestHandler(new PageProvider(errorPage));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccessControlException(java.security.AccessControlException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Login(org.apache.syncope.client.console.pages.Login) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException)

Example 2 with ExceptionErrorPage

use of org.apache.wicket.markup.html.pages.ExceptionErrorPage in project wicket by apache.

the class DefaultExceptionMapper method mapUnexpectedExceptions.

/**
 * Maps unexpected exceptions to their corresponding {@link IRequestHandler}.
 *
 * @param e
 * 			the current exception
 * @param application
 * 			the current application object
 * @return the {@link IRequestHandler} for the current exception
 */
protected IRequestHandler mapUnexpectedExceptions(Exception e, final Application application) {
    final ExceptionSettings.UnexpectedExceptionDisplay unexpectedExceptionDisplay = application.getExceptionSettings().getUnexpectedExceptionDisplay();
    logger.error("Unexpected error occurred", e);
    if (ExceptionSettings.SHOW_EXCEPTION_PAGE.equals(unexpectedExceptionDisplay)) {
        Page currentPage = extractCurrentPage();
        return createPageRequestHandler(new PageProvider(new ExceptionErrorPage(e, currentPage)));
    } else if (ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE.equals(unexpectedExceptionDisplay)) {
        return createPageRequestHandler(new PageProvider(application.getApplicationSettings().getInternalErrorPage()));
    }
    // IExceptionSettings.SHOW_NO_EXCEPTION_PAGE
    return new ErrorCodeRequestHandler(500);
}
Also used : ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) ErrorCodeRequestHandler(org.apache.wicket.request.http.handler.ErrorCodeRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage) ExceptionSettings(org.apache.wicket.settings.ExceptionSettings)

Aggregations

PageProvider (org.apache.wicket.core.request.handler.PageProvider)2 ExceptionErrorPage (org.apache.wicket.markup.html.pages.ExceptionErrorPage)2 AccessControlException (java.security.AccessControlException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 Login (org.apache.syncope.client.console.pages.Login)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 UnauthorizedInstantiationException (org.apache.wicket.authorization.UnauthorizedInstantiationException)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 ErrorCodeRequestHandler (org.apache.wicket.request.http.handler.ErrorCodeRequestHandler)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 ExceptionSettings (org.apache.wicket.settings.ExceptionSettings)1