use of alluxio.grpc.SaslMessage in project alluxio by Alluxio.
the class AuthenticatedChannelServerDriver method onNext.
@Override
public void onNext(SaslMessage saslMessage) {
try {
if (mChannelId.equals(EMPTY_UUID)) {
initAuthenticatedChannel(saslMessage.getAuthenticationScheme(), UUID.fromString(saslMessage.getClientId()), saslMessage.getChannelRef());
}
LOG.debug("Responding to a message of channel: {}. Message: {}", mChannelRef, saslMessage);
// Consult sasl server for handling the message.
SaslMessage response = mSaslServerHandler.handleMessage(saslMessage);
// Activate if sasl is secured.
if (response.getMessageType() == SaslMessageType.SUCCESS) {
channelAuthenticated(mSaslServerHandler.getAuthenticatedUserInfo());
}
// Push response to stream.
mRequestObserver.onNext(response);
} catch (Throwable t) {
LOG.debug("Exception while handling message of channel: {}. Message: {}. Error: {}", mChannelRef, saslMessage, t);
// Invalidate stream.
mRequestObserver.onError(AlluxioStatusException.fromThrowable(t).toGrpcStatusException());
closeAuthenticatedChannel(false);
}
}
use of alluxio.grpc.SaslMessage in project alluxio by Alluxio.
the class AuthenticatedChannelClientDriver method onNext.
@Override
public void onNext(SaslMessage saslMessage) {
try {
LOG.debug("Received message for channel: {}. Message: {}", mChannelKey.toStringShort(), saslMessage);
SaslMessage response = mSaslClientHandler.handleMessage(saslMessage);
if (response != null) {
mRequestObserver.onNext(response);
} else {
// {@code null} response means server message was a success.
// Release blocked waiters.
LOG.debug("Authentication established for {}", mChannelKey.toStringShort());
mChannelAuthenticatedFuture.set(null);
}
} catch (Throwable t) {
LOG.debug("Exception while handling message for {}. Message: {}. Error: {}", mChannelKey.toStringShort(), saslMessage, t);
// Fail blocked waiters.
mChannelAuthenticatedFuture.setException(t);
mRequestObserver.onError(AlluxioStatusException.fromThrowable(t).toGrpcStatusException());
}
}
use of alluxio.grpc.SaslMessage in project alluxio by Alluxio.
the class ChannelAuthenticator method authenticate.
/**
* It builds an authenticated channel.
*
* @throws AlluxioStatusException
*/
public void authenticate() throws AlluxioStatusException {
LOG.debug("Authenticating channel: {}. AuthType: {}", mChannelKey.toStringShort(), mAuthType);
ChannelAuthenticationScheme authScheme = getChannelAuthScheme(mAuthType, mParentSubject, mChannelKey.getServerAddress().getSocketAddress());
try {
// Create client-side driver for establishing authenticated channel with the target.
mAuthDriver = new AuthenticatedChannelClientDriver(createSaslClientHandler(mChannelKey.getServerAddress(), authScheme, mParentSubject), mChannelKey);
// Initialize client-server authentication drivers.
SaslAuthenticationServiceGrpc.SaslAuthenticationServiceStub serverStub = SaslAuthenticationServiceGrpc.newStub(mConnection.getChannel());
StreamObserver<SaslMessage> requestObserver = serverStub.authenticate(mAuthDriver);
mAuthDriver.setServerObserver(requestObserver);
// Start authentication with the target. (This is blocking.)
long authTimeout = mConfiguration.getMs(PropertyKey.NETWORK_CONNECTION_AUTH_TIMEOUT);
mAuthDriver.startAuthenticatedChannel(authTimeout);
// Intercept authenticated channel with channel-id injector.
mConnection.interceptChannel(new ChannelIdInjector(mChannelKey.getChannelId()));
} catch (Throwable t) {
AlluxioStatusException e = AlluxioStatusException.fromThrowable(t);
// Build a pretty message for authentication failure.
String message = String.format("Channel authentication failed with code:%s. Channel: %s, AuthType: %s, Error: %s", e.getStatusCode().name(), mChannelKey.toStringShort(), mAuthType, e.toString());
throw AlluxioStatusException.from(Status.fromCode(e.getStatusCode()).withDescription(message).withCause(t));
}
}
Aggregations