1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.permission; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
21 | |
import org.kuali.rice.core.api.exception.RiceIllegalStateException; |
22 | |
import org.kuali.rice.kim.api.common.assignee.Assignee; |
23 | |
import org.kuali.rice.kim.api.common.delegate.DelegateType; |
24 | |
import org.kuali.rice.kim.api.common.template.Template; |
25 | |
import org.kuali.rice.kim.api.permission.Permission; |
26 | |
import org.kuali.rice.kim.api.permission.PermissionService; |
27 | |
import org.kuali.rice.kim.api.permission.PermissionTypeService; |
28 | |
import org.kuali.rice.kim.api.role.Role; |
29 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
30 | |
import org.kuali.rice.kim.api.role.RoleService; |
31 | |
import org.kuali.rice.kim.api.type.KimType; |
32 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
33 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
34 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
35 | |
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
36 | |
import org.kuali.rice.kim.util.KimConstants; |
37 | |
import org.kuali.rice.kns.lookup.Lookupable; |
38 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
39 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
40 | |
import org.kuali.rice.krad.lookup.CollectionIncomplete; |
41 | |
import org.kuali.rice.krad.service.BusinessObjectDictionaryService; |
42 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
43 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
44 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
45 | |
|
46 | |
import javax.jws.WebService; |
47 | |
import java.util.ArrayList; |
48 | |
import java.util.Collection; |
49 | |
import java.util.Collections; |
50 | |
import java.util.Comparator; |
51 | |
import java.util.HashMap; |
52 | |
import java.util.List; |
53 | |
import java.util.Map; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@SuppressWarnings("unused") |
62 | |
@WebService(endpointInterface = KIMWebServiceConstants.PermissionService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.PermissionService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.PermissionService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
63 | 0 | public class PermissionServiceImpl extends PermissionServiceBase implements PermissionService { |
64 | 0 | private static final Logger LOG = Logger.getLogger( PermissionServiceImpl.class ); |
65 | |
|
66 | |
private RoleService roleService; |
67 | |
private PermissionDao permissionDao; |
68 | |
private PermissionTypeService defaultPermissionTypeService; |
69 | |
private DataDictionaryService dataDictionaryService; |
70 | |
private KimTypeInfoService kimTypeInfoService; |
71 | |
private BusinessObjectDictionaryService businessObjectDictionaryService; |
72 | |
|
73 | |
private List<Template> allTemplates; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
protected PermissionTypeService getPermissionTypeService( String namespaceCode, String permissionTemplateName, String permissionName, String permissionId ) { |
80 | 0 | StringBuffer cacheKey = new StringBuffer(); |
81 | 0 | if ( namespaceCode != null ) { |
82 | 0 | cacheKey.append( namespaceCode ); |
83 | |
} |
84 | 0 | cacheKey.append( '|' ); |
85 | 0 | if ( permissionTemplateName != null ) { |
86 | 0 | cacheKey.append( permissionTemplateName ); |
87 | |
} |
88 | 0 | cacheKey.append( '|' ); |
89 | 0 | if ( permissionName != null ) { |
90 | 0 | cacheKey.append( permissionName ); |
91 | |
} |
92 | 0 | cacheKey.append( '|' ); |
93 | 0 | if ( permissionId != null ) { |
94 | 0 | cacheKey.append( permissionId ); |
95 | |
} |
96 | 0 | String key = cacheKey.toString(); |
97 | 0 | PermissionTypeService service = getPermissionTypeServiceByNameCache().get(key); |
98 | 0 | if ( service == null ) { |
99 | 0 | PermissionTemplateBo permTemplate = null; |
100 | 0 | if ( permissionTemplateName != null ) { |
101 | 0 | PermissionBo perms = getPermissionImplsByTemplateName(namespaceCode, permissionTemplateName); |
102 | 0 | permTemplate = perms.getTemplate(); |
103 | 0 | } else if ( permissionName != null ) { |
104 | 0 | PermissionBo perms = getPermissionImplsByName(namespaceCode, permissionName); |
105 | 0 | permTemplate = perms.getTemplate(); |
106 | 0 | } else if ( permissionId != null ) { |
107 | 0 | PermissionBo perm = getPermissionImpl(permissionId); |
108 | 0 | if ( perm != null ) { |
109 | 0 | permTemplate = perm.getTemplate(); |
110 | |
} |
111 | |
} |
112 | 0 | service = getPermissionTypeService( permTemplate ); |
113 | 0 | getPermissionTypeServiceByNameCache().put(key, service); |
114 | |
} |
115 | 0 | return service; |
116 | |
} |
117 | |
|
118 | |
protected PermissionTypeService getPermissionTypeService( PermissionTemplateBo permissionTemplate ) { |
119 | 0 | if ( permissionTemplate == null ) { |
120 | 0 | throw new IllegalArgumentException( "permissionTemplate may not be null" ); |
121 | |
} |
122 | 0 | KimType kimType = kimTypeInfoService.getKimType( permissionTemplate.getKimTypeId() ); |
123 | 0 | String serviceName = kimType.getServiceName(); |
124 | |
|
125 | 0 | if ( StringUtils.isBlank( serviceName ) ) { |
126 | 0 | return defaultPermissionTypeService; |
127 | |
} |
128 | |
try { |
129 | 0 | Object service = KIMServiceLocatorWeb.getService(serviceName); |
130 | |
|
131 | 0 | if ( service == null ) { |
132 | 0 | throw new RuntimeException("null returned for permission type service for service name: " + serviceName); |
133 | |
} |
134 | |
|
135 | 0 | if ( !(service instanceof PermissionTypeService) ) { |
136 | 0 | throw new RuntimeException( "Service " + serviceName + " was not a PermissionTypeService. Was: " + service.getClass().getName() ); |
137 | |
} |
138 | 0 | return (PermissionTypeService)service; |
139 | 0 | } catch( Exception ex ) { |
140 | |
|
141 | 0 | throw new RuntimeException( "Error retrieving service: " + serviceName + " from the KIMServiceLocatorInternal.", ex ); |
142 | |
} |
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public boolean hasPermission(String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails) { |
149 | 0 | return isAuthorized( principalId, namespaceCode, permissionName, permissionDetails, null ); |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public boolean isAuthorized(String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
156 | 0 | List<String> roleIds = getRoleIdsForPermission( namespaceCode, permissionName, permissionDetails ); |
157 | 0 | if ( roleIds.isEmpty() ) { |
158 | 0 | return false; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | 0 | return roleService.principalHasRole( principalId, roleIds, qualification); |
164 | |
|
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public boolean hasPermissionByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails) { |
171 | 0 | return isAuthorizedByTemplateName( principalId, namespaceCode, permissionTemplateName, permissionDetails, null ); |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public boolean isAuthorizedByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
178 | 0 | List<String> roleIds = getRoleIdsForPermissionTemplate( namespaceCode, permissionTemplateName, permissionDetails ); |
179 | 0 | if ( roleIds.isEmpty() ) { |
180 | 0 | return false; |
181 | |
} |
182 | 0 | return roleService.principalHasRole( principalId, roleIds, qualification); |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public List<Permission> getAuthorizedPermissions( String principalId, String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
189 | |
|
190 | 0 | PermissionBo permissions = getPermissionImplsByName( namespaceCode, permissionName ); |
191 | |
|
192 | 0 | List<Permission> applicablePermissions = getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ); |
193 | 0 | return getPermissionsForUser(principalId, applicablePermissions, qualification); |
194 | |
} |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
public List<Permission> getAuthorizedPermissionsByTemplateName( String principalId, String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
200 | |
|
201 | 0 | PermissionBo permissions = getPermissionImplsByTemplateName( namespaceCode, permissionTemplateName ); |
202 | |
|
203 | 0 | List<Permission> applicablePermissions = getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ); |
204 | 0 | return getPermissionsForUser(principalId, applicablePermissions, qualification); |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
protected List<Permission> getPermissionsForUser( String principalId, List<Permission> permissions, Map<String, String> qualification ) { |
211 | 0 | ArrayList<Permission> results = new ArrayList<Permission>(); |
212 | 0 | List<Permission> tempList = new ArrayList<Permission>(1); |
213 | 0 | for ( Permission perm : permissions ) { |
214 | 0 | tempList.clear(); |
215 | 0 | tempList.add( perm ); |
216 | 0 | List<String> roleIds = permissionDao.getRoleIdsForPermissions( tempList ); |
217 | |
|
218 | |
|
219 | |
|
220 | 0 | if ( roleIds != null && !roleIds.isEmpty() ) { |
221 | 0 | if ( roleService.principalHasRole( principalId, roleIds, qualification) ) { |
222 | 0 | results.add( perm ); |
223 | |
} |
224 | |
} |
225 | 0 | } |
226 | |
|
227 | 0 | return results; |
228 | |
} |
229 | |
|
230 | |
protected Map<String,PermissionTypeService> getPermissionTypeServicesByTemplateId( Collection<PermissionBo> permissions ) { |
231 | 0 | Map<String,PermissionTypeService> permissionTypeServices = new HashMap<String, PermissionTypeService>( permissions.size() ); |
232 | 0 | for ( PermissionBo perm : permissions ) { |
233 | 0 | permissionTypeServices.put(perm.getTemplateId(), getPermissionTypeService( perm.getTemplate() ) ); |
234 | |
} |
235 | 0 | return permissionTypeServices; |
236 | |
} |
237 | |
|
238 | |
@SuppressWarnings("static-access") |
239 | |
protected Map<String,List<Permission>> groupPermissionsByTemplate( Collection<PermissionBo> permissions ) { |
240 | 0 | Map<String,List<Permission>> results = new HashMap<String,List<Permission>>(); |
241 | 0 | for ( PermissionBo perm : permissions ) { |
242 | 0 | List<Permission> perms = results.get( perm.getTemplateId() ); |
243 | 0 | if ( perms == null ) { |
244 | 0 | perms = new ArrayList<Permission>(); |
245 | 0 | results.put( perm.getTemplateId(), perms ); |
246 | |
} |
247 | 0 | perms.add( perm.to(perm) ); |
248 | 0 | } |
249 | 0 | return results; |
250 | |
} |
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
protected List<Permission> getMatchingPermissions( List<PermissionBo> permissions, Map<String, String> permissionDetails ) { |
257 | 0 | List<Permission> applicablePermissions = new ArrayList<Permission>(); |
258 | 0 | if ( permissionDetails == null || permissionDetails.isEmpty() ) { |
259 | |
|
260 | 0 | for ( PermissionBo perm : permissions ) { |
261 | 0 | applicablePermissions.add( PermissionBo.to(perm) ); |
262 | |
} |
263 | |
} else { |
264 | |
|
265 | |
|
266 | 0 | Map<String,PermissionTypeService> permissionTypeServices = getPermissionTypeServicesByTemplateId( permissions ); |
267 | |
|
268 | 0 | Map<String,List<Permission>> permissionMap = groupPermissionsByTemplate( permissions ); |
269 | |
|
270 | |
|
271 | 0 | for ( String templateId : permissionMap.keySet() ) { |
272 | 0 | PermissionTypeService permissionTypeService = permissionTypeServices.get( templateId ); |
273 | 0 | List<Permission> permissionList = permissionMap.get( templateId ); |
274 | 0 | applicablePermissions.addAll( permissionTypeService.getMatchingPermissions( permissionDetails, permissionList ) ); |
275 | 0 | } |
276 | |
} |
277 | 0 | return applicablePermissions; |
278 | |
} |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
public List<Assignee> getPermissionAssignees( String namespaceCode, String permissionName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
284 | 0 | List<Assignee> results = new ArrayList<Assignee>(); |
285 | 0 | List<String> roleIds = getRoleIdsForPermission( namespaceCode, permissionName, permissionDetails); |
286 | 0 | if ( roleIds.isEmpty() ) { |
287 | 0 | return results; |
288 | |
} |
289 | 0 | Collection<RoleMembership> roleMembers = roleService.getRoleMembers( roleIds,qualification ); |
290 | 0 | for ( RoleMembership rm : roleMembers ) { |
291 | 0 | List<DelegateType.Builder> delegateBuilderList = new ArrayList<DelegateType.Builder>(); |
292 | 0 | if (!rm.getDelegates().isEmpty()) { |
293 | 0 | for (DelegateType delegate : rm.getDelegates()){ |
294 | 0 | delegateBuilderList.add(DelegateType.Builder.create(delegate)); |
295 | |
} |
296 | |
} |
297 | 0 | if ( rm.getMemberTypeCode().equals( Role.PRINCIPAL_MEMBER_TYPE ) ) { |
298 | 0 | results.add (Assignee.Builder.create(rm.getMemberId(), null, delegateBuilderList).build()); |
299 | 0 | } else if ( rm.getMemberTypeCode().equals( Role.GROUP_MEMBER_TYPE ) ) { |
300 | 0 | results.add (Assignee.Builder.create(null, rm.getMemberId(), delegateBuilderList).build()); |
301 | |
} |
302 | 0 | } |
303 | 0 | return results; |
304 | |
} |
305 | |
|
306 | |
public List<Assignee> getPermissionAssigneesForTemplateName( String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails, Map<String, String> qualification ) { |
307 | 0 | List<Assignee> results = new ArrayList<Assignee>(); |
308 | 0 | List<String> roleIds = getRoleIdsForPermissionTemplate( namespaceCode, permissionTemplateName, permissionDetails); |
309 | 0 | if ( roleIds.isEmpty() ) { |
310 | 0 | return results; |
311 | |
} |
312 | 0 | Collection<RoleMembership> roleMembers = roleService.getRoleMembers( roleIds,qualification); |
313 | 0 | for ( RoleMembership rm : roleMembers ) { |
314 | 0 | List<DelegateType.Builder> delegateBuilderList = new ArrayList<DelegateType.Builder>(); |
315 | 0 | if (!rm.getDelegates().isEmpty()) { |
316 | 0 | for (DelegateType delegate : rm.getDelegates()){ |
317 | 0 | delegateBuilderList.add(DelegateType.Builder.create(delegate)); |
318 | |
} |
319 | |
} |
320 | 0 | if ( rm.getMemberTypeCode().equals( Role.PRINCIPAL_MEMBER_TYPE ) ) { |
321 | 0 | results.add (Assignee.Builder.create(rm.getMemberId(), null, delegateBuilderList).build()); |
322 | |
} else { |
323 | 0 | results.add (Assignee.Builder.create(null, rm.getMemberId(), delegateBuilderList).build()); |
324 | |
} |
325 | 0 | } |
326 | 0 | return results; |
327 | |
} |
328 | |
|
329 | |
public boolean isPermissionAssigned( String namespaceCode, String permissionName, Map<String, String> permissionDetails ) { |
330 | 0 | return !getRoleIdsForPermission(namespaceCode, permissionName, permissionDetails).isEmpty(); |
331 | |
} |
332 | |
|
333 | |
public boolean isPermissionDefined( String namespaceCode, String permissionName, Map<String, String> permissionDetails ) { |
334 | |
|
335 | 0 | PermissionBo permissions = getPermissionImplsByName( namespaceCode, permissionName ); |
336 | |
|
337 | 0 | return !getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ).isEmpty(); |
338 | |
} |
339 | |
|
340 | |
public boolean isPermissionDefinedForTemplateName( String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails ) { |
341 | |
|
342 | 0 | PermissionBo permissions = getPermissionImplsByTemplateName( namespaceCode, permissionTemplateName ); |
343 | |
|
344 | 0 | return !getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ).isEmpty(); |
345 | |
} |
346 | |
|
347 | |
public List<String> getRoleIdsForPermission( String namespaceCode, String permissionName, Map<String, String> permissionDetails) { |
348 | |
|
349 | 0 | PermissionBo permissions = getPermissionImplsByName( namespaceCode, permissionName ); |
350 | |
|
351 | 0 | List<Permission> applicablePermissions = getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ); |
352 | 0 | List<String> roleIds = getRolesForPermissionsFromCache( applicablePermissions ); |
353 | 0 | if ( roleIds == null ) { |
354 | 0 | roleIds = permissionDao.getRoleIdsForPermissions( applicablePermissions ); |
355 | 0 | addRolesForPermissionsToCache( applicablePermissions, roleIds ); |
356 | |
} |
357 | 0 | return roleIds; |
358 | |
} |
359 | |
|
360 | |
protected List<String> getRoleIdsForPermissionTemplate( String namespaceCode, String permissionTemplateName, Map<String, String> permissionDetails ) { |
361 | |
|
362 | 0 | PermissionBo permissions = getPermissionImplsByTemplateName( namespaceCode, permissionTemplateName ); |
363 | |
|
364 | 0 | List<Permission> applicablePermissions = getMatchingPermissions( Collections.singletonList(permissions), permissionDetails ); |
365 | 0 | List<String> roleIds = getRolesForPermissionsFromCache( applicablePermissions ); |
366 | 0 | if ( roleIds == null ) { |
367 | 0 | roleIds = permissionDao.getRoleIdsForPermissions( applicablePermissions ); |
368 | 0 | addRolesForPermissionsToCache( applicablePermissions, roleIds ); |
369 | |
} |
370 | 0 | return roleIds; |
371 | |
} |
372 | |
|
373 | |
public List<String> getRoleIdsForPermissions( List<Permission> permissions ) { |
374 | 0 | List<String> roleIds = getRolesForPermissionsFromCache( permissions ); |
375 | 0 | if ( roleIds == null ) { |
376 | 0 | roleIds = permissionDao.getRoleIdsForPermissions( permissions ); |
377 | 0 | addRolesForPermissionsToCache( permissions, roleIds ); |
378 | |
} |
379 | 0 | return roleIds; |
380 | |
} |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
public Permission getPermission(String permissionId) { |
390 | 0 | PermissionBo impl = getPermissionImpl( permissionId ); |
391 | 0 | if ( impl != null ) { |
392 | 0 | return PermissionBo.to(impl); |
393 | |
} |
394 | 0 | return null; |
395 | |
} |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
public Permission getPermissionsByTemplateName(String namespaceCode, String permissionTemplateName) { |
401 | 0 | PermissionBo impls = getPermissionImplsByTemplateName( namespaceCode, permissionTemplateName ); |
402 | 0 | return PermissionBo.to(impls); |
403 | |
} |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
public Permission getPermissionsByName(String namespaceCode, String permissionName) { |
409 | 0 | PermissionBo impls = getPermissionImplsByName( namespaceCode, permissionName ); |
410 | 0 | return PermissionBo.to(impls); |
411 | |
} |
412 | |
|
413 | |
@SuppressWarnings("unchecked") |
414 | |
protected PermissionBo getPermissionImpl(String permissionId) { |
415 | 0 | if ( StringUtils.isBlank( permissionId ) ) { |
416 | 0 | return null; |
417 | |
} |
418 | 0 | String cacheKey = getPermissionImplByIdCacheKey(permissionId); |
419 | 0 | List<PermissionBo> permissions = (List<PermissionBo>) cacheAdministrator.getFromCache(cacheKey); |
420 | 0 | if ( permissions == null ) { |
421 | 0 | HashMap<String,Object> pk = new HashMap<String,Object>( 1 ); |
422 | 0 | pk.put( KimConstants.PrimaryKeyConstants.PERMISSION_ID, permissionId ); |
423 | 0 | permissions = Collections.singletonList( (PermissionBo) businessObjectService.findByPrimaryKey( PermissionBo.class, pk ) ); |
424 | 0 | cacheAdministrator.putInCache(cacheKey, permissions, PERMISSION_IMPL_CACHE_GROUP); |
425 | |
} |
426 | 0 | return permissions.get( 0 ); |
427 | |
} |
428 | |
|
429 | |
protected PermissionBo getPermissionImplsByTemplateName( String namespaceCode, String permissionTemplateName ) { |
430 | 0 | String cacheKey = getPermissionImplByTemplateNameCacheKey(namespaceCode, permissionTemplateName); |
431 | 0 | PermissionBo permissions = (PermissionBo) cacheAdministrator.getFromCache(cacheKey); |
432 | 0 | if ( permissions == null ) { |
433 | 0 | HashMap<String,Object> pk = new HashMap<String,Object>( 3 ); |
434 | 0 | pk.put( "template.namespaceCode", namespaceCode ); |
435 | 0 | pk.put( "template.name", permissionTemplateName ); |
436 | 0 | pk.put( KRADPropertyConstants.ACTIVE, "Y" ); |
437 | 0 | permissions = ((List<PermissionBo>) businessObjectService.findMatching( PermissionBo.class, pk )).get(0); |
438 | 0 | cacheAdministrator.putInCache(cacheKey, permissions, PERMISSION_IMPL_CACHE_GROUP); |
439 | |
} |
440 | 0 | return permissions; |
441 | |
} |
442 | |
|
443 | |
protected PermissionBo getPermissionImplsByName( String namespaceCode, String permissionName ) { |
444 | 0 | String cacheKey = getPermissionImplByNameCacheKey(namespaceCode, permissionName); |
445 | 0 | PermissionBo permissions = (PermissionBo) cacheAdministrator.getFromCache(cacheKey); |
446 | 0 | if ( permissions == null ) { |
447 | 0 | HashMap<String,Object> pk = new HashMap<String,Object>( 3 ); |
448 | 0 | pk.put( KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode ); |
449 | 0 | pk.put( KimConstants.UniqueKeyConstants.PERMISSION_NAME, permissionName ); |
450 | 0 | pk.put( KRADPropertyConstants.ACTIVE, "Y" ); |
451 | 0 | permissions = ((List<PermissionBo>) businessObjectService.findMatching( PermissionBo.class, pk )).get(0); |
452 | 0 | cacheAdministrator.putInCache(cacheKey, permissions, PERMISSION_IMPL_CACHE_GROUP); |
453 | |
} |
454 | 0 | return permissions; |
455 | |
} |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
public PermissionDao getPermissionDao() { |
465 | 0 | return this.permissionDao; |
466 | |
} |
467 | |
|
468 | |
public void setPermissionDao(PermissionDao permissionDao) { |
469 | 0 | this.permissionDao = permissionDao; |
470 | 0 | } |
471 | |
|
472 | |
@SuppressWarnings("unchecked") |
473 | |
public List<Permission> lookupPermissions(Map<String, String> searchCriteria, boolean unbounded ){ |
474 | 0 | Collection baseResults = null; |
475 | 0 | Lookupable permissionLookupable = KNSServiceLocator.getLookupable( |
476 | |
KRADServiceLocatorWeb.getBusinessObjectDictionaryService().getLookupableID(PermissionBo.class)); |
477 | 0 | permissionLookupable.setBusinessObjectClass(PermissionBo.class); |
478 | 0 | if ( unbounded ) { |
479 | 0 | baseResults = permissionLookupable.getSearchResultsUnbounded( searchCriteria ); |
480 | |
} else { |
481 | 0 | baseResults = permissionLookupable.getSearchResults(searchCriteria); |
482 | |
} |
483 | 0 | List<Permission> results = new ArrayList<Permission>( baseResults.size() ); |
484 | 0 | for ( PermissionBo resp : (Collection<PermissionBo>)baseResults ) { |
485 | 0 | results.add( PermissionBo.to(resp) ); |
486 | |
} |
487 | 0 | if ( baseResults instanceof CollectionIncomplete ) { |
488 | 0 | results = new CollectionIncomplete<Permission>( results, ((CollectionIncomplete<Permission>)baseResults).getActualSizeIfTruncated() ); |
489 | |
} |
490 | 0 | return results; |
491 | |
} |
492 | |
|
493 | |
public String getPermissionDetailLabel( String permissionId, String kimTypeId, String attributeName) { |
494 | |
|
495 | 0 | PermissionTypeService typeService = getPermissionTypeService(null, null, null, permissionId); |
496 | 0 | if ( typeService != null ) { |
497 | |
|
498 | 0 | AttributeDefinitionMap attributes = typeService.getAttributeDefinitions( kimTypeId ); |
499 | 0 | String label = null; |
500 | 0 | for ( AttributeDefinition attributeDef : attributes.values() ) { |
501 | 0 | if ( attributeDef.getName().equals(attributeName) ) { |
502 | 0 | label = attributeDef.getLabel(); |
503 | |
} |
504 | |
} |
505 | |
|
506 | 0 | if ( label != null ) { |
507 | 0 | return label; |
508 | |
} else { |
509 | 0 | return "Missing Def: " + attributeName; |
510 | |
} |
511 | |
} else { |
512 | 0 | return "No Label: " + attributeName; |
513 | |
} |
514 | |
} |
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
public Template getPermissionTemplate(String permissionTemplateId) { |
520 | 0 | PermissionTemplateBo impl = businessObjectService.findBySinglePrimaryKey( PermissionTemplateBo.class, permissionTemplateId ); |
521 | 0 | if ( impl != null ) { |
522 | 0 | return PermissionTemplateBo.to(impl); |
523 | |
} |
524 | 0 | return null; |
525 | |
} |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
public Template getPermissionTemplateByName(String namespaceCode, |
533 | |
String permissionTemplateName) { |
534 | 0 | Map<String,String> criteria = new HashMap<String,String>(2); |
535 | 0 | criteria.put( KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode ); |
536 | 0 | criteria.put( KimConstants.UniqueKeyConstants.PERMISSION_TEMPLATE_NAME, permissionTemplateName ); |
537 | 0 | PermissionTemplateBo impl = (PermissionTemplateBo) businessObjectService.findByPrimaryKey( PermissionTemplateBo.class, criteria ); |
538 | 0 | if ( impl != null ) { |
539 | 0 | return PermissionTemplateBo.to(impl); |
540 | |
} |
541 | 0 | return null; |
542 | |
} |
543 | |
|
544 | |
public List<Template> getAllTemplates() { |
545 | 0 | if ( allTemplates == null ) { |
546 | 0 | Map<String,String> criteria = new HashMap<String,String>(1); |
547 | 0 | criteria.put( KRADPropertyConstants.ACTIVE, "Y" ); |
548 | 0 | List<PermissionTemplateBo> impls = (List<PermissionTemplateBo>) businessObjectService.findMatching( PermissionTemplateBo.class, criteria ); |
549 | 0 | List<Template> infos = new ArrayList<Template>( impls.size() ); |
550 | 0 | for ( PermissionTemplateBo impl : impls ) { |
551 | 0 | infos.add( PermissionTemplateBo.to(impl) ); |
552 | |
} |
553 | 0 | Collections.sort(infos, new Comparator<Template>() { |
554 | |
public int compare(Template tmpl1, |
555 | |
Template tmpl2) { |
556 | 0 | int result = 0; |
557 | 0 | result = tmpl1.getNamespaceCode().compareTo(tmpl2.getNamespaceCode()); |
558 | 0 | if ( result != 0 ) { |
559 | 0 | return result; |
560 | |
} |
561 | 0 | result = tmpl1.getName().compareTo(tmpl2.getName()); |
562 | 0 | return result; |
563 | |
} |
564 | |
}); |
565 | 0 | allTemplates = infos; |
566 | |
} |
567 | 0 | return allTemplates; |
568 | |
} |
569 | |
|
570 | |
public List<String> getRoleIdsForPermissionId(String permissionId) { |
571 | 0 | Permission permissionInfo = getPermission(permissionId); |
572 | |
|
573 | 0 | List<Permission> applicablePermissions = new ArrayList<Permission>(); |
574 | 0 | applicablePermissions.add(permissionInfo); |
575 | |
|
576 | 0 | List<String> roleIds = getRolesForPermissionsFromCache(applicablePermissions); |
577 | 0 | if (roleIds == null) { |
578 | 0 | roleIds = permissionDao.getRoleIdsForPermissions(applicablePermissions); |
579 | 0 | addRolesForPermissionsToCache(applicablePermissions, roleIds); |
580 | |
} |
581 | |
|
582 | 0 | return roleIds; |
583 | |
} |
584 | |
|
585 | |
public Permission getPermissionsByNameIncludingInactive(String namespaceCode, String permissionName) { |
586 | 0 | PermissionBo impls = getPermissionImplsByNameIncludingInactive(namespaceCode, permissionName); |
587 | 0 | return PermissionBo.to(impls); |
588 | |
} |
589 | |
|
590 | |
protected PermissionBo getPermissionImplsByNameIncludingInactive(String namespaceCode, String permissionName) { |
591 | 0 | String cacheKey = getPermissionImplByNameCacheKey(namespaceCode, permissionName + "inactive"); |
592 | 0 | PermissionBo permissions = (PermissionBo) cacheAdministrator.getFromCache(cacheKey); |
593 | 0 | if (permissions == null) { |
594 | 0 | HashMap<String, Object> pk = new HashMap<String, Object>(2); |
595 | 0 | pk.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode); |
596 | 0 | pk.put(KimConstants.UniqueKeyConstants.PERMISSION_NAME, permissionName); |
597 | 0 | permissions = ((List<PermissionBo>) businessObjectService.findMatching(PermissionBo.class, pk)).get(0); |
598 | 0 | cacheAdministrator.putInCache(cacheKey, permissions, PERMISSION_IMPL_CACHE_GROUP); |
599 | |
} |
600 | 0 | return permissions; |
601 | |
} |
602 | |
|
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | |
|
608 | |
@Override |
609 | |
public String createPermission(Permission permission) |
610 | |
throws RiceIllegalArgumentException, RiceIllegalStateException { |
611 | |
|
612 | 0 | return null; |
613 | |
} |
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
|
620 | |
@Override |
621 | |
public void updatePermission(Permission permission) |
622 | |
throws RiceIllegalArgumentException, RiceIllegalStateException { |
623 | |
|
624 | |
|
625 | 0 | } |
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
protected void setDataDictionaryService(DataDictionaryService dataDictionaryService) { |
633 | 0 | this.dataDictionaryService = dataDictionaryService; |
634 | 0 | } |
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | |
protected void setKimTypeInfoService(KimTypeInfoService kimTypeInfoService) { |
642 | 0 | this.kimTypeInfoService = kimTypeInfoService; |
643 | 0 | } |
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
protected void setDefaultPermissionTypeService(PermissionTypeService defaultPermissionTypeService) { |
651 | 0 | this.defaultPermissionTypeService = defaultPermissionTypeService; |
652 | 0 | } |
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
protected void setBusinessObjectDictionaryService(BusinessObjectDictionaryService businessObjectDictionaryService) { |
660 | 0 | this.businessObjectDictionaryService = businessObjectDictionaryService; |
661 | 0 | } |
662 | |
|
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
public void setRoleService(RoleService roleService) { |
669 | 0 | this.roleService = roleService; |
670 | 0 | } |
671 | |
|
672 | |
} |