001/** 002 * Copyright 2005-2016 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/ecl2.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 */ 016package org.kuali.rice.kns.web.struts.form.pojo; 017 018import org.apache.commons.logging.Log; 019import org.apache.commons.logging.LogFactory; 020import org.apache.struts.Globals; 021import org.apache.struts.action.ActionForm; 022import org.apache.struts.action.ActionForward; 023import org.apache.struts.action.ActionMapping; 024import org.apache.struts.action.ExceptionHandler; 025import org.apache.struts.config.ExceptionConfig; 026 027import javax.servlet.http.HttpServletRequest; 028import javax.servlet.http.HttpServletResponse; 029 030/** 031 * Handles any AuthorizationException by logging it first and then passing it forward to an explanation page. 032 */ 033public 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 exception.printStackTrace(); 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}