Class: Onelogin::Saml::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/onelogin/saml/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/onelogin/saml/response.rb', line 8

def initialize(response)
  raise ArgumentError.new("Response cannot be nil") if response.nil?
  self.response = response
  self.document = XMLSecurity::SignedDocument.new(Base64.decode64(response))
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



6
7
8
# File 'lib/onelogin/saml/response.rb', line 6

def document
  @document
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/onelogin/saml/response.rb', line 6

def logger
  @logger
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/onelogin/saml/response.rb', line 6

def response
  @response
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/onelogin/saml/response.rb', line 6

def settings
  @settings
end

Instance Method Details

#attributesObject

A hash of attributes and values



36
37
38
39
40
41
42
43
44
# File 'lib/onelogin/saml/response.rb', line 36

def attributes
  result = {}
  document.elements.each("saml2:Assertion/saml2:AttributeStatement/saml2:Attribute") do |element|
    result.merge!(element.attributes["FriendlyName"] => element.elements.first.text)
  end
  result.merge!("name_id" => name_id)
  result.merge!("session_index" => session_index)
  result
end

#decodeObject



21
22
23
24
# File 'lib/onelogin/saml/response.rb', line 21

def decode
  body = document.decode(settings.private_key)
  self.document = body
end

#is_valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/onelogin/saml/response.rb', line 14

def is_valid?
  return false if response.empty?
  return false if settings.nil?
  return true if document.validate_doc(settings.idp_public_cert, nil)
  return false
end

#name_idObject

The value of the user identifier as designated by the initialization request response



27
28
29
# File 'lib/onelogin/saml/response.rb', line 27

def name_id
  @name_id ||= document.elements["saml2:Assertion/saml2:Subject/saml2:NameID"].text
end

#session_indexObject



31
32
33
# File 'lib/onelogin/saml/response.rb', line 31

def session_index
  @session_index ||= document.elements["saml2:Assertion/saml2:AuthnStatement"].attributes["SessionIndex"]
end