1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.common;
17
18 import org.apache.log4j.Logger;
19 import org.joda.time.DateTime;
20 import org.joda.time.LocalDate;
21 import org.kuali.kpme.core.KPMENamespace;
22 import org.kuali.kpme.core.authorization.DepartmentalRule;
23 import org.kuali.kpme.core.department.Department;
24 import org.kuali.kpme.core.role.KPMERole;
25 import org.kuali.kpme.core.service.HrServiceLocator;
26 import org.kuali.kpme.core.util.HrConstants;
27 import org.kuali.kpme.core.util.HrContext;
28 import org.kuali.kpme.tklm.time.util.TkContext;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31 public class AuthorizationValidationUtils {
32
33 private static final Logger LOG = Logger.getLogger(AuthorizationValidationUtils.class);
34
35
36
37
38
39
40
41
42
43 public static boolean canWildcardWorkArea(DepartmentalRule departmentalRule) {
44 boolean canWildcardWorkArea = false;
45
46 if (HrContext.isSystemAdmin()) {
47 return true;
48 }
49
50 if (departmentalRule != null) {
51 String principalId = GlobalVariables.getUserSession().getPrincipalId();
52 String department = departmentalRule.getDept();
53 Department departmentObj = HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, LocalDate.now());
54 String location = departmentObj != null ? departmentObj.getLocation() : null;
55
56 if (!HrConstants.WILDCARD_CHARACTER.equals(department)) {
57 canWildcardWorkArea = HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment(principalId, KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_ADMINISTRATOR.getRoleName(), department, LocalDate.now().toDateTimeAtStartOfDay())
58 || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment(principalId, KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_ADMINISTRATOR.getRoleName(), department, LocalDate.now().toDateTimeAtStartOfDay())
59 || HrServiceLocator.getKPMERoleService().principalHasRoleInLocation(principalId, KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_ADMINISTRATOR.getRoleName(), location, LocalDate.now().toDateTimeAtStartOfDay())
60 || HrServiceLocator.getKPMERoleService().principalHasRoleInLocation(principalId, KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_ADMINISTRATOR.getRoleName(), location, LocalDate.now().toDateTimeAtStartOfDay());
61 }
62 }
63
64 return canWildcardWorkArea;
65 }
66
67
68
69
70
71
72
73
74 public static boolean canWildcardDepartment(DepartmentalRule departmentalRule) {
75 return HrContext.isSystemAdmin();
76 }
77
78 public static boolean hasAccessToWrite(DepartmentalRule departmentalRule) {
79 boolean hasAccessToWrite = false;
80
81 if (HrContext.isSystemAdmin()) {
82 return true;
83 }
84
85 if (departmentalRule != null) {
86 String principalId = GlobalVariables.getUserSession().getPrincipalId();
87 String department = departmentalRule.getDept();
88 Department departmentObj = HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, LocalDate.now());
89 String location = departmentObj != null ? departmentObj.getLocation() : null;
90
91 if (!HrConstants.WILDCARD_CHARACTER.equals(department)) {
92 hasAccessToWrite = HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment(principalId, KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_ADMINISTRATOR.getRoleName(), department, LocalDate.now().toDateTimeAtStartOfDay())
93 || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment(principalId, KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_ADMINISTRATOR.getRoleName(), department, LocalDate.now().toDateTimeAtStartOfDay())
94 || HrServiceLocator.getKPMERoleService().principalHasRoleInLocation(principalId, KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_ADMINISTRATOR.getRoleName(), location, LocalDate.now().toDateTimeAtStartOfDay())
95 || HrServiceLocator.getKPMERoleService().principalHasRoleInLocation(principalId, KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_ADMINISTRATOR.getRoleName(), location, LocalDate.now().toDateTimeAtStartOfDay());
96 }
97 }
98
99 return hasAccessToWrite;
100 }
101
102
103
104
105
106
107
108
109
110 public static boolean hasAccessToRead(DepartmentalRule departmentalRule) {
111 boolean hasAccessToRead = false;
112
113 if (HrContext.isSystemAdmin() || HrContext.isGlobalViewOnly())
114 return true;
115
116 if (departmentalRule != null) {
117
118
119
120 /
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157