Search in sources :

Example 16 with AuthenticationException

use of io.pravega.auth.AuthenticationException in project pravega by pravega.

the class PasswordAuthHandler method authenticate.

@Override
public Principal authenticate(String token) throws AuthException {
    String[] parts = parseToken(token);
    String userName = parts[0];
    char[] password = parts[1].toCharArray();
    try {
        if (aclsByUser.containsKey(userName) && encryptor.checkPassword(password, aclsByUser.get(userName).getEncryptedPassword())) {
            return new UserPrincipal(userName);
        }
        throw new AuthenticationException("User authentication exception");
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        log.warn("Exception during password authentication", e);
        throw new AuthenticationException(e);
    } finally {
        // Zero out the password for security.
        Arrays.fill(password, '0');
    }
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) UserPrincipal(io.pravega.shared.security.auth.UserPrincipal)

Example 17 with AuthenticationException

use of io.pravega.auth.AuthenticationException in project pravega by pravega.

the class TestAuthHandler method authenticate.

@Override
public Principal authenticate(String token) throws AuthException {
    log.debug("Authenticating using token [{}]", token);
    if (token.equals(TOKEN)) {
        Principal result = new TestPrincipal(TOKEN);
        log.debug("Returning principal [{}] after successful authentication", result);
        return result;
    } else {
        throw new AuthenticationException("Specified token was invalid");
    }
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) Principal(java.security.Principal)

Example 18 with AuthenticationException

use of io.pravega.auth.AuthenticationException in project pravega by pravega.

the class ConditionalOutputStreamImpl method handleUnexpectedReply.

@VisibleForTesting
RuntimeException handleUnexpectedReply(Reply reply, String expectation) {
    log.warn("Unexpected reply {} observed instead of {} for conditional writer {}", reply, expectation, writerId);
    closeConnection(reply.toString());
    if (reply instanceof WireCommands.NoSuchSegment) {
        throw new NoSuchSegmentException(reply.toString());
    } else if (reply instanceof SegmentIsSealed) {
        throw Exceptions.sneakyThrow(new SegmentSealedException(reply.toString()));
    } else if (reply instanceof WrongHost) {
        throw Exceptions.sneakyThrow(new ConnectionFailedException(reply.toString()));
    } else if (reply instanceof InvalidEventNumber) {
        InvalidEventNumber ien = (InvalidEventNumber) reply;
        throw Exceptions.sneakyThrow(new ConnectionFailedException(ien.getWriterId() + " Got stale data from setupAppend on segment " + segmentId + " for ConditionalOutputStream. Event number was " + ien.getEventNumber()));
    } else if (reply instanceof AuthTokenCheckFailed) {
        AuthTokenCheckFailed authTokenCheckFailed = (WireCommands.AuthTokenCheckFailed) reply;
        if (authTokenCheckFailed.isTokenExpired()) {
            this.tokenProvider.signalTokenExpired();
            throw Exceptions.sneakyThrow(new TokenExpiredException(authTokenCheckFailed.getServerStackTrace()));
        } else {
            throw Exceptions.sneakyThrow(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    } else {
        throw Exceptions.sneakyThrow(new ConnectionFailedException("Unexpected reply of " + reply + " when expecting an " + expectation));
    }
}
Also used : AuthTokenCheckFailed(io.pravega.shared.protocol.netty.WireCommands.AuthTokenCheckFailed) TokenExpiredException(io.pravega.auth.TokenExpiredException) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) InvalidEventNumber(io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber) AuthenticationException(io.pravega.auth.AuthenticationException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 19 with AuthenticationException

use of io.pravega.auth.AuthenticationException in project pravega by pravega.

the class MockController method abortTxSegment.

private CompletableFuture<Void> abortTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    if (!callServer) {
        result.complete(null);
        return result;
    }
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void segmentsMerged(WireCommands.SegmentsMerged segmentsMerged) {
            result.completeExceptionally(new TxnFailedException("Transaction already committed."));
        }

        @Override
        public void segmentDeleted(WireCommands.SegmentDeleted transactionAborted) {
            result.complete(null);
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    String transactionName = NameUtils.getTransactionNameFromId(segment.getScopedName(), txId);
    sendRequestOverNewConnection(new DeleteSegment(idGenerator.get(), transactionName, ""), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) AuthenticationException(io.pravega.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) CompletableFuture(java.util.concurrent.CompletableFuture) TxnFailedException(io.pravega.client.stream.TxnFailedException)

Aggregations

AuthenticationException (io.pravega.auth.AuthenticationException)19 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)12 WireCommands (io.pravega.shared.protocol.netty.WireCommands)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 Test (org.junit.Test)7 TokenExpiredException (io.pravega.auth.TokenExpiredException)6 Cleanup (lombok.Cleanup)6 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)5 Reply (io.pravega.shared.protocol.netty.Reply)5 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Segment (io.pravega.client.segment.impl.Segment)4 List (java.util.List)4 UUID (java.util.UUID)4 Unpooled (io.netty.buffer.Unpooled)3 TxnFailedException (io.pravega.client.stream.TxnFailedException)3 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)3 MockController (io.pravega.client.stream.mock.MockController)3 Exceptions (io.pravega.common.Exceptions)3 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)3