Search in sources :

Example 31 with AccessToken

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageQueue(com.cinchapi.concourse.server.plugin.io.MessageQueue) AccessToken(com.cinchapi.concourse.thrift.AccessToken) InterProcessCommunication(com.cinchapi.concourse.server.plugin.io.InterProcessCommunication) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with AccessToken

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");
    }
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) Inspector(com.cinchapi.concourse.server.Inspector) ConcourseServer(com.cinchapi.concourse.server.ConcourseServer)

Example 33 with AccessToken

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]);
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) ByteBuffer(java.nio.ByteBuffer)

Example 34 with AccessToken

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);
    }
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 35 with AccessToken

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);
    }
}
Also used : TException(org.apache.thrift.TException) AccessToken(com.cinchapi.concourse.thrift.AccessToken)

Aggregations

AccessToken (com.cinchapi.concourse.thrift.AccessToken)96 ByteBuffer (java.nio.ByteBuffer)72 TransactionToken (com.cinchapi.concourse.thrift.TransactionToken)60 TException (org.apache.thrift.TException)60 AtomicReference (java.util.concurrent.atomic.AtomicReference)56 AnyStrings (com.cinchapi.common.base.AnyStrings)55 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)55 Reflection (com.cinchapi.common.reflect.Reflection)55 Permission (com.cinchapi.concourse.security.Permission)55 Role (com.cinchapi.concourse.security.Role)55 Internal (com.cinchapi.concourse.server.aop.Internal)55 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)55 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)55 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)55 FileSystem (com.cinchapi.concourse.server.io.FileSystem)55 ConcourseManagementService (com.cinchapi.concourse.server.management.ConcourseManagementService)55 PluginManager (com.cinchapi.concourse.server.plugin.PluginManager)55 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)28 NaturalLanguage (com.cinchapi.ccl.util.NaturalLanguage)28 Array (com.cinchapi.common.base.Array)28