use of org.kuali.kfs.kim.framework.permission.PermissionTypeService in project cu-kfs by CU-CommunityApps.
the class PermissionServiceImpl method getMatchingPermissions.
/**
* Compare each of the passed in permissions with the given permissionDetails. Those that match are added to the
* result list.
*/
protected List<Permission> getMatchingPermissions(List<Permission> permissions, Map<String, String> permissionDetails) {
List<String> permissionIds = new ArrayList<>(permissions.size());
for (Permission permission : permissions) {
permissionIds.add(permission.getId());
}
String cacheKey = "{getMatchingPermissions}permissionIds=" + CacheKeyUtils.key(permissionIds) + "|" + "permissionDetails=" + CacheKeyUtils.mapKey(permissionDetails);
Cache.ValueWrapper cachedValue = cacheManager.getCache(Permission.CACHE_NAME).get(cacheKey);
if (cachedValue != null && cachedValue.get() instanceof List) {
return (List<Permission>) cachedValue.get();
}
List<Permission> applicablePermissions = new ArrayList<>();
if (permissionDetails == null || permissionDetails.isEmpty()) {
// if no details passed, assume that all match
applicablePermissions.addAll(permissions);
} else {
// otherwise, attempt to match the permission details
// build a map of the template IDs to the type services
Map<String, PermissionTypeService> permissionTypeServices = getPermissionTypeServicesByTemplateId(permissions);
// build a map of permissions by template ID
Map<String, List<Permission>> permissionMap = groupPermissionsByTemplate(permissions);
// service at once
for (Map.Entry<String, List<Permission>> entry : permissionMap.entrySet()) {
PermissionTypeService permissionTypeService = permissionTypeServices.get(entry.getKey());
List<Permission> permissionList = entry.getValue();
applicablePermissions.addAll(permissionTypeService.getMatchingPermissions(permissionDetails, permissionList));
}
}
applicablePermissions = Collections.unmodifiableList(applicablePermissions);
cacheManager.getCache(Permission.CACHE_NAME).put(cacheKey, applicablePermissions);
return applicablePermissions;
}
use of org.kuali.kfs.kim.framework.permission.PermissionTypeService in project cu-kfs by CU-CommunityApps.
the class PermissionServiceImpl method getPermissionTypeService.
protected PermissionTypeService getPermissionTypeService(PermissionTemplate permissionTemplate) {
if (permissionTemplate == null) {
throw new IllegalArgumentException("permissionTemplate may not be null");
}
KimType kimType = kimTypeInfoService.getKimType(permissionTemplate.getKimTypeId());
String serviceName = kimType.getServiceName();
// if no service specified, return a default implementation
if (StringUtils.isBlank(serviceName)) {
return defaultPermissionTypeService;
}
try {
PermissionTypeService service = SpringContext.getBean(PermissionTypeService.class, serviceName);
// if we have a service name, it must exist
if (service == null) {
throw new RuntimeException("null returned for permission type service for service name: " + serviceName);
}
return service;
} catch (Exception ex) {
// sometimes service locators throw exceptions rather than returning null, handle that
throw new RuntimeException("Error retrieving service: " + serviceName + " from the SpringContext.", ex);
}
}
Aggregations