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