Search in sources :

Example 1 with PermissionException

use of com.cinchapi.concourse.thrift.PermissionException in project concourse by cinchapi.

the class PermissionVerificationAdvice method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    AccessToken token = null;
    String environment = null;
    Object[] args = invocation.getArguments();
    int i = 0;
    while ((token == null || environment == null) && i < args.length) {
        Object arg = args[i];
        if (token == null && arg instanceof AccessToken) {
            token = (AccessToken) arg;
        } else if (token != null && environment == null && arg instanceof String) {
            // This relies on the convention that the environment parameter
            // always comes after the AccessToken parameter
            environment = (String) arg;
        }
        ++i;
    }
    if (token != null && environment != null) {
        ConcourseServer concourse = (ConcourseServer) invocation.getThis();
        Inspector inspector = concourse.inspector();
        if (inspector.tokenUserHasPermission(token, permission, environment)) {
            return invocation.proceed();
        } else {
            throw new PermissionException("Insufficient Permission");
        }
    } else {
        throw new IllegalStateException("Cannot verify permissions without an AccessToken and environment");
    }
}
Also used : PermissionException(com.cinchapi.concourse.thrift.PermissionException) AccessToken(com.cinchapi.concourse.thrift.AccessToken) Inspector(com.cinchapi.concourse.server.Inspector) ConcourseServer(com.cinchapi.concourse.server.ConcourseServer)

Aggregations

ConcourseServer (com.cinchapi.concourse.server.ConcourseServer)1 Inspector (com.cinchapi.concourse.server.Inspector)1 AccessToken (com.cinchapi.concourse.thrift.AccessToken)1 PermissionException (com.cinchapi.concourse.thrift.PermissionException)1