Class: Jabber::Protocol::Authentication::SASL

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber4r/protocol/authentication/sasl.rb

Overview

Class provided SASL authentication on jabber server

Constant Summary collapse

MECHANISMS =
[:plain].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jid, password, options = {}) ⇒ SASL

Public: Creates new SASL authentication object

jid - [Jabber::JID|String] the jid of jabber server user password - String the user password options - Hash the authentication options (default: Empty hash)

:mechanism - Symbol the name of mechnism to use

Examples

non_sasl = Jabber::Protocol::Authentication::SASL.new(“strech@localhost/res-1”, “my-pass-phrase”) non_sasl.plain? # => true non_sasl.to_xml # =>

<auth xmlns=“urn:ietf:params:xml:ns:xmpp-sasl” mechanism=“PLAIN”>biwsbj1qdWxpZXQscj1vTXNUQUF3QUFBQU1BQUFBTlAwVEFBQUFBQUJQVTBBQQ==</auth>

Raises:

  • (TypeError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 34

def initialize(jid, password, options = {})
  raise TypeError,
    "Class(Jabber::JID) or Class(String) expected," +
    " but #{jid.class} was given" unless jid.is_a?(Jabber::JID) || jid.is_a?(String)

  @jid = jid.is_a?(Jabber::JID) ? jid : Jabber::JID.new(jid)
  @password = password

  @mechanism = options.fetch(:mechanism, :plain)

  raise ArgumentError,
    "Unknown authentication mechanism '#{mechanism}'," +
    " available is [#{MECHANISMS * ", "}]" unless MECHANISMS.include?(mechanism)
end

Instance Attribute Details

#jidObject (readonly)

Returns the value of attribute jid.



17
18
19
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 17

def jid
  @jid
end

#mechanismObject (readonly)

Returns the value of attribute mechanism.



18
19
20
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 18

def mechanism
  @mechanism
end

#passwordObject (readonly)

Returns the value of attribute password.



17
18
19
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 17

def password
  @password
end

Instance Method Details

#dumpObject Also known as: to_xml

Public: Create XML string from SASL object

Returns String



59
60
61
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 59

def dump
  Ox.dump(send mechanism)
end

#plain?Boolean

Public: Is SASL object is for plain authentication

Returns boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 52

def plain?
  mechanism == :plain
end

#to_oxObject

Public: Create Ox::Element from SASL object

Returns Ox::Element



67
68
69
# File 'lib/jabber4r/protocol/authentication/sasl.rb', line 67

def to_ox
  send(mechanism)
end