| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.web.struts.action; |
| 17 | |
|
| 18 | |
import java.util.HashMap; |
| 19 | |
import java.util.Map; |
| 20 | |
|
| 21 | |
import javax.servlet.http.HttpServletRequest; |
| 22 | |
import javax.servlet.http.HttpServletResponse; |
| 23 | |
|
| 24 | |
import org.apache.commons.logging.Log; |
| 25 | |
import org.apache.commons.logging.LogFactory; |
| 26 | |
import org.apache.struts.Globals; |
| 27 | |
import org.apache.struts.action.Action; |
| 28 | |
import org.apache.struts.action.ActionForm; |
| 29 | |
import org.apache.struts.action.ActionForward; |
| 30 | |
import org.apache.struts.action.ActionMapping; |
| 31 | |
import org.kuali.rice.core.util.RiceConstants; |
| 32 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class AuthorizationExceptionAction extends Action { |
| 40 | |
|
| 41 | |
private static final String MESSAGE_FIELD = "message"; |
| 42 | |
|
| 43 | 0 | private static final Log LOG = LogFactory.getLog(AuthorizationExceptionAction.class); |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
@Override |
| 53 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 54 | 0 | if (LOG.isDebugEnabled()) { |
| 55 | 0 | LOG.debug(String.format("ENTRY %s%n%s", form.getClass().getSimpleName(), request.getRequestURI())); |
| 56 | |
} |
| 57 | |
|
| 58 | 0 | ActionForward forward = null; |
| 59 | |
|
| 60 | 0 | Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_KEY); |
| 61 | |
|
| 62 | 0 | if (t == null) { |
| 63 | 0 | forward = mapping.findForward(KNSConstants.MAPPING_CLOSE); |
| 64 | |
} else { |
| 65 | 0 | forward = processException(mapping, form, request, t); |
| 66 | |
} |
| 67 | |
|
| 68 | 0 | if (LOG.isDebugEnabled()) { |
| 69 | 0 | LOG.debug(String.format("EXIT %s", (forward == null) ? "null" : forward.getPath())); |
| 70 | |
} |
| 71 | |
|
| 72 | 0 | return forward; |
| 73 | |
} |
| 74 | |
|
| 75 | |
private ActionForward processException(ActionMapping mapping, ActionForm form, HttpServletRequest request, Throwable t) throws Exception { |
| 76 | 0 | Map<String, String> properties = new HashMap<String, String>(); |
| 77 | 0 | properties.put(MESSAGE_FIELD, t.getMessage()); |
| 78 | |
|
| 79 | 0 | request.setAttribute(AuthorizationExceptionAction.class.getName(), properties); |
| 80 | |
|
| 81 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 82 | |
} |
| 83 | |
|
| 84 | |
} |