Search in sources :

Example 1 with SaslMessage

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);
    }
}
Also used : SaslMessage(alluxio.grpc.SaslMessage)

Example 2 with SaslMessage

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());
    }
}
Also used : SaslMessage(alluxio.grpc.SaslMessage)

Example 3 with SaslMessage

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));
    }
}
Also used : ChannelAuthenticationScheme(alluxio.grpc.ChannelAuthenticationScheme) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) SaslMessage(alluxio.grpc.SaslMessage) SaslAuthenticationServiceGrpc(alluxio.grpc.SaslAuthenticationServiceGrpc)

Aggregations

SaslMessage (alluxio.grpc.SaslMessage)3 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 ChannelAuthenticationScheme (alluxio.grpc.ChannelAuthenticationScheme)1 SaslAuthenticationServiceGrpc (alluxio.grpc.SaslAuthenticationServiceGrpc)1