001 /*
002 * Copyright 2005-2010 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl1.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kns.web.struts.pojo;
017
018 import javax.servlet.http.HttpServletRequest;
019 import javax.servlet.http.HttpServletResponse;
020
021 import org.apache.commons.logging.Log;
022 import org.apache.commons.logging.LogFactory;
023 import org.apache.struts.Globals;
024 import org.apache.struts.action.ActionForm;
025 import org.apache.struts.action.ActionForward;
026 import org.apache.struts.action.ActionMapping;
027 import org.apache.struts.action.ExceptionHandler;
028 import org.apache.struts.config.ExceptionConfig;
029
030 /**
031 * Handles any AuthorizationException by logging it first and then passing it forward to an explanation page.
032 */
033 public class AuthorizationExceptionHandler extends ExceptionHandler {
034
035 private static final String AUTHORIZATION_EXCEPTION_HANDLER = "authorizationExceptionHandler";
036
037 private static final Log LOG = LogFactory.getLog(AuthorizationExceptionHandler.class);
038
039 /**
040 * Logs the AuthorizationException before forwarding the user to the explanation page.
041 *
042 * @see org.apache.struts.action.ExceptionHandler#execute(
043 * java.lang.Exception, org.apache.struts.config.ExceptionConfig, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
044 * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
045 */
046 @Override
047 public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request,
048 HttpServletResponse response) {
049
050 if (LOG.isTraceEnabled()) {
051 String message = String.format("ENTRY %s", exception.getMessage());
052 LOG.trace(message);
053 }
054
055 request.setAttribute(Globals.EXCEPTION_KEY, exception);
056
057 ActionForward forward = mapping.findForward(AUTHORIZATION_EXCEPTION_HANDLER);
058
059 if (LOG.isTraceEnabled()) {
060 LOG.trace(String.format("EXIT %s", exception.getMessage()));
061 }
062
063 return forward;
064 }
065
066 }