Search in sources :

Example 6 with UnsupportedSaslMechanismException

use of org.apache.kafka.common.errors.UnsupportedSaslMechanismException 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)

Aggregations

UnsupportedSaslMechanismException (org.apache.kafka.common.errors.UnsupportedSaslMechanismException)6 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)3 ApiVersionsRequest (org.apache.kafka.common.requests.ApiVersionsRequest)3 SaslHandshakeResponse (org.apache.kafka.common.requests.SaslHandshakeResponse)3 ByteBuffer (java.nio.ByteBuffer)2 InetSocketAddress (java.net.InetSocketAddress)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1