use of com.sequenceiq.authorization.resource.AuthorizationResourceType in project cloudbreak by hortonworks.
the class EnforcePropertyProviderTestUtil method validationAnnotationByProvider.
private static <T extends ResourcePropertyProvider> Optional<Class<? extends ResourcePropertyProvider>> validationAnnotationByProvider(Class<T> propertyProviderClass, Set<Predicate<Annotation>> validationPredicates, Annotation annotation) {
AuthorizationResourceAction action = getAction(annotation);
AuthorizationResourceType authorizationResourceType = action.getAuthorizationResourceType();
if (validationPredicates.stream().allMatch(predicate -> predicate.test(annotation))) {
return PROVIDER_SUBTYPES_MAP.get(propertyProviderClass).stream().filter(type -> {
ResourcePropertyProvider resourcePropertyProvider = (T) EnforceAuthorizationTestUtil.getSampleObjectFactory().manufacturePojo(type);
return authorizationResourceType.equals(resourcePropertyProvider.getSupportedAuthorizationResourceType());
}).findFirst();
}
return Optional.of(propertyProviderClass);
}
use of com.sequenceiq.authorization.resource.AuthorizationResourceType in project cloudbreak by hortonworks.
the class EnforcePropertyProviderTestUtil method addErrorIfNeeded.
private static void addErrorIfNeeded(Method method, List<String> errors, Class<? extends ResourcePropertyProvider> providerClass, Annotation annotation, Optional<Class<? extends ResourcePropertyProvider>> providerClassPresent) {
if (providerClassPresent.isEmpty()) {
AuthorizationResourceAction action = getAction(annotation);
AuthorizationResourceType authorizationResourceType = action.getAuthorizationResourceType();
errors.add(String.format("Provider with interface %s implemented is needed to authorize using action %s and resource type %s (method: %s)", providerClass.getSimpleName(), action, authorizationResourceType, method.getDeclaringClass().getSimpleName() + "#" + method.getName()));
}
}
use of com.sequenceiq.authorization.resource.AuthorizationResourceType in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method supportedAuthorizationResourceTypeShouldBeImageCatalog.
@Test
public void supportedAuthorizationResourceTypeShouldBeImageCatalog() {
AuthorizationResourceType actual = victim.getSupportedAuthorizationResourceType();
assertEquals(AuthorizationResourceType.IMAGE_CATALOG, actual);
}
use of com.sequenceiq.authorization.resource.AuthorizationResourceType 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