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;
}
}
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();
}
}
Aggregations