Sha256: 672e214f0d6a4cae3d33aff234f53643c5939686d49b1b7b2db0d9a745915dae

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

require 'kafka/sasl_gssapi_authenticator'
require 'kafka/sasl_plain_authenticator'

module Kafka
  class SaslAuthenticator
    def initialize(logger:, sasl_gssapi_principal:, sasl_gssapi_keytab:, sasl_plain_authzid:, sasl_plain_username:, sasl_plain_password:)
      @logger = logger
      @sasl_gssapi_principal = sasl_gssapi_principal
      @sasl_gssapi_keytab = sasl_gssapi_keytab
      @sasl_plain_authzid = sasl_plain_authzid
      @sasl_plain_username = sasl_plain_username
      @sasl_plain_password = sasl_plain_password
    end

    def authenticate!(connection)
      if authenticate_using_sasl_gssapi?
        sasl_gssapi_authenticate(connection)
      elsif authenticate_using_sasl_plain?
        sasl_plain_authenticate(connection)
      end
    end

    private

    def sasl_gssapi_authenticate(connection)
      auth = SaslGssapiAuthenticator.new(
        connection: connection,
        logger: @logger,
        sasl_gssapi_principal: @sasl_gssapi_principal,
        sasl_gssapi_keytab: @sasl_gssapi_keytab
      )

      auth.authenticate!
    end

    def sasl_plain_authenticate(connection)
      auth = SaslPlainAuthenticator.new(
        connection: connection,
        logger: @logger,
        authzid: @sasl_plain_authzid,
        username: @sasl_plain_username,
        password: @sasl_plain_password
      )

      auth.authenticate!
    end

    def authenticate_using_sasl_gssapi?
      !@ssl_context && @sasl_gssapi_principal && !@sasl_gssapi_principal.empty?
    end

    def authenticate_using_sasl_plain?
      @sasl_plain_authzid && @sasl_plain_username && @sasl_plain_password
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby-kafka-0.4.4 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0.beta6 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0.beta5 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0.beta4 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0.beta3 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.5.0.beta2 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.4.3 lib/kafka/sasl_authenticator.rb
ruby-kafka-0.4.2 lib/kafka/sasl_authenticator.rb