use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class BackgroundThreadTest method testBackgroundExecutorHasCorrectInformation.
@Test
public void testBackgroundExecutorHasCorrectInformation() throws InterruptedException {
InterProcessCommunication outgoing = new MessageQueue();
ConcurrentMap<AccessToken, RemoteMethodResponse> responses = Maps.newConcurrentMap();
BackgroundExecutor executor = PluginExecutors.newCachedBackgroundExecutor(outgoing, responses);
CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean passed = new AtomicBoolean(true);
executor.execute(Random.getSimpleString(), () -> {
InterProcessCommunication myOutgoing = ((BackgroundThread) Thread.currentThread()).outgoing();
ConcurrentMap<AccessToken, RemoteMethodResponse> myResponses = ((BackgroundThread) Thread.currentThread()).responses();
try {
Assert.assertSame(outgoing, myOutgoing);
Assert.assertSame(responses, myResponses);
} catch (AssertionError e) {
passed.set(false);
e.printStackTrace();
}
latch.countDown();
});
latch.await();
Assert.assertTrue(passed.get());
}
use of com.cinchapi.concourse.thrift.AccessToken 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.thrift.AccessToken in project concourse by cinchapi.
the class HttpRequests method decodeAuthToken.
/**
* Decode an auth token.
*
* @param token
* @param request
* @return an array with three elements: the first contains the actual
* {@link AccessToken} and the second contains the environment that
* the token was encoded with and the third contains the fingerprint
* @throws GeneralSecurityException
*/
public static HttpAuthToken decodeAuthToken(String token) throws GeneralSecurityException {
ByteBuffer cryptPack = ByteBuffer.wrap(BaseEncoding.base64Url().decode(token));
String pack = ByteBuffers.getUtf8String(ClientSecurity.decrypt(cryptPack));
String[] toks = pack.split("\\|");
return new HttpAuthToken(new AccessToken(ByteBuffer.wrap(BaseEncoding.base32Hex().decode(toks[0]))), toks[1], toks[2]);
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class AuthenticationTest method testCannotInvokeMethodWithInvalidAccessToken.
@Test
public void testCannotInvokeMethodWithInvalidAccessToken() {
AccessToken token = new AccessToken(ByteBuffers.fromUtf8String(ByteBuffers.encodeAsHexString(ByteBuffers.fromUtf8String("fake"))));
Reflection.set("creds", token, client);
// must
Reflection.set("password", ByteBuffers.fromUtf8String(""), client);
// work
try {
client.getServerEnvironment();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(true);
}
}
use of com.cinchapi.concourse.thrift.AccessToken in project concourse by cinchapi.
the class ConcourseIntegrationTest method setUserPassword.
/**
* Set the {@code password} associated with the {@code username}.
*
* @param username
* @param password
*/
protected final void setUserPassword(String username, String password) {
try {
AccessToken token = server.login(ByteBuffers.fromUtf8String("admin"), ByteBuffers.fromUtf8String("admin"));
server.setUserPassword(ByteBuffers.fromUtf8String(username), ByteBuffers.fromUtf8String(password), token);
} catch (TException e) {
throw CheckedExceptions.wrapAsRuntimeException(e);
}
}
Aggregations