Search in sources :

Example 1 with SaslAuthenticateRequestData

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

the class SaslAuthenticatorTest method authenticateUsingSaslPlainAndCheckConnection.

private void authenticateUsingSaslPlainAndCheckConnection(String node, boolean enableSaslAuthenticateHeader) throws Exception {
    // Authenticate using PLAIN username/password
    String authString = "\u0000" + TestJaasConfig.USERNAME + "\u0000" + TestJaasConfig.PASSWORD;
    ByteBuffer authBuf = ByteBuffer.wrap(Utils.utf8(authString));
    if (enableSaslAuthenticateHeader) {
        SaslAuthenticateRequestData data = new SaslAuthenticateRequestData().setAuthBytes(authBuf.array());
        SaslAuthenticateRequest request = new SaslAuthenticateRequest.Builder(data).build();
        sendKafkaRequestReceiveResponse(node, ApiKeys.SASL_AUTHENTICATE, request);
    } else {
        selector.send(new NetworkSend(node, ByteBufferSend.sizePrefixed(authBuf)));
        waitForResponse();
    }
    // Check send/receive on the manually authenticated connection
    NetworkTestUtils.checkClientConnection(selector, node, 100, 10);
}
Also used : SaslAuthenticateRequestData(org.apache.kafka.common.message.SaslAuthenticateRequestData) SaslAuthenticateRequest(org.apache.kafka.common.requests.SaslAuthenticateRequest) NetworkSend(org.apache.kafka.common.network.NetworkSend) ByteBuffer(java.nio.ByteBuffer)

Example 2 with SaslAuthenticateRequestData

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

the class SaslClientAuthenticator method sendSaslClientToken.

/**
 * Sends a SASL client token to server if required. This may be an initial token to start
 * SASL token exchange or response to a challenge from the server.
 * @return true if a token was sent to the server
 */
private boolean sendSaslClientToken(byte[] serverToken, boolean isInitial) throws IOException {
    if (!saslClient.isComplete()) {
        byte[] saslToken = createSaslToken(serverToken, isInitial);
        if (saslToken != null) {
            ByteBuffer tokenBuf = ByteBuffer.wrap(saslToken);
            Send send;
            if (saslAuthenticateVersion == DISABLE_KAFKA_SASL_AUTHENTICATE_HEADER) {
                send = ByteBufferSend.sizePrefixed(tokenBuf);
            } else {
                SaslAuthenticateRequestData data = new SaslAuthenticateRequestData().setAuthBytes(tokenBuf.array());
                SaslAuthenticateRequest request = new SaslAuthenticateRequest.Builder(data).build(saslAuthenticateVersion);
                send = request.toSend(nextRequestHeader(ApiKeys.SASL_AUTHENTICATE, saslAuthenticateVersion));
            }
            send(send);
            return true;
        }
    }
    return false;
}
Also used : SaslAuthenticateRequestData(org.apache.kafka.common.message.SaslAuthenticateRequestData) SaslAuthenticateRequest(org.apache.kafka.common.requests.SaslAuthenticateRequest) ByteBuffer(java.nio.ByteBuffer) Send(org.apache.kafka.common.network.Send) ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 SaslAuthenticateRequestData (org.apache.kafka.common.message.SaslAuthenticateRequestData)2 SaslAuthenticateRequest (org.apache.kafka.common.requests.SaslAuthenticateRequest)2 ByteBufferSend (org.apache.kafka.common.network.ByteBufferSend)1 NetworkSend (org.apache.kafka.common.network.NetworkSend)1 Send (org.apache.kafka.common.network.Send)1