use of com.sequenceiq.authorization.resource.AuthorizationVariableType in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactory method calcAuthorization.
private Optional<AuthorizationRule> calcAuthorization(Object resourceObject, CheckPermissionByRequestProperty methodAnnotation, String userCrn) {
boolean skipOnNull = methodAnnotation.skipOnNull();
try {
Object fieldObject = PropertyUtils.getProperty(resourceObject, methodAnnotation.path());
AuthorizationVariableType authorizationVariableType = methodAnnotation.type();
AuthorizationResourceAction action = methodAnnotation.action();
if (fieldObject != null) {
return calcAuthorizationFromObject(action, authorizationVariableType, fieldObject, userCrn);
} else if (!methodAnnotation.skipOnNull()) {
throw new BadRequestException(String.format("Property [%s] of the request object must not be null.", methodAnnotation.path()));
}
} catch (NestedNullException nne) {
if (!skipOnNull) {
throw new BadRequestException(String.format("Property [%s] of the request object must not be null.", methodAnnotation.path()));
}
} catch (NotFoundException nfe) {
LOGGER.warn("Resource not found during permission check of resource object, this should be handled by microservice.");
} catch (Error | RuntimeException unchecked) {
LOGGER.error("Error happened during authorization of the request object: ", unchecked);
throw unchecked;
} catch (Throwable t) {
LOGGER.error("Error happened during authorization of the request object: ", t);
throw new AccessDeniedException("Error happened during authorization of the request object, thus access is denied!", t);
}
return Optional.empty();
}
Aggregations