1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.spring; |
17 | |
|
18 | |
import javax.servlet.http.HttpServletRequest; |
19 | |
import javax.servlet.http.HttpServletResponse; |
20 | |
|
21 | |
import org.apache.log4j.Level; |
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.kuali.rice.core.api.services.CoreApiServiceLocator; |
24 | |
import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator; |
25 | |
import org.kuali.rice.kns.UserSession; |
26 | |
import org.kuali.rice.kns.uif.UifConstants; |
27 | |
import org.kuali.rice.kns.util.GlobalVariables; |
28 | |
import org.kuali.rice.kns.util.KNSConstants; |
29 | |
import org.kuali.rice.kns.util.WebUtils; |
30 | |
import org.kuali.rice.kns.web.spring.controller.UifControllerBase; |
31 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
32 | |
import org.springframework.web.servlet.HandlerInterceptor; |
33 | |
import org.springframework.web.servlet.ModelAndView; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class UifControllerHandlerInterceptor implements HandlerInterceptor { |
42 | |
|
43 | 0 | private static final Logger LOG = Logger.getLogger(UifControllerHandlerInterceptor.class); |
44 | |
|
45 | 0 | private static Boolean OUTPUT_ENCRYPTION_WARNING = null; |
46 | |
|
47 | |
@Override |
48 | |
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
49 | |
|
50 | |
|
51 | 0 | } |
52 | |
|
53 | |
@Override |
54 | |
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
55 | |
|
56 | 0 | if(handler instanceof UifControllerBase) { |
57 | 0 | UifControllerBase controller = (UifControllerBase)handler; |
58 | 0 | UifFormBase form = null; |
59 | |
|
60 | 0 | Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME); |
61 | 0 | if(model instanceof UifFormBase) { |
62 | 0 | form = (UifFormBase)model; |
63 | |
} |
64 | |
|
65 | |
|
66 | 0 | form.setPreviousView(null); |
67 | 0 | request.getSession().setAttribute(form.getFormKey(), model); |
68 | |
|
69 | |
|
70 | 0 | String methodToCall = request.getParameter(KNSConstants.DISPATCH_REQUEST_PARAMETER); |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | if (!controller.getMethodToCallsToNotCheckAuthorization().contains(methodToCall)) { |
76 | 0 | if (LOG.isDebugEnabled()) { |
77 | 0 | LOG.debug("'" + methodToCall + "' not in set of excempt methods: " + controller.getMethodToCallsToNotCheckAuthorization()); |
78 | |
} |
79 | |
|
80 | 0 | controller.checkAuthorization(form, methodToCall); |
81 | |
} else { |
82 | 0 | if (LOG.isDebugEnabled()) { |
83 | 0 | LOG.debug("'" + methodToCall + "' is exempt from auth checks."); |
84 | |
} |
85 | |
} |
86 | |
} |
87 | |
|
88 | |
|
89 | 0 | if (LOG.isEnabledFor(Level.WARN)) { |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
@Override |
105 | |
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
106 | |
|
107 | 0 | final UserSession session = WebUtils.getUserSessionFromRequest(request); |
108 | |
|
109 | 0 | if (session == null) { |
110 | 0 | throw new IllegalStateException("the user session has not been established"); |
111 | |
} |
112 | |
|
113 | 0 | GlobalVariables.setUserSession(session); |
114 | 0 | GlobalVariables.clear(); |
115 | |
|
116 | 0 | return true; |
117 | |
} |
118 | |
|
119 | |
} |