Sha256: 2e17a0275779406e24cd4771b8b9f96887384a43e92d891ace2c8e8feb2a6592

Contents?: true

Size: 909 Bytes

Versions: 15

Compression:

Stored size: 909 Bytes

Contents

module Kafka
  module Sasl
    class Plain
      PLAIN_IDENT = "PLAIN"

      def initialize(logger:, authzid:, username:, password:)
        @logger = logger
        @authzid = authzid
        @username = username
        @password = password
      end

      def ident
        PLAIN_IDENT
      end

      def configured?
        @authzid && @username && @password
      end

      def authenticate!(host, encoder, decoder)
        msg = [@authzid, @username, @password].join("\000").force_encoding("utf-8")

        encoder.write_bytes(msg)

        begin
          msg = decoder.bytes
          raise Kafka::Error, "SASL PLAIN authentication failed: unknown error" unless msg
        rescue Errno::ETIMEDOUT, EOFError => e
          raise Kafka::Error, "SASL PLAIN authentication failed: #{e.message}"
        end

        @logger.debug "SASL PLAIN authentication successful."
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ruby-kafka-0.6.0.beta4 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.0.beta3 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.0.beta2 lib/kafka/sasl/plain.rb
ruby-kafka-0.6.0.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.5 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.4 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.4.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.3 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.2 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.2.beta3 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.2.beta2 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.2.beta1 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.1 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.1.beta2 lib/kafka/sasl/plain.rb
ruby-kafka-0.5.1.beta1 lib/kafka/sasl/plain.rb