Search in sources :

Example 1 with AuthorizationVariableType

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();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) NestedNullException(org.apache.commons.beanutils.NestedNullException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) RequestObject(com.sequenceiq.authorization.annotation.RequestObject) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) AuthorizationVariableType(com.sequenceiq.authorization.resource.AuthorizationVariableType)

Aggregations

RequestObject (com.sequenceiq.authorization.annotation.RequestObject)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)1 AuthorizationVariableType (com.sequenceiq.authorization.resource.AuthorizationVariableType)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 NestedNullException (org.apache.commons.beanutils.NestedNullException)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1