Search in sources :

Example 11 with AuthenticationToken

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

the class CassandraTokenRepository method tryToConvertRowToToken.

private AuthenticationToken tryToConvertRowToToken(Row row) throws OperationFailedException, InvalidTokenException {
    AuthenticationToken token;
    try {
        token = tokenMapper.apply(row);
    } catch (Exception ex) {
        LOG.error("Could not map Row {} to Token", row, ex);
        throw new OperationFailedException("Failed to query for Token: " + ex.getMessage());
    }
    checkThat(token).throwing(InvalidTokenException.class).is(completeToken());
    return token;
}
Also used : InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 12 with AuthenticationToken

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

the class TokenRepository method doesTokenBelongTo.

default boolean doesTokenBelongTo(@NonEmpty String tokenId, @NonEmpty String ownerId) throws InvalidTokenException, TException {
    checkThat(tokenId, ownerId).throwing(InvalidArgumentException.class).usingMessage("tokenId and ownerId are required").are(nonEmptyString());
    AuthenticationToken token = this.getToken(tokenId);
    checkThat(token).throwing(InvalidTokenException.class).is(tokenContainingOwnerId());
    return Objects.equals(ownerId, token.ownerId);
}
Also used : InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken)

Example 13 with AuthenticationToken

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

the class MappersTest method testAuthenticationTokenMapper.

@Test
public void testAuthenticationTokenMapper() throws Exception {
    Function<Row, AuthenticationToken> mapper = Mappers.tokenMapper();
    assertThat(mapper, notNullValue());
    token.unsetOrganizationName();
    Row tokenRow = rowFor(token);
    AuthenticationToken result = mapper.apply(tokenRow);
    assertThat(result, is(token));
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 14 with AuthenticationToken

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

the class CassandraTokenRepository method createStatementToDeleteToken.

private Statement createStatementToDeleteToken(String tokenId) throws TException {
    UUID tokenUuid = UUID.fromString(tokenId);
    // Need to get Token first
    AuthenticationToken token = this.getToken(tokenId);
    UUID ownerUuid = UUID.fromString(token.ownerId);
    BatchStatement batch = new BatchStatement();
    Statement deleteFromMainTable = QueryBuilder.delete().all().from(Tokens.TABLE_NAME).where(eq(TOKEN_ID, tokenUuid));
    batch.add(deleteFromMainTable);
    Statement deleteFromOwnersTable = QueryBuilder.delete().all().from(Tokens.TABLE_NAME_BY_OWNER).where(eq(OWNER_ID, ownerUuid));
    batch.add(deleteFromOwnersTable);
    return batch;
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) BatchStatement(com.datastax.driver.core.BatchStatement) StringAssertions.validUUID(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.validUUID) UUID(java.util.UUID)

Example 15 with AuthenticationToken

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

the class MemoryTokenRepository method expired.

@Override
public void expired(String key, AuthenticationToken value) {
    String ownerId = value.ownerId;
    if (isNullOrEmpty(ownerId)) {
        return;
    }
    synchronized (tokens) {
        this.deleteTokenFromOwner(value);
        List<AuthenticationToken> ownerTokens = this.tokensByOwner.getOrDefault(value.ownerId, Lists.emptyList());
        if (!Lists.isEmpty(ownerTokens)) {
            tokensByOwner.remove(ownerId);
        }
    }
}
Also used : AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) StringAssertions.nonEmptyString(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString)

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