Search in sources :

Example 1 with AuthorizationException

use of fi.otavanopisto.security.AuthorizationException in project muikku by otavanopisto.

the class ExceptionHandler method handle.

@Override
public void handle() throws FacesException {
    for (final Iterator<ExceptionQueuedEvent> queuedEventIterator = getUnhandledExceptionQueuedEvents().iterator(); queuedEventIterator.hasNext(); ) {
        ExceptionQueuedEvent queuedEvent = queuedEventIterator.next();
        ExceptionQueuedEventContext queuedEventContext = queuedEvent.getContext();
        Throwable exception = queuedEventContext.getException();
        while ((exception instanceof FacesException || exception instanceof EJBException || exception instanceof ELException || exception instanceof RewriteException || exception instanceof CreationException || exception instanceof IllegalStateException) && exception.getCause() != null) {
            exception = exception.getCause();
        }
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        try {
            if (exception instanceof AuthorizationException) {
                externalContext.setResponseStatus(HttpServletResponse.SC_FORBIDDEN);
                renderView("/error/access-denied.jsf");
            } else if (exception instanceof FileNotFoundException) {
                externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                renderView("/error/not-found.jsf");
            } else {
                throw new FacesException(exception);
            }
        } finally {
            queuedEventIterator.remove();
        }
    }
    getWrapped().handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) AuthorizationException(fi.otavanopisto.security.AuthorizationException) FileNotFoundException(java.io.FileNotFoundException) CreationException(javax.enterprise.inject.CreationException) FacesException(javax.faces.FacesException) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) RewriteException(org.ocpsoft.rewrite.exception.RewriteException) ExternalContext(javax.faces.context.ExternalContext) ELException(javax.el.ELException) EJBException(javax.ejb.EJBException)

Aggregations

AuthorizationException (fi.otavanopisto.security.AuthorizationException)1 FileNotFoundException (java.io.FileNotFoundException)1 EJBException (javax.ejb.EJBException)1 ELException (javax.el.ELException)1 CreationException (javax.enterprise.inject.CreationException)1 FacesException (javax.faces.FacesException)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)1 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)1 RewriteException (org.ocpsoft.rewrite.exception.RewriteException)1