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 | 0 | public class AuthorizationExceptionAction extends Action { |
39 | |
|
40 | |
private static final String MESSAGE_FIELD = "message"; |
41 | |
|
42 | 0 | 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 | 0 | if (LOG.isDebugEnabled()) { |
54 | 0 | LOG.debug(String.format("ENTRY %s%n%s", form.getClass().getSimpleName(), request.getRequestURI())); |
55 | |
} |
56 | |
|
57 | 0 | ActionForward forward = null; |
58 | |
|
59 | 0 | Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_KEY); |
60 | |
|
61 | 0 | if (t == null) { |
62 | 0 | forward = mapping.findForward(KRADConstants.MAPPING_CLOSE); |
63 | |
} else { |
64 | 0 | forward = processException(mapping, form, request, t); |
65 | |
} |
66 | |
|
67 | 0 | if (LOG.isDebugEnabled()) { |
68 | 0 | LOG.debug(String.format("EXIT %s", (forward == null) ? "null" : forward.getPath())); |
69 | |
} |
70 | |
|
71 | 0 | return forward; |
72 | |
} |
73 | |
|
74 | |
private ActionForward processException(ActionMapping mapping, ActionForm form, HttpServletRequest request, Throwable t) throws Exception { |
75 | 0 | Map<String, String> properties = new HashMap<String, String>(); |
76 | 0 | properties.put(MESSAGE_FIELD, t.getMessage()); |
77 | |
|
78 | 0 | request.setAttribute(AuthorizationExceptionAction.class.getName(), properties); |
79 | |
|
80 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
81 | |
} |
82 | |
|
83 | |
} |