Class: Onelogin::Saml::Response
- Inherits:
-
Object
- Object
- Onelogin::Saml::Response
- Defined in:
- lib/onelogin/saml/response.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#response ⇒ Object
Returns the value of attribute response.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
-
#attributes ⇒ Object
A hash of attributes and values.
- #decode ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #is_valid? ⇒ Boolean
-
#name_id ⇒ Object
The value of the user identifier as designated by the initialization request response.
- #parser(element) ⇒ Object
- #session_index ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
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
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/onelogin/saml/response.rb', line 6 def document @document end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/onelogin/saml/response.rb', line 6 def logger @logger end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/onelogin/saml/response.rb', line 6 def response @response end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/onelogin/saml/response.rb', line 6 def settings @settings end |
Instance Method Details
#attributes ⇒ Object
A hash of attributes and values
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/onelogin/saml/response.rb', line 36 def attributes result = {} document.elements.each('saml2:Assertion/saml2:AttributeStatement/saml2:Attribute') do |element| name = element.attributes['FriendlyName'] value = parser(element.elements.first) result.merge!(name => value) end result.merge!('name_id' => name_id) result.merge!('session_index' => session_index) result end |
#decode ⇒ Object
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
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_id ⇒ Object
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 |
#parser(element) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/onelogin/saml/response.rb', line 49 def parser(element) if element.elements.first.nil? return (element.name == 'AttributeValue') ? element.text : { element.name => element.text } end value = {} element.elements.each do |e| v = e.elements.first.nil? ? e.text : parser(e) if value.has_key?(e.name) value[e.name] = [value[e.name], v].flatten else value[e.name] = v end end value end |
#session_index ⇒ Object
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 |