Class: Saml::Kit::Xml

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_xml) ⇒ Xml

Returns a new instance of Xml.



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

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.



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

def document
  @document
end

#raw_xml ⇒ Object (readonly)

Returns the value of attribute raw_xml.



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

def raw_xml
  @raw_xml
end

Instance Method Details

#find_all(xpath) ⇒ Object



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

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

#find_by(xpath) ⇒ Object



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

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

#to_xml(pretty: true) ⇒ Object



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

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

#x509_certificates ⇒ Object



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

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