class Cql::Client::SaslAuthenticationStep

@private

Public Class Methods

new(auth_provider) click to toggle source
# File lib/cql/client/connector.rb, line 133
def initialize(auth_provider)
  @auth_provider = auth_provider
end

Public Instance Methods

challenge_cycle(pending_connection, authenticator, response_token) click to toggle source
# File lib/cql/client/connector.rb, line 157
def challenge_cycle(pending_connection, authenticator, response_token)
  request = Protocol::AuthResponseRequest.new(response_token)
  f = pending_connection.execute(request) { |raw_response| raw_response }
  f.flat_map do |response|
    case response
    when Protocol::AuthChallengeResponse
      token = authenticator.challenge_response(response.token)
      challenge_cycle(pending_connection, authenticator, token)
    when Protocol::AuthSuccessResponse
      authenticator.authentication_successful(response.token)
      Future.resolved(pending_connection)
    else
      Future.resolved(pending_connection)
    end
  end
end
run(pending_connection) click to toggle source
# File lib/cql/client/connector.rb, line 137
def run(pending_connection)
  if pending_connection.authentication_class
    begin
      authenticator = @auth_provider && @auth_provider.create_authenticator(pending_connection.authentication_class)
      if authenticator
        token = authenticator.initial_response
        challenge_cycle(pending_connection, authenticator, token)
      elsif @auth_provider
        Future.failed(AuthenticationError.new('Auth provider does not support the required authentication class "%s" and/or protocol version %d' % [pending_connection.authentication_class, @protocol_version]))
      else
        Future.failed(AuthenticationError.new('Server requested authentication, but no auth provider found'))
      end
    rescue => e
      Future.failed(AuthenticationError.new('Auth provider raised an error: %s' % e.message))
    end
  else
    Future.resolved(pending_connection)
  end
end