Search in sources :

Example 1 with PermissionTypeService

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;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PermissionTypeService(org.kuali.kfs.kim.framework.permission.PermissionTypeService) RolePermission(org.kuali.kfs.kim.impl.role.RolePermission) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Cache(org.springframework.cache.Cache)

Example 2 with PermissionTypeService

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);
    }
}
Also used : KimType(org.kuali.kfs.kim.impl.type.KimType) PermissionTypeService(org.kuali.kfs.kim.framework.permission.PermissionTypeService)

Aggregations

PermissionTypeService (org.kuali.kfs.kim.framework.permission.PermissionTypeService)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 RolePermission (org.kuali.kfs.kim.impl.role.RolePermission)1 KimType (org.kuali.kfs.kim.impl.type.KimType)1 Cache (org.springframework.cache.Cache)1