1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.controller;
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.lang.StringUtils;
25 import org.apache.log4j.Logger;
26 import org.kuali.rice.kim.api.KimConstants;
27 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29 import org.kuali.rice.krad.service.KualiModuleService;
30 import org.kuali.rice.krad.service.ModuleService;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.KRADConstants;
33 import org.springframework.web.servlet.HandlerInterceptor;
34 import org.springframework.web.servlet.ModelAndView;
35
36
37
38
39
40
41
42 public class ModuleLockingHandlerInterceptor implements HandlerInterceptor {
43 private static final Logger LOG = Logger.getLogger(ModuleLockingHandlerInterceptor.class);
44
45 private KualiModuleService kualiModuleService;
46 private String moduleLockedMapping;
47
48
49
50
51
52 @Override
53 public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
54 Exception exception) throws Exception {
55
56 }
57
58
59
60
61
62 @Override
63 public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
64 ModelAndView modelAndview) throws Exception {
65
66 }
67
68
69
70
71
72 @Override
73 public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
74 Object handler) throws Exception {
75 if (isModuleLocked(request)) {
76 response.sendRedirect(this.getModuleLockedMapping() + "?" + ModuleLockedController.MODULE_PARAMETER
77 + "=" + getModuleService(request).getModuleConfiguration().getNamespaceCode());
78
79 return false;
80 }
81
82 return true;
83 }
84
85
86
87
88
89
90
91 protected boolean isModuleLocked(HttpServletRequest request) {
92 ModuleService moduleService = getModuleService(request);
93
94 if (moduleService != null && moduleService.isLocked()) {
95 String principalId = GlobalVariables.getUserSession().getPrincipalId();
96 String namespaceCode = KRADConstants.KUALI_RICE_SYSTEM_NAMESPACE;
97 String permissionName = KimConstants.PermissionNames.ACCESS_LOCKED_MODULE;
98
99 Map<String, String> permissionDetails = new HashMap<String, String>();
100 Map<String, String> qualification = new HashMap<String, String>();
101 if (!KimApiServiceLocator.getPermissionService().isAuthorized(principalId, namespaceCode, permissionName,
102 qualification)) {
103 return true;
104 }
105 }
106
107 return false;
108 }
109
110
111
112
113
114
115
116 protected ModuleService getModuleService(HttpServletRequest request) {
117 String boClass = request.getParameter(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE);
118 if (StringUtils.isBlank(boClass)) {
119 boClass = request.getParameter(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE);
120 }
121
122 ModuleService moduleService = null;
123 if (StringUtils.isNotBlank(boClass)) {
124 try {
125 moduleService = getKualiModuleService().getResponsibleModuleService(Class.forName(boClass));
126 } catch (ClassNotFoundException classNotFoundException) {
127 LOG.warn("BO class not found: " + boClass, classNotFoundException);
128 }
129 } else {
130 moduleService = getKualiModuleService().getResponsibleModuleService(this.getClass());
131 }
132
133 return moduleService;
134 }
135
136 public String getModuleLockedMapping() {
137 return this.moduleLockedMapping;
138 }
139
140 public void setModuleLockedMapping(String moduleLockedMapping) {
141 this.moduleLockedMapping = moduleLockedMapping;
142 }
143
144 public void setKualiModuleService(KualiModuleService kualiModuleService) {
145 this.kualiModuleService = kualiModuleService;
146 }
147
148 protected KualiModuleService getKualiModuleService() {
149 if (kualiModuleService == null) {
150 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
151 }
152 return kualiModuleService;
153 }
154 }