1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import com.google.common.collect.MapMaker; |
19 | |
import org.kuali.rice.kim.impl.permission.PermissionBo; |
20 | |
import org.kuali.rice.kim.impl.role.RoleMemberAttributeDataBo; |
21 | |
import org.kuali.rice.kim.service.support.KimPermissionTypeService; |
22 | |
import org.kuali.rice.kim.util.KimConstants; |
23 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
24 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
25 | |
import org.kuali.rice.krad.service.SequenceAccessorService; |
26 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
27 | |
import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator; |
28 | |
|
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
import java.util.concurrent.ConcurrentMap; |
32 | |
import java.util.concurrent.TimeUnit; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class PermissionServiceBase { |
41 | |
protected static final String PERMISSION_IMPL_CACHE_PREFIX = "PermissionImpl-Template-"; |
42 | |
protected static final String PERMISSION_IMPL_NAME_CACHE_PREFIX = "PermissionImpl-Name-"; |
43 | |
protected static final String PERMISSION_IMPL_ID_CACHE_PREFIX = "PermissionImpl-Id-"; |
44 | |
protected static final String PERMISSION_IMPL_CACHE_GROUP = "PermissionImpl"; |
45 | |
|
46 | |
protected static final String DEFAULT_PERMISSION_TYPE_SERVICE = "defaultPermissionTypeService"; |
47 | |
|
48 | |
private BusinessObjectService businessObjectService; |
49 | |
private SequenceAccessorService sequenceAccessorService; |
50 | |
private RiceCacheAdministrator cacheAdministrator; |
51 | |
|
52 | 0 | private ConcurrentMap<List<PermissionBo>, List<String>> permissionToRoleCache = new MapMaker().expireAfterAccess(CACHE_MAX_AGE_SECONDS, TimeUnit.SECONDS).softValues().makeMap(); |
53 | |
|
54 | |
|
55 | 0 | private ConcurrentMap<String,KimPermissionTypeService> permissionTypeServiceByNameCache = new MapMaker().makeMap(); |
56 | |
|
57 | |
|
58 | |
private static final long CACHE_MAX_AGE_SECONDS = 60L; |
59 | |
|
60 | |
protected BusinessObjectService getBusinessObjectService() { |
61 | 0 | if ( businessObjectService == null ) { |
62 | 0 | businessObjectService = KRADServiceLocator.getBusinessObjectService(); |
63 | |
} |
64 | 0 | return businessObjectService; |
65 | |
} |
66 | |
|
67 | |
public void flushPermissionImplCache() { |
68 | 0 | getCacheAdministrator().flushGroup(PERMISSION_IMPL_CACHE_GROUP); |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
protected Map<String, KimPermissionTypeService> getPermissionTypeServiceByNameCache() { |
75 | 0 | return this.permissionTypeServiceByNameCache; |
76 | |
} |
77 | |
|
78 | |
protected void addRolesForPermissionsToCache( List<PermissionBo> key, List<String> roleIds ) { |
79 | 0 | permissionToRoleCache.put(key, roleIds); |
80 | 0 | } |
81 | |
|
82 | |
protected List<String> getRolesForPermissionsFromCache( List<PermissionBo> key ) { |
83 | 0 | return permissionToRoleCache.get( key ); |
84 | |
} |
85 | |
|
86 | |
protected String getPermissionImplByTemplateNameCacheKey( String namespaceCode, String permissionTemplateName ) { |
87 | 0 | return PERMISSION_IMPL_CACHE_PREFIX + namespaceCode + "-" + permissionTemplateName; |
88 | |
} |
89 | |
protected String getPermissionImplByNameCacheKey( String namespaceCode, String permissionName ) { |
90 | 0 | return PERMISSION_IMPL_NAME_CACHE_PREFIX + namespaceCode + "-" + permissionName; |
91 | |
} |
92 | |
protected String getPermissionImplByIdCacheKey( String permissionId ) { |
93 | 0 | return PERMISSION_IMPL_ID_CACHE_PREFIX + permissionId; |
94 | |
} |
95 | |
|
96 | |
protected String getNewAttributeDataId(){ |
97 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
98 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
99 | |
KimConstants.SequenceNames.KRIM_ATTR_DATA_ID_S, |
100 | |
RoleMemberAttributeDataBo.class ); |
101 | 0 | return nextSeq.toString(); |
102 | |
} |
103 | |
|
104 | |
protected SequenceAccessorService getSequenceAccessorService() { |
105 | 0 | if ( sequenceAccessorService == null ) { |
106 | 0 | sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService(); |
107 | |
} |
108 | 0 | return sequenceAccessorService; |
109 | |
} |
110 | |
|
111 | |
protected RiceCacheAdministrator getCacheAdministrator() { |
112 | 0 | if ( cacheAdministrator == null ) { |
113 | 0 | cacheAdministrator = KsbApiServiceLocator.getCacheAdministrator(); |
114 | |
} |
115 | 0 | return cacheAdministrator; |
116 | |
} |
117 | |
} |