Search in sources :

Example 1 with SaslServerAuthenticator

use of org.apache.kafka.common.security.authenticator.SaslServerAuthenticator in project kafka by apache.

the class SaslChannelBuilder method buildChannel.

public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize) throws KafkaException {
    try {
        SocketChannel socketChannel = (SocketChannel) key.channel();
        TransportLayer transportLayer = buildTransportLayer(id, key, socketChannel);
        Authenticator authenticator;
        if (mode == Mode.SERVER)
            authenticator = new SaslServerAuthenticator(id, jaasContext, loginManager.subject(), kerberosShortNamer, socketChannel.socket().getLocalAddress().getHostName(), maxReceiveSize, credentialCache);
        else
            authenticator = new SaslClientAuthenticator(id, loginManager.subject(), loginManager.serviceName(), socketChannel.socket().getInetAddress().getHostName(), clientSaslMechanism, handshakeRequestEnable);
        // Both authenticators don't use `PrincipalBuilder`, so we pass `null` for now. Reconsider if this changes.
        authenticator.configure(transportLayer, null, this.configs);
        return new KafkaChannel(id, transportLayer, authenticator, maxReceiveSize);
    } catch (Exception e) {
        log.info("Failed to create channel due to ", e);
        throw new KafkaException(e);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) SaslServerAuthenticator(org.apache.kafka.common.security.authenticator.SaslServerAuthenticator) KafkaException(org.apache.kafka.common.KafkaException) SaslClientAuthenticator(org.apache.kafka.common.security.authenticator.SaslClientAuthenticator) SaslServerAuthenticator(org.apache.kafka.common.security.authenticator.SaslServerAuthenticator) SaslClientAuthenticator(org.apache.kafka.common.security.authenticator.SaslClientAuthenticator) KafkaException(org.apache.kafka.common.KafkaException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketChannel (java.nio.channels.SocketChannel)1 KafkaException (org.apache.kafka.common.KafkaException)1 SaslClientAuthenticator (org.apache.kafka.common.security.authenticator.SaslClientAuthenticator)1 SaslServerAuthenticator (org.apache.kafka.common.security.authenticator.SaslServerAuthenticator)1