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
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.
16 17 18 19 20 21 |
# File 'lib/saml/kit/document.rb', line 16 def initialize(xml, name:, configuration: Saml::Kit.configuration) @configuration = configuration @content = xml @name = name @xml_hash = Hash.from_xml(xml) || {} end |
Class Method Details
.to_saml_document(xml, configuration: Saml::Kit.configuration) ⇒ Object
Returns the raw xml as a Saml::Kit SAML document.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/saml/kit/document.rb', line 75 def to_saml_document(xml, configuration: Saml::Kit.configuration) hash = Hash.from_xml(xml) if hash['Response'].present? Response.new(xml, configuration: configuration) elsif hash['LogoutResponse'].present? LogoutResponse.new(xml, configuration: configuration) elsif hash['AuthnRequest'].present? AuthenticationRequest.new(xml, configuration: configuration) elsif hash['LogoutRequest'].present? LogoutRequest.new(xml, configuration: configuration) end rescue => error Saml::Kit.logger.error(error) InvalidDocument.new(xml) end |
Instance Method Details
#destination ⇒ Object
Returns the Destination of the SAML document.
39 40 41 |
# File 'lib/saml/kit/document.rb', line 39 def destination to_h.fetch(name, {}).fetch('Destination', nil) end |
#id ⇒ Object
Returns the ID for the SAML document.
24 25 26 |
# File 'lib/saml/kit/document.rb', line 24 def id to_h.fetch(name, {}).fetch('ID', nil) end |
#issue_instant ⇒ Object
Returns the Destination of the SAML document.
44 45 46 |
# File 'lib/saml/kit/document.rb', line 44 def issue_instant Time.parse(to_h[name]['IssueInstant']) end |
#issuer ⇒ Object
Returns the Issuer for the SAML document.
29 30 31 |
# File 'lib/saml/kit/document.rb', line 29 def issuer to_h.fetch(name, {}).fetch('Issuer', nil) end |
#to_h ⇒ Object
Returns the SAML document returned as a Hash.
49 50 51 |
# File 'lib/saml/kit/document.rb', line 49 def to_h @xml_hash end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/saml/kit/document.rb', line 66 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.
62 63 64 |
# File 'lib/saml/kit/document.rb', line 62 def to_xhtml Nokogiri::XML(content, &:noblanks).to_xhtml end |
#to_xml(pretty: false) ⇒ Object
Returns the SAML document as an XML string.
56 57 58 |
# File 'lib/saml/kit/document.rb', line 56 def to_xml(pretty: false) pretty ? Nokogiri::XML(content).to_xml(indent: 2) : content end |
#version ⇒ Object
Returns the Version of the SAML document.
34 35 36 |
# File 'lib/saml/kit/document.rb', line 34 def version to_h.fetch(name, {}).fetch('Version', {}) end |