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');
}
}
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");
}
}
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));
}
}
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;
}
Aggregations