Search in sources :

Example 1 with AuthenticationException

use of org.apache.kafka.common.errors.AuthenticationException in project kafka by apache.

the class SaslClientAuthenticator method handleKafkaResponse.

private void handleKafkaResponse(RequestHeader requestHeader, byte[] responseBytes) {
    AbstractResponse response;
    ApiKeys apiKey;
    try {
        response = NetworkClient.parseResponse(ByteBuffer.wrap(responseBytes), requestHeader);
        apiKey = ApiKeys.forId(requestHeader.apiKey());
    } catch (SchemaException | IllegalArgumentException e) {
        LOG.debug("Invalid SASL mechanism response, server may be expecting only GSSAPI tokens");
        throw new AuthenticationException("Invalid SASL mechanism response", e);
    }
    switch(apiKey) {
        case SASL_HANDSHAKE:
            handleSaslHandshakeResponse((SaslHandshakeResponse) response);
            break;
        default:
            throw new IllegalStateException("Unexpected API key during handshake: " + apiKey);
    }
}
Also used : ApiKeys(org.apache.kafka.common.protocol.ApiKeys) SchemaException(org.apache.kafka.common.protocol.types.SchemaException) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException)

Aggregations

AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1 SchemaException (org.apache.kafka.common.protocol.types.SchemaException)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1