org.apache.struts.config.ExceptionConfig Java Examples

The following examples show how to use org.apache.struts.config.ExceptionConfig. 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: SecurityExceptionIncidentHandler.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.kuali.rice.kns.web.struts.pojo.StrutsExceptionIncidentHandler#execute(java.lang.Exception, org.apache.struts.config.ExceptionConfig,
 *      org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    AccessSecurityRestrictionInfo restrictionInfo = (AccessSecurityRestrictionInfo) GlobalVariables.getUserSession().retrieveObject(SecConstants.OPEN_DOCUMENT_SECURITY_ACCESS_DENIED_ERROR_KEY);
    if (restrictionInfo != null) {
        String accessMessage = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(SecKeyConstants.MESSAGE_OPEN_DOCUMENT_RESTRICTED);
        accessMessage = StringUtils.replace(accessMessage, "{0}", GlobalVariables.getUserSession().getPrincipalName());
        accessMessage = StringUtils.replace(accessMessage, "{1}", restrictionInfo.getDocumentNumber());
        accessMessage = StringUtils.replace(accessMessage, "{2}", restrictionInfo.getPropertyLabel());
        accessMessage = StringUtils.replace(accessMessage, "{3}", restrictionInfo.getRetrictedValue());
        request.setAttribute(SecConstants.ACCESS_ERROR_STRING_REQUEST_KEY, accessMessage);

        GlobalVariables.getUserSession().removeObject(SecConstants.OPEN_DOCUMENT_SECURITY_ACCESS_DENIED_ERROR_KEY);

        return mapping.findForward(SecConstants.ACCESS_DENIED_ERROR_FORWARD);
    }

    return super.execute(exception, exceptionConfig, mapping, form, request, response);
}
 
Example #2
Source File: FenixDomainExceptionHandler.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionForward execute(Exception ex, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) throws ServletException {

    ActionForward forward = mapping.getInputForward();

    if (ex instanceof DomainException) {
        super.execute(ex, exceptionConfig, mapping, actionForm, request, response);

        DomainException domainException = (DomainException) ex;
        String property = domainException.getKey();
        ActionMessage error = new ActionMessage(domainException.getKey(), domainException.getArgs());
        super.storeException(request, property, error, forward, exceptionConfig.getScope());
    }
    return forward;
}
 
Example #3
Source File: PermissionExceptionHandler.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Custom Handler for HibernateLookupExceptions
 * {@inheritDoc}
 */
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
                             ActionMapping mapping, ActionForm form,
                             HttpServletRequest request, HttpServletResponse response)
                             throws ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    request.setAttribute("error", ex);
    Logger log = Logger.getLogger(PermissionExceptionHandler.class);
    log.error("Permission Error", ex);

    TraceBackEvent evt = new TraceBackEvent();
    RequestContext requestContext = new RequestContext(request);
    User usr = requestContext.getCurrentUser();
    evt.setUser(usr);
    evt.setRequest(request);
    evt.setException(ex);
    MessageQueue.publish(evt);

    return super.execute(ex, exConfig, mapping, form, request, response);
}
 
Example #4
Source File: NoSuchKickstartExceptionHandler.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Custom Handler for HibernateLookupExceptions
 * {@inheritDoc}
 */
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
                             ActionMapping mapping, ActionForm form,
                             HttpServletRequest request, HttpServletResponse response)
                             throws ServletException {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    request.setAttribute("error", ex);


    TraceBackEvent evt = new TraceBackEvent();
    RequestContext requestContext = new RequestContext(request);
    User usr = requestContext.getCurrentUser();
    evt.setUser(usr);
    evt.setRequest(request);
    evt.setException(ex);
    MessageQueue.publish(evt);

    return super.execute(ex, exConfig, mapping, form, request, response);
}
 
Example #5
Source File: AuthorizationExceptionHandler.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Logs the AuthorizationException before forwarding the user to the explanation page.
 * 
 * @see org.apache.struts.action.ExceptionHandler#execute(
 *      java.lang.Exception, org.apache.struts.config.ExceptionConfig, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, 
 *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request, 
        HttpServletResponse response) {
    
    if (LOG.isTraceEnabled()) {
        String message = String.format("ENTRY %s", exception.getMessage());
        LOG.trace(message);
    }
    exception.printStackTrace();
    request.setAttribute(Globals.EXCEPTION_KEY, exception);
    
    ActionForward forward = mapping.findForward(AUTHORIZATION_EXCEPTION_HANDLER);
    
    if (LOG.isTraceEnabled()) {
        LOG.trace(String.format("EXIT %s", exception.getMessage()));
    }
    
    return forward;
}
 
Example #6
Source File: PermissionExceptionHandler.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Custom Handler for HibernateLookupExceptions
 * {@inheritDoc}
 */
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
                             ActionMapping mapping, ActionForm form,
                             HttpServletRequest request, HttpServletResponse response)
                             throws ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    request.setAttribute("error", ex);
    Logger log = Logger.getLogger(PermissionExceptionHandler.class);
    log.error("Permission Error", ex);

    TraceBackEvent evt = new TraceBackEvent();
    RequestContext requestContext = new RequestContext(request);
    User usr = requestContext.getCurrentUser();
    evt.setUser(usr);
    evt.setRequest(request);
    evt.setException(ex);
    MessageQueue.publish(evt);

    return super.execute(ex, exConfig, mapping, form, request, response);
}
 
Example #7
Source File: NoSuchKickstartExceptionHandler.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Custom Handler for HibernateLookupExceptions
 * {@inheritDoc}
 */
public ActionForward execute(Exception ex, ExceptionConfig exConfig,
                             ActionMapping mapping, ActionForm form,
                             HttpServletRequest request, HttpServletResponse response)
                             throws ServletException {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    request.setAttribute("error", ex);


    TraceBackEvent evt = new TraceBackEvent();
    RequestContext requestContext = new RequestContext(request);
    User usr = requestContext.getCurrentUser();
    evt.setUser(usr);
    evt.setRequest(request);
    evt.setException(ex);
    MessageQueue.publish(evt);

    return super.execute(ex, exConfig, mapping, form, request, response);
}
 
Example #8
Source File: BadParameterExceptionHandler.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ActionForward execute(Exception exIn, ExceptionConfig aeIn,
        ActionMapping mappingIn, ActionForm formInstanceIn,
        HttpServletRequest requestIn, HttpServletResponse responseIn)
    throws ServletException {
    exception = (BadParameterException) exIn;
    requestIn.setAttribute("error", exception);
    responseIn.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return super.execute(exception, aeIn, mappingIn, formInstanceIn, requestIn,
            responseIn);
}
 
Example #9
Source File: InvalidPathExceptionHandler.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ActionForward execute(Exception ex, 
           ExceptionConfig exConfig,
           ActionMapping mapping,
           ActionForm formInstance,
           HttpServletRequest request,
           HttpServletResponse response
	) throws ServletException {
	
	logger.error("No path was found for this action.");
	// interesting point here, the ActionMapping mapping is "null".
	// Therefore mapping.findForward("error") quits with a null pointer exception :-(
	return null;
}
 
Example #10
Source File: LookupExceptionHandler.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ActionForward execute(Exception exIn, ExceptionConfig aeIn,
        ActionMapping mappingIn, ActionForm formInstanceIn,
        HttpServletRequest requestIn, HttpServletResponse responseIn)
    throws ServletException {
    exception = (LookupException) exIn;
    requestIn.setAttribute("error", exception);
    responseIn.setStatus(HttpServletResponse.SC_FORBIDDEN);
    return super.execute(exception, aeIn, mappingIn, formInstanceIn, requestIn,
            responseIn);
}
 
Example #11
Source File: LookupExceptionHandler.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ActionForward execute(Exception exIn, ExceptionConfig aeIn,
        ActionMapping mappingIn, ActionForm formInstanceIn,
        HttpServletRequest requestIn, HttpServletResponse responseIn)
    throws ServletException {
    exception = (LookupException) exIn;
    requestIn.setAttribute("error", exception);
    responseIn.setStatus(HttpServletResponse.SC_FORBIDDEN);
    return super.execute(exception, aeIn, mappingIn, formInstanceIn, requestIn,
            responseIn);
}
 
Example #12
Source File: BadParameterExceptionHandler.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ActionForward execute(Exception exIn, ExceptionConfig aeIn,
        ActionMapping mappingIn, ActionForm formInstanceIn,
        HttpServletRequest requestIn, HttpServletResponse responseIn)
    throws ServletException {
    exception = (BadParameterException) exIn;
    requestIn.setAttribute("error", exception);
    responseIn.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return super.execute(exception, aeIn, mappingIn, formInstanceIn, requestIn,
            responseIn);
}
 
Example #13
Source File: NotAllowedActionExceptionHandler.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ActionForward execute(Exception ex, 
           ExceptionConfig exConfig,
           ActionMapping mapping,
           ActionForm formInstance,
           HttpServletRequest request,
           HttpServletResponse response
	) throws ServletException {

       ActionForward actionForward = new ActionForward();
       actionForward.setPath(exConfig.getPath());
       actionForward.setRedirect(true);
       return actionForward;
}
 
Example #14
Source File: LookupExceptionHandlerTest.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks
         * Logging complains and sends warnings (expected)
         * Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(LookupExceptionHandler.class);
        Level orig = log.getLevel();
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail", "");
        try {
            log.setLevel(Level.OFF);
            c.setString("web.traceback_mail", "[email protected]");

            LookupException ex = new LookupException("Simply a test");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());

            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            LookupExceptionHandler leh = new LookupExceptionHandler();

            leh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
            assertEquals(ex, request.getAttribute("error"));
        }
        finally {
            //Turn tracebacks and logging back on
            Thread.sleep(1000); //wait for message to be sent
            c.setString("web.traceback_mail", mail);
            log.setLevel(orig);
        }
    }
 
Example #15
Source File: BadParameterExceptionHandlerTest.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks
         * Logging complains and sends warnings (expected)
         * Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(BadParameterExceptionHandler.class);
        Level origLevel = log.getLevel();
        log.setLevel(Level.OFF);
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail");
        try {
            c.setString("web.traceback_mail", "[email protected]");

            BadParameterException ex =
                new BadParameterException("Invalid test parameter");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            // mockup a dumb ass Enumeration class for the Mock request
            // jmock RULES!
            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());
            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            BadParameterExceptionHandler bpeh = new BadParameterExceptionHandler();

            bpeh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
        }
        finally {
            // Turn tracebacks and logging back on
            // wait for message to be sent
            int tries = 0;
            Thread.sleep(1000);
            while (MessageQueue.getMessageCount() != 0 && tries  < 10) {
                Thread.sleep(100);
                tries++;
            }
            // don't bother resetting it if it were already missing.
            // Blame mmccune for change getString to return freakin null.
            if (mail != null) {
                c.setString("web.traceback_mail", mail);
            }
            log.setLevel(origLevel);
        }
    }
 
Example #16
Source File: PermissionExceptionHandlerTest.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks Logging complains and sends warnings
         * (expected) Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(PermissionExceptionHandler.class);
        Level orig = log.getLevel();
        log.setLevel(Level.OFF);
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail", "");
        try {
            c.setString("web.traceback_mail", "[email protected]");

            PermissionException ex = new PermissionException("Simply a test");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());

            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            response.setExpectedSetStatusCalls(1);
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            PermissionExceptionHandler peh = new PermissionExceptionHandler();

            peh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
            assertEquals(ex, request.getAttribute("error"));
            response.verify();
        }
        finally {
            // Turn tracebacks and logging back on
            Thread.sleep(1000); // wait for message to be sent
            c.setString("web.traceback_mail", mail);
            log.setLevel(orig);
        }
    }
 
Example #17
Source File: LookupExceptionHandlerTest.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks
         * Logging complains and sends warnings (expected)
         * Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(LookupExceptionHandler.class);
        Level orig = log.getLevel();
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail", "");
        try {
            log.setLevel(Level.OFF);
            c.setString("web.traceback_mail", "[email protected]");

            LookupException ex = new LookupException("Simply a test");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());

            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            LookupExceptionHandler leh = new LookupExceptionHandler();

            leh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
            assertEquals(ex, request.getAttribute("error"));
        }
        finally {
            //Turn tracebacks and logging back on
            Thread.sleep(1000); //wait for message to be sent
            c.setString("web.traceback_mail", mail);
            log.setLevel(orig);
        }
    }
 
Example #18
Source File: BadParameterExceptionHandlerTest.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks
         * Logging complains and sends warnings (expected)
         * Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(BadParameterExceptionHandler.class);
        Level origLevel = log.getLevel();
        log.setLevel(Level.OFF);
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail");
        try {
            c.setString("web.traceback_mail", "[email protected]");

            BadParameterException ex =
                new BadParameterException("Invalid test parameter");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            // mockup a dumb ass Enumeration class for the Mock request
            // jmock RULES!
            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());
            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            BadParameterExceptionHandler bpeh = new BadParameterExceptionHandler();

            bpeh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
        }
        finally {
            // Turn tracebacks and logging back on
            // wait for message to be sent
            int tries = 0;
            Thread.sleep(1000);
            while (MessageQueue.getMessageCount() != 0 && tries  < 10) {
                Thread.sleep(100);
                tries++;
            }
            // don't bother resetting it if it were already missing.
            // Blame mmccune for change getString to return freakin null.
            if (mail != null) {
                c.setString("web.traceback_mail", mail);
            }
            log.setLevel(origLevel);
        }
    }
 
Example #19
Source File: PermissionExceptionHandlerTest.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
public void testExecute() throws Exception {

        /*
         * Turn off logging and tracebacks Logging complains and sends warnings
         * (expected) Tracebacks will get sent to root@localhost
         */
        Logger log = Logger.getLogger(PermissionExceptionHandler.class);
        Level orig = log.getLevel();
        log.setLevel(Level.OFF);
        Config c = Config.get();
        String mail = c.getString("web.traceback_mail", "");
        try {
            c.setString("web.traceback_mail", "[email protected]");

            PermissionException ex = new PermissionException("Simply a test");

            final ActionMapping mapping = mock(ActionMapping.class, "mapping");
            context().checking(new Expectations() { {
                oneOf(mapping).getInputForward();
                will(returnValue(new ActionForward()));
            } });

            RhnMockHttpServletRequest request = TestUtils
                    .getRequestWithSessionAndUser();
            request.setupGetHeaderNames(new Vector<String>().elements());
            request.setupGetMethod("POST");
            request.setupGetRequestURI("http://localhost:8080");
            request.setupGetParameterNames(new Vector<String>().elements());

            RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();
            response.setExpectedSetStatusCalls(1);
            RhnMockDynaActionForm form = new RhnMockDynaActionForm();

            PermissionExceptionHandler peh = new PermissionExceptionHandler();

            peh.execute(ex, new ExceptionConfig(), mapping, form, request, response);
            assertEquals(ex, request.getAttribute("error"));
            response.verify();
        }
        finally {
            // Turn tracebacks and logging back on
            Thread.sleep(1000); // wait for message to be sent
            c.setString("web.traceback_mail", mail);
            log.setLevel(orig);
        }
    }