Search in sources :

Example 1 with SaslHandshakeResponseData

use of org.apache.kafka.common.message.SaslHandshakeResponseData in project kafka by apache.

the class SaslServerAuthenticator method handleHandshakeRequest.

private String handleHandshakeRequest(RequestContext context, SaslHandshakeRequest handshakeRequest) throws IOException, UnsupportedSaslMechanismException {
    String clientMechanism = handshakeRequest.data().mechanism();
    short version = context.header.apiVersion();
    if (version >= 1)
        this.enableKafkaSaslAuthenticateHeaders(true);
    if (enabledMechanisms.contains(clientMechanism)) {
        LOG.debug("Using SASL mechanism '{}' provided by client", clientMechanism);
        sendKafkaResponse(context, new SaslHandshakeResponse(new SaslHandshakeResponseData().setErrorCode(Errors.NONE.code()).setMechanisms(enabledMechanisms)));
        return clientMechanism;
    } else {
        LOG.debug("SASL mechanism '{}' requested by client is not supported", clientMechanism);
        buildResponseOnAuthenticateFailure(context, new SaslHandshakeResponse(new SaslHandshakeResponseData().setErrorCode(Errors.UNSUPPORTED_SASL_MECHANISM.code()).setMechanisms(enabledMechanisms)));
        throw new UnsupportedSaslMechanismException("Unsupported SASL mechanism " + clientMechanism);
    }
}
Also used : SaslHandshakeResponse(org.apache.kafka.common.requests.SaslHandshakeResponse) UnsupportedSaslMechanismException(org.apache.kafka.common.errors.UnsupportedSaslMechanismException) SaslHandshakeResponseData(org.apache.kafka.common.message.SaslHandshakeResponseData)

Example 2 with SaslHandshakeResponseData

use of org.apache.kafka.common.message.SaslHandshakeResponseData in project kafka by apache.

the class SaslHandshakeRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    SaslHandshakeResponseData response = new SaslHandshakeResponseData();
    response.setErrorCode(ApiError.fromThrowable(e).error().code());
    return new SaslHandshakeResponse(response);
}
Also used : SaslHandshakeResponseData(org.apache.kafka.common.message.SaslHandshakeResponseData)

Aggregations

SaslHandshakeResponseData (org.apache.kafka.common.message.SaslHandshakeResponseData)2 UnsupportedSaslMechanismException (org.apache.kafka.common.errors.UnsupportedSaslMechanismException)1 SaslHandshakeResponse (org.apache.kafka.common.requests.SaslHandshakeResponse)1