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.action; 017 018import org.apache.commons.logging.Log; 019import org.apache.commons.logging.LogFactory; 020import org.apache.struts.Globals; 021import org.apache.struts.action.Action; 022import org.apache.struts.action.ActionForm; 023import org.apache.struts.action.ActionForward; 024import org.apache.struts.action.ActionMapping; 025import org.kuali.rice.core.api.util.RiceConstants; 026import org.kuali.rice.krad.util.KRADConstants; 027 028import javax.servlet.http.HttpServletRequest; 029import javax.servlet.http.HttpServletResponse; 030import java.util.HashMap; 031import java.util.Map; 032 033/** 034 * This is the struts action class for handling the exception for Kuali 035 * applications. 036 * 037 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework. 038 */ 039@Deprecated 040public class AuthorizationExceptionAction extends Action { 041 042 private static final String MESSAGE_FIELD = "message"; 043 044 private static final Log LOG = LogFactory.getLog(AuthorizationExceptionAction.class); 045 046 /** 047 * Dispatches action to be taken during an AuthorizationException. 048 * 049 * @see org.apache.struts.action.Action#execute( 050 * org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, 051 * javax.servlet.http.HttpServletResponse) 052 */ 053 @Override 054 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 055 if (LOG.isDebugEnabled()) { 056 LOG.debug(String.format("ENTRY %s%n%s", form.getClass().getSimpleName(), request.getRequestURI())); 057 } 058 059 ActionForward forward = null; 060 061 Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_KEY); 062 063 if (t == null) { 064 forward = mapping.findForward(KRADConstants.MAPPING_CLOSE); 065 } else { 066 forward = processException(mapping, form, request, t); 067 } 068 069 if (LOG.isDebugEnabled()) { 070 LOG.debug(String.format("EXIT %s", (forward == null) ? "null" : forward.getPath())); 071 } 072 073 return forward; 074 } 075 076 private ActionForward processException(ActionMapping mapping, ActionForm form, HttpServletRequest request, Throwable t) throws Exception { 077 Map<String, String> properties = new HashMap<String, String>(); 078 properties.put(MESSAGE_FIELD, t.getMessage()); 079 080 request.setAttribute(AuthorizationExceptionAction.class.getName(), properties); 081 082 return mapping.findForward(RiceConstants.MAPPING_BASIC); 083 } 084 085}