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