Search in sources :

Example 41 with AccessToken

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

the class UserServiceTest method testRoleOfServiceUserTokenIsAlwaysServiceRole.

@Test
public void testRoleOfServiceUserTokenIsAlwaysServiceRole() {
    AccessToken token = service.tokens.issueServiceToken();
    ByteBuffer username = service.tokens.identify(token);
    Assert.assertEquals(Role.SERVICE, service.getRole(username));
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) ByteBuffer(java.nio.ByteBuffer) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 42 with AccessToken

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

the class ConcourseServerTest method testGetEngineRaceCondition.

@Test
public void testGetEngineRaceCondition() throws TException, InterruptedException {
    // CON-673
    int port = Networking.getOpenPort();
    String env = "test";
    String buffer = TestData.getTemporaryTestDir();
    String db = TestData.getTemporaryTestDir();
    server = ConcourseServer.create(port, buffer, db);
    server.spawn();
    try {
        AccessToken token = server.login(ByteBuffers.fromUtf8String("admin"), ByteBuffers.fromUtf8String("admin"), env);
        for (int i = 0; i < 10000; ++i) {
            server.addKeyValue(TestData.getSimpleString(), TestData.getTObject(), token, null, env);
        }
        server.stop();
        server = ConcourseServer.create(port, buffer, db);
        server.spawn();
        int threads = 20;
        CountDownLatch latch = new CountDownLatch(threads);
        for (int i = 0; i < threads; ++i) {
            Thread t = new Thread(() -> {
                Concourse client = Concourse.at().port(port).environment(env).connect();
                client.exit();
                latch.countDown();
            });
            t.start();
        }
        latch.await();
        Assert.assertEquals(2, server.numEnginesInitialized.get());
    } finally {
        server.stop();
    }
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) Concourse(com.cinchapi.concourse.Concourse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Example 43 with AccessToken

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

the class ConcourseServerTest method testCommandIsIntrospected.

@Test
public void testCommandIsIntrospected() throws TException, InterruptedException {
    server = ConcourseServer.create();
    server.spawn();
    try {
        List<Object> actuals = Lists.newArrayList();
        Thread t = new Thread(() -> {
            try {
                Command.current();
                actuals.add(false);
            } catch (IllegalStateException e) {
                actuals.add(true);
            }
            try {
                AccessToken creds = server.login(ByteBuffer.wrap("admin".getBytes()), ByteBuffer.wrap("admin".getBytes()));
                server.addKeyValue("name", Convert.javaToThrift("jeff"), creds, null, "");
                actuals.add(Command.current().operation());
                server.browseKey("name", creds, null, "");
                actuals.add(Command.current().operation());
            } catch (TException e) {
                e.printStackTrace();
            }
        });
        t.start();
        t.join();
        Assert.assertTrue((boolean) actuals.get(0));
        Assert.assertEquals("add", actuals.get(1));
        Assert.assertEquals("browse", actuals.get(2));
    } finally {
        server.stop();
    }
}
Also used : TException(org.apache.thrift.TException) AccessToken(com.cinchapi.concourse.thrift.AccessToken) Test(org.junit.Test) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest)

Example 44 with AccessToken

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

the class UserServiceTest method testAccessTokenIsNotValidIfAccessIsRevoked.

@Test
public void testAccessTokenIsNotValidIfAccessIsRevoked() {
    ByteBuffer username = getAcceptableUsername();
    ByteBuffer password = getSecurePassword();
    service.create(username, password, Role.ADMIN);
    AccessToken token = service.tokens.issue(username);
    service.delete(username);
    Assert.assertFalse(service.tokens.isValid(token));
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) ByteBuffer(java.nio.ByteBuffer) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Example 45 with AccessToken

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

the class UserServiceTest method testDisablingUserInvalidatesAllAccessTokens.

@Test
public void testDisablingUserInvalidatesAllAccessTokens() {
    ByteBuffer username = getAcceptableUsername();
    ByteBuffer password = getSecurePassword();
    service.create(username, password, Role.ADMIN);
    List<AccessToken> tokens = Lists.newArrayList();
    for (int i = 0; i < TestData.getScaleCount(); i++) {
        tokens.add(service.tokens.issue(username));
    }
    service.disable(username);
    for (AccessToken token : tokens) {
        Assert.assertFalse(service.tokens.isValid(token));
    }
}
Also used : AccessToken(com.cinchapi.concourse.thrift.AccessToken) ByteBuffer(java.nio.ByteBuffer) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

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