Class: Onelogin::Saml::Logoutresponse

Inherits:
Object
  • Object
show all
Defined in:
lib/onelogin/ruby-saml/logoutresponse.rb

Constant Summary collapse

ASSERTION =
"urn:oasis:names:tc:SAML:2.0:assertion"
PROTOCOL =
"urn:oasis:names:tc:SAML:2.0:protocol"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, settings = nil, options = {}) ⇒ Logoutresponse

In order to validate that the response matches a given request, append the option:

:matches_request_id => REQUEST_ID

It will validate that the logout response matches the ID of the request. You can also do this yourself through the in_response_to accessor.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 29

def initialize(response, settings = nil, options = {})
  raise ArgumentError.new("Logoutresponse cannot be nil") if response.nil?
  self.settings = settings

  @options = options
  @response = decode_raw_response(response)
  @document = XMLSecurity::SignedDocument.new(response)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



17
18
19
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 17

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 19

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



18
19
20
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 18

def response
  @response
end

#settingsObject

For API compability, this is mutable.



15
16
17
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 15

def settings
  @settings
end

Instance Method Details

#in_response_toObject



55
56
57
58
59
60
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 55

def in_response_to
  @in_response_to ||= begin
    node = REXML::XPath.first(document, "/p:LogoutResponse", { "p" => PROTOCOL, "a" => ASSERTION })
    node.nil? ? nil : node.attributes['InResponseTo']
  end
end

#issuerObject



62
63
64
65
66
67
68
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 62

def issuer
  @issuer ||= begin
    node = REXML::XPath.first(document, "/p:LogoutResponse/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION })
    node ||= REXML::XPath.first(document, "/p:LogoutResponse/a:Assertion/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION })
    node.nil? ? nil : node.text
  end
end

#status_codeObject



70
71
72
73
74
75
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 70

def status_code
  @status_code ||= begin
    node = REXML::XPath.first(document, "/p:LogoutResponse/p:Status/p:StatusCode", { "p" => PROTOCOL, "a" => ASSERTION })
    node.nil? ? nil : node.attributes["Value"]
  end
end

#success?(soft = true) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 48

def success?(soft = true)
  unless status_code == "urn:oasis:names:tc:SAML:2.0:status:Success"
    return soft ? false : validation_error("Bad status code. Expected <urn:oasis:names:tc:SAML:2.0:status:Success>, but was: <#@status_code> ")
  end
  true
end

#validate(soft = true) ⇒ Object



42
43
44
45
46
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 42

def validate(soft = true)
  return false unless valid_saml?(soft) && valid_state?(soft)

  valid_in_response_to?(soft) && valid_issuer?(soft) && success?(soft)
end

#validate!Object



38
39
40
# File 'lib/onelogin/ruby-saml/logoutresponse.rb', line 38

def validate!
  validate(false)
end