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