Class: Saml::Kit::Document
- Inherits:
-
Object
- Object
- Saml::Kit::Document
- Includes:
- Buildable, Translatable, Trustable, Validatable, XmlParseable, XsdValidatable
- Defined in:
- lib/saml/kit/document.rb
Overview
This class is a base class for SAML documents.
Direct Known Subclasses
Assertion, AuthenticationRequest, InvalidDocument, LogoutRequest, LogoutResponse, Response
Constant Summary collapse
- CONSTRUCTORS =
{ 'AuthnRequest' => -> { Saml::Kit::AuthenticationRequest }, 'LogoutRequest' => -> { Saml::Kit::LogoutRequest }, 'LogoutResponse' => -> { Saml::Kit::LogoutResponse }, 'Response' => -> { Saml::Kit::Response }, }.freeze
- XPATH =
[ '/samlp:AuthnRequest', '/samlp:LogoutRequest', '/samlp:LogoutResponse', '/samlp:Response', ].join('|')
Constants included from XsdValidatable
XsdValidatable::METADATA_XSD, XsdValidatable::PROTOCOL_XSD
Constants included from XmlParseable
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#registry ⇒ Object
Returns the value of attribute registry.
Class Method Summary collapse
-
.to_saml_document(xml, configuration: Saml::Kit.configuration) ⇒ Object
Returns the raw xml as a Saml::Kit SAML document.
Instance Method Summary collapse
-
#destination ⇒ Object
Returns the Destination of the SAML document.
-
#id ⇒ Object
Returns the ID for the SAML document.
-
#initialize(xml, name:, configuration: Saml::Kit.configuration) ⇒ Document
constructor
A new instance of Document.
-
#issue_instant ⇒ Object
Returns the Destination of the SAML document.
-
#issuer ⇒ Object
Returns the Issuer for the SAML document.
-
#version ⇒ Object
Returns the Version of the SAML document.
Methods included from XmlParseable
#present?, #to_h, #to_s, #to_xhtml, #to_xml
Methods included from Trustable
Methods included from Validatable
Constructor Details
#initialize(xml, name:, configuration: Saml::Kit.configuration) ⇒ Document
Returns a new instance of Document.
22 23 24 25 26 27 |
# File 'lib/saml/kit/document.rb', line 22 def initialize(xml, name:, configuration: Saml::Kit.configuration) @configuration = configuration @registry = configuration.registry @content = xml @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/saml/kit/document.rb', line 15 def name @name end |
#registry ⇒ Object
Returns the value of attribute registry.
14 15 16 |
# File 'lib/saml/kit/document.rb', line 14 def registry @registry end |
Class Method Details
.to_saml_document(xml, configuration: Saml::Kit.configuration) ⇒ Object
Returns the raw xml as a Saml::Kit SAML document.
for unpacking the document.
73 74 75 76 77 78 79 80 81 |
# File 'lib/saml/kit/document.rb', line 73 def to_saml_document(xml, configuration: Saml::Kit.configuration) namespaces = { samlp: Namespaces::PROTOCOL } element = Nokogiri::XML(xml).at_xpath(XPATH, namespaces) constructor = CONSTRUCTORS[element.name].try(:call) || InvalidDocument constructor.new(xml, configuration: configuration) rescue StandardError => error Saml::Kit.logger.error(error) InvalidDocument.new(xml, configuration: configuration) end |
Instance Method Details
#destination ⇒ Object
Returns the Destination of the SAML document.
45 46 47 |
# File 'lib/saml/kit/document.rb', line 45 def destination at_xpath('./*/@Destination').try(:value) end |
#id ⇒ Object
Returns the ID for the SAML document.
30 31 32 |
# File 'lib/saml/kit/document.rb', line 30 def id at_xpath('./*/@ID').try(:value) end |
#issue_instant ⇒ Object
Returns the Destination of the SAML document.
50 51 52 |
# File 'lib/saml/kit/document.rb', line 50 def issue_instant Time.parse(at_xpath('./*/@IssueInstant').try(:value)) end |
#issuer ⇒ Object
Returns the Issuer for the SAML document.
35 36 37 |
# File 'lib/saml/kit/document.rb', line 35 def issuer at_xpath('./*/saml:Issuer').try(:text) end |
#version ⇒ Object
Returns the Version of the SAML document.
40 41 42 |
# File 'lib/saml/kit/document.rb', line 40 def version at_xpath('./*/@Version').try(:value) end |