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 com.google.common.collect.MapMaker; |
19 | |
import org.kuali.rice.core.api.criteria.CriteriaLookupService; |
20 | |
import org.kuali.rice.kim.api.permission.Permission; |
21 | |
import org.kuali.rice.kim.api.permission.PermissionTypeService; |
22 | |
import org.kuali.rice.kim.impl.role.RoleMemberAttributeDataBo; |
23 | |
import org.kuali.rice.kim.util.KimConstants; |
24 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
25 | |
import org.kuali.rice.krad.service.SequenceAccessorService; |
26 | |
import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator; |
27 | |
|
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
import java.util.concurrent.ConcurrentMap; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class PermissionServiceBase { |
39 | |
protected static final String PERMISSION_IMPL_CACHE_PREFIX = "PermissionImpl-Template-"; |
40 | |
protected static final String PERMISSION_IMPL_NAME_CACHE_PREFIX = "PermissionImpl-Name-"; |
41 | |
protected static final String PERMISSION_IMPL_ID_CACHE_PREFIX = "PermissionImpl-Id-"; |
42 | |
protected static final String PERMISSION_IMPL_CACHE_GROUP = "PermissionImpl"; |
43 | |
|
44 | |
protected static final String DEFAULT_PERMISSION_TYPE_SERVICE = "defaultPermissionTypeService"; |
45 | |
|
46 | |
protected BusinessObjectService businessObjectService; |
47 | |
protected CriteriaLookupService criteriaLookupService; |
48 | |
protected SequenceAccessorService sequenceAccessorService; |
49 | |
protected RiceCacheAdministrator cacheAdministrator; |
50 | |
|
51 | 0 | private ConcurrentMap<List<Permission>,List<String>> permissionToRoleCache = new MapMaker().softValues().makeMap(); |
52 | |
|
53 | |
|
54 | 0 | private ConcurrentMap<String,PermissionTypeService> permissionTypeServiceByNameCache = new MapMaker().makeMap(); |
55 | |
|
56 | |
|
57 | |
private static final long CACHE_MAX_AGE_SECONDS = 60L; |
58 | |
|
59 | |
public void flushPermissionImplCache() { |
60 | 0 | cacheAdministrator.flushGroup(PERMISSION_IMPL_CACHE_GROUP); |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
protected Map<String, PermissionTypeService> getPermissionTypeServiceByNameCache() { |
67 | 0 | return this.permissionTypeServiceByNameCache; |
68 | |
} |
69 | |
|
70 | |
protected void addRolesForPermissionsToCache( List<Permission> applicablePermissions, List<String> roleIds ) { |
71 | 0 | permissionToRoleCache.put( applicablePermissions, roleIds ); |
72 | 0 | } |
73 | |
|
74 | |
protected List<String> getRolesForPermissionsFromCache( List<Permission> applicablePermissions ) { |
75 | 0 | return permissionToRoleCache.get( applicablePermissions ); |
76 | |
} |
77 | |
|
78 | |
protected String getPermissionImplByTemplateNameCacheKey( String namespaceCode, String permissionTemplateName ) { |
79 | 0 | return PERMISSION_IMPL_CACHE_PREFIX + namespaceCode + "-" + permissionTemplateName; |
80 | |
} |
81 | |
protected String getPermissionImplByNameCacheKey( String namespaceCode, String permissionName ) { |
82 | 0 | return PERMISSION_IMPL_NAME_CACHE_PREFIX + namespaceCode + "-" + permissionName; |
83 | |
} |
84 | |
protected String getPermissionImplByIdCacheKey( String permissionId ) { |
85 | 0 | return PERMISSION_IMPL_ID_CACHE_PREFIX + permissionId; |
86 | |
} |
87 | |
|
88 | |
protected String getNewAttributeDataId(){ |
89 | 0 | Long nextSeq = sequenceAccessorService.getNextAvailableSequenceNumber( |
90 | |
KimConstants.SequenceNames.KRIM_ATTR_DATA_ID_S, |
91 | |
RoleMemberAttributeDataBo.class ); |
92 | 0 | return nextSeq.toString(); |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void setSequenceAccessorService(final SequenceAccessorService sequenceAccessorService) { |
101 | 0 | this.sequenceAccessorService = sequenceAccessorService; |
102 | 0 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public void setBusinessObjectService(final BusinessObjectService businessObjectService) { |
110 | 0 | this.businessObjectService = businessObjectService; |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
public void setCriteriaLookupService(final CriteriaLookupService criteriaLookupService) { |
119 | 0 | this.criteriaLookupService = criteriaLookupService; |
120 | 0 | } |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
protected void setCacheAdministrator(RiceCacheAdministrator cacheAdministrator) { |
129 | 0 | this.cacheAdministrator = cacheAdministrator; |
130 | 0 | } |
131 | |
} |