Search in sources :

Example 1 with AuthenticatedChannelClientDriver

use of alluxio.security.authentication.AuthenticatedChannelClientDriver in project alluxio by Alluxio.

the class GrpcChannelBuilder method build.

/**
 * Creates an authenticated channel of type {@link GrpcChannel}.
 *
 * @return the built {@link GrpcChannel}
 */
public GrpcChannel build() throws AlluxioStatusException {
    // Acquire a connection from the pool.
    GrpcConnection connection = GrpcConnectionPool.INSTANCE.acquireConnection(mChannelKey, mConfiguration);
    try {
        AuthenticatedChannelClientDriver authDriver = null;
        if (mAuthenticateChannel) {
            // Create channel authenticator based on provided content.
            ChannelAuthenticator channelAuthenticator = new ChannelAuthenticator(connection, mParentSubject, mAuthType, mConfiguration);
            // Authenticate a new logical channel.
            channelAuthenticator.authenticate();
            // Acquire authentication driver.
            authDriver = channelAuthenticator.getAuthenticationDriver();
        }
        // Return a wrapper over logical channel.
        return new GrpcChannel(connection, authDriver);
    } catch (Throwable t) {
        try {
            connection.close();
        } catch (Exception e) {
            throw new RuntimeException("Failed to release the connection. " + mChannelKey.toStringShort(), e);
        }
        // Pretty print unavailable cases.
        if (t instanceof UnavailableException) {
            throw new UnavailableException(String.format("Failed to connect to remote server %s. %s", mChannelKey.getServerAddress(), mChannelKey.toStringShort()), t.getCause());
        }
        throw AlluxioStatusException.fromThrowable(t);
    }
}
Also used : ChannelAuthenticator(alluxio.security.authentication.ChannelAuthenticator) UnavailableException(alluxio.exception.status.UnavailableException) AuthenticatedChannelClientDriver(alluxio.security.authentication.AuthenticatedChannelClientDriver) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) UnavailableException(alluxio.exception.status.UnavailableException)

Aggregations

AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 AuthenticatedChannelClientDriver (alluxio.security.authentication.AuthenticatedChannelClientDriver)1 ChannelAuthenticator (alluxio.security.authentication.ChannelAuthenticator)1