Search in sources :

Example 6 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class MemoryTokenRepositoryTest method testSaveToken.

@Test
public void testSaveToken() throws Exception {
    repository.saveToken(token);
    AuthenticationToken result = repository.getToken(tokenId);
    assertThat(result, is(token));
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Test(org.junit.Test)

Example 7 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class MemoryTokenRepositoryTest method testGetTokensWhenNoneExistForOwner.

@Test
public void testGetTokensWhenNoneExistForOwner() throws Exception {
    String ownerId = one(hexadecimalString(10));
    List<AuthenticationToken> result = repository.getTokensBelongingTo(ownerId);
    assertThat(result, notNullValue());
    assertThat(result.isEmpty(), is(true));
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) StringGenerators.hexadecimalString(tech.sirwellington.alchemy.generator.StringGenerators.hexadecimalString) Test(org.junit.Test)

Example 8 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class AuthenticationAssertionsTest method testCompleteToken.

@Test
public void testCompleteToken() {
    AlchemyAssertion<AuthenticationToken> instance = AuthenticationAssertions.completeToken();
    assertThat(instance, notNullValue());
    instance.check(token);
    AuthenticationToken tokenWithoutTokenId = new AuthenticationToken(token);
    tokenWithoutTokenId.unsetTokenId();
    assertThrows(() -> instance.check(tokenWithoutTokenId)).isInstanceOf(FailedAssertionException.class);
    AuthenticationToken tokenWithoutOwnerId = new AuthenticationToken(token);
    tokenWithoutOwnerId.unsetOwnerId();
    assertThrows(() -> instance.check(tokenWithoutOwnerId)).isInstanceOf(FailedAssertionException.class);
    AuthenticationToken tokenWithoutTokenType = new AuthenticationToken(token);
    tokenWithoutTokenType.unsetTokenType();
    assertThrows(() -> instance.check(tokenWithoutTokenType)).isInstanceOf(FailedAssertionException.class);
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Test(org.junit.Test)

Example 9 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class CassandraTokenRepository method getTokensBelongingTo.

@Override
public List<AuthenticationToken> getTokensBelongingTo(String ownerId) throws TException {
    checkThat(ownerId).throwing(InvalidArgumentException.class).usingMessage("ownerId missing").is(nonEmptyString()).usingMessage("ownerId must be a UUID type").is(validUUID());
    Statement query = createQueryToGetTokensOwnedBy(ownerId);
    ResultSet results = tryToGetResultSetFrom(query);
    List<AuthenticationToken> tokens = Lists.create();
    for (Row row : results) {
        AuthenticationToken token = tryToConvertRowToToken(row);
        tokens.add(token);
    }
    LOG.debug("Found {} tokens owned by {}", tokens.size(), ownerId);
    return tokens;
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 10 with AuthenticationToken

use of tech.aroma.thrift.authentication.AuthenticationToken in project aroma-data-operations by RedRoma.

the class CassandraTokenRepository method getToken.

@Override
public AuthenticationToken getToken(String tokenId) throws TException, InvalidTokenException {
    checkTokenId(tokenId);
    Statement query = createQueryToGetToken(tokenId);
    Row row = tryToGetOneRowFrom(query);
    AuthenticationToken token = tryToConvertRowToToken(row);
    return token;
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) Row(com.datastax.driver.core.Row)

Aggregations

AuthenticationToken (tech.aroma.thrift.authentication.AuthenticationToken)22 Test (org.junit.Test)14 BatchStatement (com.datastax.driver.core.BatchStatement)4 Row (com.datastax.driver.core.Row)4 Statement (com.datastax.driver.core.Statement)4 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)3 InvalidTokenException (tech.aroma.thrift.exceptions.InvalidTokenException)3 ResultSet (com.datastax.driver.core.ResultSet)2 TException (org.apache.thrift.TException)2 OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 StringAssertions.nonEmptyString (tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString)2 StringGenerators.hexadecimalString (tech.sirwellington.alchemy.generator.StringGenerators.hexadecimalString)2 Cluster (com.datastax.driver.core.Cluster)1 Session (com.datastax.driver.core.Session)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1