Class: Jabber::Bosh::Authentication::SASL::Query

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

Constant Summary collapse

MECHANISMS =
[:plain].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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)


184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 184

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.



167
168
169
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 167

def jid
  @jid
end

#mechanismObject (readonly)

Returns the value of attribute mechanism.



168
169
170
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 168

def mechanism
  @mechanism
end

#passwordObject (readonly)

Returns the value of attribute password.



167
168
169
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 167

def password
  @password
end

Instance Method Details

#dumpObject Also known as: to_xml

Public: Create XML string from SASL object

Returns String



209
210
211
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 209

def dump
  Ox.dump(send mechanism)
end

#plain?Boolean

Public: Is SASL object is for plain authentication

Returns boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 202

def plain?
  mechanism == :plain
end

#to_oxObject

Public: Create Ox::Element from SASL object

Returns Ox::Element



217
218
219
# File 'lib/jabber4r/bosh/authentication/sasl.rb', line 217

def to_ox
  send(mechanism)
end