Search in sources :

Example 1 with SaslMessage

use of org.apache.drill.exec.proto.UserBitShared.SaslMessage in project drill by apache.

the class ServerAuthenticationHandler method handle.

@Override
public void handle(S connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
    final String remoteAddress = connection.getRemoteAddress().toString();
    // exchange involves server "challenges" and client "responses" (initiated by client)
    if (saslRequestTypeValue == rpcType) {
        final SaslMessage saslResponse;
        try {
            saslResponse = SaslMessage.PARSER.parseFrom(new ByteBufInputStream(pBody));
        } catch (final InvalidProtocolBufferException e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
            return;
        }
        logger.trace("Received SASL message {} from {}", saslResponse.getStatus(), remoteAddress);
        final SaslResponseProcessor processor = RESPONSE_PROCESSORS.get(saslResponse.getStatus());
        if (processor == null) {
            logger.info("Unknown message type from client from {}. Will stop authentication.", remoteAddress);
            handleAuthFailure(connection, sender, new SaslException("Received unexpected message"), saslResponseType);
            return;
        }
        final SaslResponseContext<S, T> context = new SaslResponseContext<>(saslResponse, connection, sender, requestHandler, saslResponseType);
        try {
            processor.process(context);
        } catch (final Exception e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
        }
    } else {
        // drop connection
        throw new RpcException(String.format("Request of type %d is not allowed without authentication. Client on %s must authenticate " + "before making requests. Connection dropped. [Details: %s]", rpcType, remoteAddress, connection.getEncryptionCtxtString()));
    }
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SaslMessage(org.apache.drill.exec.proto.UserBitShared.SaslMessage) ByteString(com.google.protobuf.ByteString) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) SaslException(javax.security.sasl.SaslException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RpcException(org.apache.drill.exec.rpc.RpcException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 2 with SaslMessage

use of org.apache.drill.exec.proto.UserBitShared.SaslMessage in project drill by apache.

the class AuthenticationOutcomeListener method success.

@Override
public void success(SaslMessage value, ByteBuf buffer) {
    logger.trace("Server responded with message of type: {}", value.getStatus());
    final SaslChallengeProcessor processor = CHALLENGE_PROCESSORS.get(value.getStatus());
    if (processor == null) {
        completionListener.failed(RpcException.mapException(new SaslException("Server sent a corrupt message.")));
    } else {
        try {
            final SaslChallengeContext<C> context = new SaslChallengeContext<>(value, ugi, connection);
            final SaslMessage saslResponse = processor.process(context);
            if (saslResponse != null) {
                client.send(new AuthenticationOutcomeListener<>(client, connection, saslRpcType, ugi, completionListener), connection, saslRpcType, saslResponse, SaslMessage.class, true);
            } else {
                // success
                completionListener.success(null, null);
                if (logger.isTraceEnabled()) {
                    logger.trace("Successfully authenticated to server using {} mechanism and encryption context: {}", connection.getSaslClient().getMechanismName(), connection.getEncryptionCtxtString());
                }
            }
        } catch (final Exception e) {
            logger.error("Authentication with encryption context: {} using mechanism {} failed with {}", connection.getEncryptionCtxtString(), connection.getSaslClient().getMechanismName(), e.getMessage());
            completionListener.failed(RpcException.mapException(e));
        }
    }
}
Also used : SaslMessage(org.apache.drill.exec.proto.UserBitShared.SaslMessage) SaslException(javax.security.sasl.SaslException) RpcException(org.apache.drill.exec.rpc.RpcException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

IOException (java.io.IOException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 SaslException (javax.security.sasl.SaslException)2 SaslMessage (org.apache.drill.exec.proto.UserBitShared.SaslMessage)2 RpcException (org.apache.drill.exec.rpc.RpcException)2 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1