Search in sources :

Example 1 with ChannelAuthenticationScheme

use of alluxio.grpc.ChannelAuthenticationScheme 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

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