View Javadoc

1   /*
2    * Copyright 2005-2010 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl1.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.struts.pojo;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.struts.Globals;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.apache.struts.action.ExceptionHandler;
28  import org.apache.struts.config.ExceptionConfig;
29  
30  /**
31   * Handles any AuthorizationException by logging it first and then passing it forward to an explanation page.
32   */
33  public class AuthorizationExceptionHandler extends ExceptionHandler {
34      
35      private static final String AUTHORIZATION_EXCEPTION_HANDLER = "authorizationExceptionHandler";
36  
37      private static final Log LOG = LogFactory.getLog(AuthorizationExceptionHandler.class);
38      
39      /**
40       * Logs the AuthorizationException before forwarding the user to the explanation page.
41       * 
42       * @see org.apache.struts.action.ExceptionHandler#execute(
43       *      java.lang.Exception, org.apache.struts.config.ExceptionConfig, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, 
44       *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
45       */
46      @Override
47      public ActionForward execute(Exception exception, ExceptionConfig exceptionConfig, ActionMapping mapping, ActionForm form, HttpServletRequest request, 
48              HttpServletResponse response) {
49          
50          if (LOG.isTraceEnabled()) {
51              String message = String.format("ENTRY %s", exception.getMessage());
52              LOG.trace(message);
53          }
54          
55          request.setAttribute(Globals.EXCEPTION_KEY, exception);
56          
57          ActionForward forward = mapping.findForward(AUTHORIZATION_EXCEPTION_HANDLER);
58          
59          if (LOG.isTraceEnabled()) {
60              LOG.trace(String.format("EXIT %s", exception.getMessage()));
61          }
62          
63          return forward;
64      }
65  
66  }