use of com.cinchapi.concourse.server.Inspector in project concourse by cinchapi.
the class AdminRoleVerificiationAdvice method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
AccessToken token = null;
for (Object arg : invocation.getArguments()) {
if (arg instanceof AccessToken) {
token = (AccessToken) arg;
break;
} else {
continue;
}
}
if (token != null) {
ConcourseServer concourse = (ConcourseServer) invocation.getThis();
Inspector inspector = concourse.inspector();
if (inspector.getTokenUserRole(token) == Role.ADMIN) {
return invocation.proceed();
} else {
throw new SecurityException("Unauthorized");
}
} else {
throw new SecurityException("No token was provided to a method that requires a user with the ADMIN role");
}
}
use of com.cinchapi.concourse.server.Inspector 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