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()));
}
}
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));
}
}
}
Aggregations