Class: Federa::Saml::Response
- Inherits:
-
Object
- Object
- Federa::Saml::Response
- Defined in:
- lib/federa/ruby-saml/response.rb
Constant Summary collapse
- ASSERTION =
"urn:oasis:names:tc:SAML:2.0:assertion"
- PROTOCOL =
"urn:oasis:names:tc:SAML:2.0:protocol"
- DSIG =
"http://www.w3.org/2000/09/xmldsig#"
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#options ⇒ Object
Returns the value of attribute options.
-
#response ⇒ Object
Returns the value of attribute response.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #assertion_id ⇒ Object
- #assertion_subject ⇒ Object
- #assertion_subject_name_qualifier ⇒ Object
-
#attributes ⇒ Object
A hash of alle the attributes with the response.
-
#conditions ⇒ Object
Conditions (if any) for the assertion to run.
- #id ⇒ Object
-
#initialize(response, options = {}) ⇒ Response
constructor
A new instance of Response.
- #is_valid? ⇒ Boolean
- #issue_instant ⇒ Object
-
#issuer ⇒ Object
metodi per ricavare info per tracciatura agid.
-
#name_id ⇒ Object
The value of the user identifier as designated by the initialization request response.
- #response_to_id ⇒ Object
-
#session_expires_at ⇒ Object
When this user session should expire at latest.
-
#success? ⇒ Boolean
Checks the status of the response for a “Success” code.
- #validate! ⇒ Object
Constructor Details
#initialize(response, options = {}) ⇒ Response
Returns a new instance of Response.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/federa/ruby-saml/response.rb', line 19 def initialize(response, = {}) raise ArgumentError.new("Response cannot be nil") if response.nil? self. = self.response = response begin self.document = XMLSecurity::SignedDocument.new(Base64.decode64(response)) rescue REXML::ParseException => e if response =~ /</ self.document = XMLSecurity::SignedDocument.new(response) else raise e end end end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
17 18 19 |
# File 'lib/federa/ruby-saml/response.rb', line 17 def document @document end |
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/federa/ruby-saml/response.rb', line 17 def end |
#response ⇒ Object
Returns the value of attribute response.
17 18 19 |
# File 'lib/federa/ruby-saml/response.rb', line 17 def response @response end |
#settings ⇒ Object
Returns the value of attribute settings.
17 18 19 |
# File 'lib/federa/ruby-saml/response.rb', line 17 def settings @settings end |
Instance Method Details
#assertion_id ⇒ Object
123 124 125 126 |
# File 'lib/federa/ruby-saml/response.rb', line 123 def assertion_id node = REXML::XPath.first(document, "/p:Response/a:Assertion/", { "p" => PROTOCOL, "a" => ASSERTION }) return node.attributes["ID"] end |
#assertion_subject ⇒ Object
128 129 130 131 |
# File 'lib/federa/ruby-saml/response.rb', line 128 def assertion_subject node = REXML::XPath.first(document, "/p:Response/a:Assertion/a:Subject/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION }) return node.text end |
#assertion_subject_name_qualifier ⇒ Object
133 134 135 136 |
# File 'lib/federa/ruby-saml/response.rb', line 133 def assertion_subject_name_qualifier node = REXML::XPath.first(document, "/p:Response/a:Assertion/a:Subject/a:NameID", { "p" => PROTOCOL, "a" => ASSERTION }) return node.attributes["NameQualifier"] end |
#attributes ⇒ Object
A hash of alle the attributes with the response. Assuming there is only one value for each key
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/federa/ruby-saml/response.rb', line 53 def attributes @attr_statements ||= begin result = {} stmt_element = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AttributeStatement", { "p" => PROTOCOL, "a" => ASSERTION }) return {} if stmt_element.nil? stmt_element.elements.each do |attr_element| name = attr_element.attributes["Name"] value = attr_element.elements.first.text result[name] = value end result.keys.each do |key| result[key.intern] = result[key] end result end end |
#conditions ⇒ Object
Conditions (if any) for the assertion to run
92 93 94 95 96 |
# File 'lib/federa/ruby-saml/response.rb', line 92 def conditions @conditions ||= begin REXML::XPath.first(document, "/p:Response/a:Assertion[@ID='#{document.signed_element_id}']/a:Conditions", { "p" => PROTOCOL, "a" => ASSERTION }) end end |
#id ⇒ Object
113 114 115 116 |
# File 'lib/federa/ruby-saml/response.rb', line 113 def id node = REXML::XPath.first(document, "/p:Response", { "p" => PROTOCOL }) return node.attributes["ID"] end |
#is_valid? ⇒ Boolean
35 36 37 |
# File 'lib/federa/ruby-saml/response.rb', line 35 def is_valid? validate end |
#issue_instant ⇒ Object
118 119 120 121 |
# File 'lib/federa/ruby-saml/response.rb', line 118 def issue_instant node = REXML::XPath.first(document, "/p:Response", { "p" => PROTOCOL }) return node.attributes["IssueInstant"] end |
#issuer ⇒ Object
metodi per ricavare info per tracciatura agid
100 101 102 103 104 105 106 |
# File 'lib/federa/ruby-saml/response.rb', line 100 def issuer @issuer ||= begin node = REXML::XPath.first(document, "/p:Response/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION }) node ||= REXML::XPath.first(document, "/p:Response/a:Assertion/a:Issuer", { "p" => PROTOCOL, "a" => ASSERTION }) node.nil? ? nil : node.text end end |
#name_id ⇒ Object
The value of the user identifier as designated by the initialization request response
44 45 46 47 48 49 50 |
# File 'lib/federa/ruby-saml/response.rb', line 44 def name_id @name_id ||= begin node = REXML::XPath.first(document, "/saml2p:Response/saml2:Assertion[@ID='#{document.signed_element_id}']/saml2:Subject/saml2:NameID") node ||= REXML::XPath.first(document, "/saml2p:Response[@ID='#{document.signed_element_id}']/saml2:Assertion/saml2:Subject/saml2:NameID") node.nil? ? nil : node.text end end |
#response_to_id ⇒ Object
108 109 110 111 |
# File 'lib/federa/ruby-saml/response.rb', line 108 def response_to_id node = REXML::XPath.first(document, "/p:Response", { "p" => PROTOCOL }) return node.attributes["InResponseTo"] end |
#session_expires_at ⇒ Object
When this user session should expire at latest
76 77 78 79 80 81 |
# File 'lib/federa/ruby-saml/response.rb', line 76 def session_expires_at @expires_at ||= begin node = REXML::XPath.first(document, "/p:Response/a:Assertion/a:AuthnStatement", { "p" => PROTOCOL, "a" => ASSERTION }) parse_time(node, "SessionNotOnOrAfter") end end |
#success? ⇒ Boolean
Checks the status of the response for a “Success” code
84 85 86 87 88 89 |
# File 'lib/federa/ruby-saml/response.rb', line 84 def success? @status_code ||= begin node = REXML::XPath.first(document, "/p:Response/p:Status/p:StatusCode", { "p" => PROTOCOL, "a" => ASSERTION }) node.attributes["Value"] == "urn:oasis:names:tc:SAML:2.0:status:Success" end end |
#validate! ⇒ Object
39 40 41 |
# File 'lib/federa/ruby-saml/response.rb', line 39 def validate! validate(false) end |