Class: Saml::Kit::Xml

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/saml/kit/xml.rb

Overview

:nodoc:

Constant Summary collapse

NAMESPACES =
{
  "NameFormat": Namespaces::ATTR_SPLAT,
  "ds": Namespaces::XMLDSIG,
  "md": Namespaces::METADATA,
  "saml": Namespaces::ASSERTION,
  "samlp": Namespaces::PROTOCOL,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_xml) ⇒ Xml

Returns a new instance of Xml.



18
19
20
21
# File 'lib/saml/kit/xml.rb', line 18

def initialize(raw_xml)
  @raw_xml = raw_xml
  @document = Nokogiri::XML(raw_xml)
end

Instance Attribute Details

#document ⇒ Object (readonly)

Returns the value of attribute document.



13
14
15
# File 'lib/saml/kit/xml.rb', line 13

def document
  @document
end

#raw_xml ⇒ Object (readonly)

Returns the value of attribute raw_xml.



13
14
15
# File 'lib/saml/kit/xml.rb', line 13

def raw_xml
  @raw_xml
end

Instance Method Details

#find_all(xpath) ⇒ Object



34
35
36
# File 'lib/saml/kit/xml.rb', line 34

def find_all(xpath)
  document.search(xpath, NAMESPACES)
end

#find_by(xpath) ⇒ Object



30
31
32
# File 'lib/saml/kit/xml.rb', line 30

def find_by(xpath)
  document.at_xpath(xpath, NAMESPACES)
end

#to_xml(pretty: true) ⇒ Object



38
39
40
# File 'lib/saml/kit/xml.rb', line 38

def to_xml(pretty: true)
  pretty ? document.to_xml(indent: 2) : raw_xml
end

#x509_certificates ⇒ Object



23
24
25
26
27
28
# File 'lib/saml/kit/xml.rb', line 23

def x509_certificates
  xpath = "//ds:KeyInfo/ds:X509Data/ds:X509Certificate"
  document.search(xpath, Xmldsig::NAMESPACES).map do |item|
    Certificate.to_x509(item.text)
  end
end