Class: Saml::Kit::Document
- Inherits:
-
Object
- Object
- Saml::Kit::Document
- Includes:
- ActiveModel::Validations, Buildable, Translatable, Trustable, XsdValidatable
- Defined in:
- lib/saml/kit/document.rb
Direct Known Subclasses
AuthenticationRequest, InvalidDocument, LogoutRequest, LogoutResponse, Response
Constant Summary collapse
- PROTOCOL_XSD =
File.('./xsd/saml-schema-protocol-2.0.xsd', File.dirname(__FILE__)).freeze
- NAMESPACES =
{ "NameFormat": ::Saml::Kit::Namespaces::ATTR_SPLAT, "ds": ::Xml::Kit::Namespaces::XMLDSIG, "md": ::Saml::Kit::Namespaces::METADATA, "saml": ::Saml::Kit::Namespaces::ASSERTION, "samlp": ::Saml::Kit::Namespaces::PROTOCOL, 'xmlenc' => ::Xml::Kit::Namespaces::XMLENC, }.freeze
- XPATH =
[ '/samlp:AuthnRequest', '/samlp:LogoutRequest', '/samlp:LogoutResponse', '/samlp:Response', ].join('|')
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.
-
#to_h ⇒ Object
Returns the SAML document returned as a Hash.
- #to_s ⇒ Object
-
#to_xhtml ⇒ Object
Returns the SAML document as an XHTML string.
-
#to_xml(pretty: false) ⇒ Object
Returns the SAML document as an XML string.
-
#version ⇒ Object
Returns the Version of the SAML document.
Methods included from Trustable
Constructor Details
#initialize(xml, name:, configuration: Saml::Kit.configuration) ⇒ Document
Returns a new instance of Document.
26 27 28 29 30 |
# File 'lib/saml/kit/document.rb', line 26 def initialize(xml, name:, configuration: Saml::Kit.configuration) @configuration = configuration @content = xml @name = name end |
Class Method Details
.to_saml_document(xml, configuration: Saml::Kit.configuration) ⇒ Object
Returns the raw xml as a Saml::Kit SAML document.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/saml/kit/document.rb', line 106 def to_saml_document(xml, configuration: Saml::Kit.configuration) constructor = { 'AuthnRequest' => Saml::Kit::AuthenticationRequest, 'LogoutRequest' => Saml::Kit::LogoutRequest, 'LogoutResponse' => Saml::Kit::LogoutResponse, 'Response' => Saml::Kit::Response, }[Nokogiri::XML(xml).at_xpath(XPATH, "samlp": ::Saml::Kit::Namespaces::PROTOCOL).name] || 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.
48 49 50 |
# File 'lib/saml/kit/document.rb', line 48 def destination at_xpath('./*/@Destination').try(:value) end |
#id ⇒ Object
Returns the ID for the SAML document.
33 34 35 |
# File 'lib/saml/kit/document.rb', line 33 def id at_xpath('./*/@ID').try(:value) end |
#issue_instant ⇒ Object
Returns the Destination of the SAML document.
53 54 55 |
# File 'lib/saml/kit/document.rb', line 53 def issue_instant Time.parse(at_xpath('./*/@IssueInstant').try(:value)) end |
#issuer ⇒ Object
Returns the Issuer for the SAML document.
38 39 40 |
# File 'lib/saml/kit/document.rb', line 38 def issuer at_xpath('./*/saml:Issuer').try(:text) end |
#to_h ⇒ Object
Returns the SAML document returned as a Hash.
58 59 60 |
# File 'lib/saml/kit/document.rb', line 58 def to_h @xml_hash ||= Hash.from_xml(content) || {} end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/saml/kit/document.rb', line 90 def to_s to_xml end |
#to_xhtml ⇒ Object
Returns the SAML document as an XHTML string. This is useful for rendering in a web page.
71 72 73 |
# File 'lib/saml/kit/document.rb', line 71 def to_xhtml Nokogiri::XML(to_xml, &:noblanks).to_xhtml end |
#to_xml(pretty: false) ⇒ Object
Returns the SAML document as an XML string.
65 66 67 |
# File 'lib/saml/kit/document.rb', line 65 def to_xml(pretty: false) pretty ? to_nokogiri.to_xml(indent: 2) : content end |
#version ⇒ Object
Returns the Version of the SAML document.
43 44 45 |
# File 'lib/saml/kit/document.rb', line 43 def version at_xpath('./*/@Version').try(:value) end |