Search in sources :

Example 1 with DefaultPermission

use of org.craftercms.commons.security.permissions.DefaultPermission in project studio by craftercms.

the class CompositePermissionResolverImpl method getPermission.

@Override
public Permission getPermission(String username, Map<String, Object> resourceIds) throws PermissionException {
    String siteName = "";
    List<String> paths = new ArrayList<String>();
    if (MapUtils.isNotEmpty(resourceIds)) {
        if (resourceIds.containsKey(SITE_ID_RESOURCE_ID)) {
            siteName = (String) resourceIds.get(SITE_ID_RESOURCE_ID);
            if (StringUtils.equals(siteName, studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE))) {
                siteName = StringUtils.EMPTY;
            }
        }
        if (resourceIds.containsKey(PATH_RESOURCE_ID)) {
            paths.add((String) resourceIds.get(PATH_RESOURCE_ID));
        }
        if (resourceIds.containsKey(PATH_LIST_RESOURCE_ID)) {
            paths = (List<String>) resourceIds.get(PATH_LIST_RESOURCE_ID);
        }
    }
    if (CollectionUtils.isEmpty(paths)) {
        paths.add("/");
    }
    String finalSiteName = siteName;
    CompositePermission permission = paths.stream().map(x -> {
        DefaultPermission dp = new DefaultPermission();
        Set<String> allowedActions = securityService.getUserPermissions(finalSiteName, x, username, null);
        dp.setAllowedActions(allowedActions);
        return dp;
    }).collect(CompositePermission::new, CompositePermission::addPermission, CompositePermission::addPermission);
    return permission;
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Set(java.util.Set) CONFIGURATION_GLOBAL_SYSTEM_SITE(org.craftercms.studio.api.v2.utils.StudioConfiguration.CONFIGURATION_GLOBAL_SYSTEM_SITE) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) PermissionException(org.craftercms.commons.security.exception.PermissionException) List(java.util.List) StudioConfiguration(org.craftercms.studio.api.v2.utils.StudioConfiguration) SecurityService(org.craftercms.studio.api.v1.service.security.SecurityService) Map(java.util.Map) DefaultPermission(org.craftercms.commons.security.permissions.DefaultPermission) Required(org.springframework.beans.factory.annotation.Required) Permission(org.craftercms.commons.security.permissions.Permission) PermissionResolver(org.craftercms.commons.security.permissions.PermissionResolver) Collections(java.util.Collections) Set(java.util.Set) ArrayList(java.util.ArrayList) DefaultPermission(org.craftercms.commons.security.permissions.DefaultPermission)

Example 2 with DefaultPermission

use of org.craftercms.commons.security.permissions.DefaultPermission in project studio by craftercms.

the class PermissionResolverImpl method getPermission.

@Override
public Permission getPermission(String username, Map<String, Object> resourceIds) throws PermissionException {
    String siteName = "";
    String path = "/";
    if (MapUtils.isNotEmpty(resourceIds)) {
        if (resourceIds.containsKey(SITE_ID_RESOURCE_ID)) {
            siteName = (String) resourceIds.get(SITE_ID_RESOURCE_ID);
            if (StringUtils.equals(siteName, studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE))) {
                siteName = StringUtils.EMPTY;
            }
        }
        if (resourceIds.containsKey(PATH_RESOURCE_ID)) {
            path = (String) resourceIds.get(PATH_RESOURCE_ID);
        }
    }
    Set<String> allowedActions = securityService.getUserPermissions(siteName, path, username, null);
    DefaultPermission permission = new DefaultPermission();
    permission.setAllowedActions(allowedActions);
    return permission;
}
Also used : DefaultPermission(org.craftercms.commons.security.permissions.DefaultPermission)

Aggregations

DefaultPermission (org.craftercms.commons.security.permissions.DefaultPermission)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 MapUtils (org.apache.commons.collections4.MapUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 PermissionException (org.craftercms.commons.security.exception.PermissionException)1 Permission (org.craftercms.commons.security.permissions.Permission)1 PermissionResolver (org.craftercms.commons.security.permissions.PermissionResolver)1 SecurityService (org.craftercms.studio.api.v1.service.security.SecurityService)1 StudioConfiguration (org.craftercms.studio.api.v2.utils.StudioConfiguration)1 CONFIGURATION_GLOBAL_SYSTEM_SITE (org.craftercms.studio.api.v2.utils.StudioConfiguration.CONFIGURATION_GLOBAL_SYSTEM_SITE)1 Required (org.springframework.beans.factory.annotation.Required)1