Commit c1ca4bd
Changed files (3)
lib
saml
kit
concerns
lib/saml/kit/concerns/xml_parseable.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'saml/kit/namespaces'
+
+module Saml
+ module Kit
+ module XmlParseable
+ 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
+
+ # Returns the SAML document returned as a Hash.
+ def to_h
+ @to_h ||= Hash.from_xml(content) || {}
+ end
+
+ # Returns the SAML document as an XML string.
+ #
+ # @param pretty [Boolean] formats the xml or returns the raw xml.
+ def to_xml(pretty: nil)
+ pretty ? to_nokogiri.to_xml(indent: 2) : to_s
+ end
+
+ # Returns the SAML document as an XHTML string.
+ # This is useful for rendering in a web page.
+ def to_xhtml
+ Nokogiri::XML(to_xml, &:noblanks).to_xhtml
+ end
+
+ # @!visibility private
+ def to_nokogiri
+ @to_nokogiri ||= Nokogiri::XML(to_s)
+ end
+
+ # @!visibility private
+ def at_xpath(xpath)
+ to_nokogiri.at_xpath(xpath, NAMESPACES)
+ end
+
+ # @!visibility private
+ def search(xpath)
+ to_nokogiri.search(xpath, NAMESPACES)
+ end
+
+ def to_s
+ content
+ end
+ end
+ end
+end
lib/saml/kit/document.rb
@@ -5,18 +5,12 @@ module Saml
# This class is a base class for SAML documents.
class Document
include ActiveModel::Validations
- include XsdValidatable
+ include Buildable
include Translatable
include Trustable
- include Buildable
- 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
+ include XmlParseable
+ include XsdValidatable
+
attr_accessor :registry
attr_reader :name
validates_presence_of :content
@@ -57,43 +51,6 @@ module Saml
Time.parse(at_xpath('./*/@IssueInstant').try(:value))
end
- # Returns the SAML document returned as a Hash.
- def to_h
- @to_h ||= Hash.from_xml(content) || {}
- end
-
- # Returns the SAML document as an XML string.
- #
- # @param pretty [Boolean] formats the xml or returns the raw xml.
- def to_xml(pretty: nil)
- pretty ? to_nokogiri.to_xml(indent: 2) : to_s
- end
-
- # Returns the SAML document as an XHTML string.
- # This is useful for rendering in a web page.
- def to_xhtml
- Nokogiri::XML(to_xml, &:noblanks).to_xhtml
- end
-
- # @!visibility private
- def to_nokogiri
- @to_nokogiri ||= Nokogiri::XML(to_s)
- end
-
- # @!visibility private
- def at_xpath(xpath)
- to_nokogiri.at_xpath(xpath, NAMESPACES)
- end
-
- # @!visibility private
- def search(xpath)
- to_nokogiri.search(xpath, NAMESPACES)
- end
-
- def to_s
- content
- end
-
class << self
XPATH = [
'/samlp:AuthnRequest',
lib/saml/kit.rb
@@ -23,6 +23,7 @@ require 'saml/kit/concerns/respondable'
require 'saml/kit/concerns/serializable'
require 'saml/kit/concerns/translatable'
require 'saml/kit/concerns/trustable'
+require 'saml/kit/concerns/xml_parseable'
require 'saml/kit/concerns/xml_templatable'
require 'saml/kit/concerns/xsd_validatable'