Search in sources :

Example 1 with DefaultResourceChecker

use of com.sequenceiq.authorization.service.defaults.DefaultResourceChecker in project cloudbreak by hortonworks.

the class CommonPermissionCheckingUtils method getPermissionsForUserOnResources.

public Map<String, Boolean> getPermissionsForUserOnResources(AuthorizationResourceAction action, String userCrn, List<String> resourceCrns) {
    DefaultResourceChecker defaultResourceChecker = defaultResourceCheckerMap.get(umsRightProvider.getResourceType(action));
    if (defaultResourceChecker == null) {
        return umsResourceAuthorizationService.getRightOfUserOnResources(userCrn, action, resourceCrns);
    } else {
        CrnsByCategory crnsByCategory = defaultResourceChecker.getDefaultResourceCrns(resourceCrns);
        Map<String, Boolean> result = new HashMap<>();
        if (!crnsByCategory.getDefaultResourceCrns().isEmpty()) {
            result.putAll(crnsByCategory.getDefaultResourceCrns().stream().collect(toMap(Function.identity(), s -> defaultResourceChecker.isAllowedAction(action))));
        }
        if (!crnsByCategory.getNotDefaultResourceCrns().isEmpty()) {
            result.putAll(umsResourceAuthorizationService.getRightOfUserOnResources(userCrn, action, crnsByCategory.getNotDefaultResourceCrns()));
        }
        return result;
    }
}
Also used : CrnsByCategory(com.sequenceiq.authorization.service.defaults.CrnsByCategory) HashMap(java.util.HashMap) DefaultResourceChecker(com.sequenceiq.authorization.service.defaults.DefaultResourceChecker)

Example 2 with DefaultResourceChecker

use of com.sequenceiq.authorization.service.defaults.DefaultResourceChecker in project cloudbreak by hortonworks.

the class DefaultResourceAuthorizationProvider method authorizeDefaultOrElseCompute.

public Optional<AuthorizationRule> authorizeDefaultOrElseCompute(String resourceCrn, AuthorizationResourceAction action, Supplier<Optional<AuthorizationRule>> supplier) {
    AuthorizationResourceType authorizationResourceType = action.getAuthorizationResourceType();
    DefaultResourceChecker defaultResourceChecker = null;
    if (authorizationResourceType != null) {
        defaultResourceChecker = defaultResourceCheckerMap.get(authorizationResourceType);
    }
    if (defaultResourceChecker != null && defaultResourceChecker.isDefault(resourceCrn)) {
        commonPermissionCheckingUtils.throwAccessDeniedIfActionNotAllowed(action, List.of(resourceCrn), defaultResourceChecker);
        return Optional.empty();
    } else {
        return supplier.get();
    }
}
Also used : AuthorizationResourceType(com.sequenceiq.authorization.resource.AuthorizationResourceType) DefaultResourceChecker(com.sequenceiq.authorization.service.defaults.DefaultResourceChecker)

Aggregations

DefaultResourceChecker (com.sequenceiq.authorization.service.defaults.DefaultResourceChecker)2 AuthorizationResourceType (com.sequenceiq.authorization.resource.AuthorizationResourceType)1 CrnsByCategory (com.sequenceiq.authorization.service.defaults.CrnsByCategory)1 HashMap (java.util.HashMap)1