Class: Vines::Stream::Client::Auth

Inherits:
State
  • Object
show all
Defined in:
lib/vines/stream/client/auth.rb

Direct Known Subclasses

Http::Auth, Server::Auth

Constant Summary collapse

NS =
NAMESPACES[:sasl]
AUTH =
'auth'.freeze
SUCCESS =
%Q{<success xmlns="#{NS}"/>}.freeze
MAX_AUTH_ATTEMPTS =
3
AUTH_MECHANISMS =
{'PLAIN' => :plain_auth, 'EXTERNAL' => :external_auth}.freeze

Constants inherited from State

State::BODY, State::STREAM

Instance Attribute Summary

Attributes inherited from State

#stream

Instance Method Summary collapse

Methods inherited from State

#==, #eql?, #hash

Methods included from Log

#log

Constructor Details

#initialize(stream, success = BindRestart) ⇒ Auth

Returns a new instance of Auth.



13
14
15
16
# File 'lib/vines/stream/client/auth.rb', line 13

def initialize(stream, success=BindRestart)
  super
  @attempts, @outstanding = 0, false
end

Instance Method Details

#node(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vines/stream/client/auth.rb', line 18

def node(node)
  raise StreamErrors::NotAuthorized unless auth?(node)
  unless node.text.empty?
    (name = AUTH_MECHANISMS[node['mechanism']]) ?
        method(name).call(node) :
        send_auth_fail(SaslErrors::InvalidMechanism.new)
  else
    send_auth_fail(SaslErrors::MalformedRequest.new)
  end
end