Sha256: ca546dbb52aa115136a0dddbadb8fd19c7a3de566d97897caef9ce2207338e40

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

Contents

module Saml
  module XMLHelpers
    extend ActiveSupport::Concern

    def add_signature
      self.signature = Saml::Elements::Signature.new(uri: "##{self._id}")
      x509certificate = OpenSSL::X509::Certificate.new(provider.certificate) rescue nil
      self.signature.key_info = Saml::Elements::KeyInfo.new(x509certificate.to_pem) if x509certificate
    end

    def to_xml(builder = nil, default_namespace = nil, instruct = true)
      write_xml            = builder.nil? ? true : false
      builder              ||= Nokogiri::XML::Builder.new
      builder.doc.encoding = "UTF-8"
      result               = super(builder, default_namespace)
      if write_xml
        instruct ? result.to_xml : result.doc.root
      else
        result
      end

    end

    def to_soap
      builder = Nokogiri::XML::Builder.new
      body    = self.to_xml(builder)

      builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8")
      builder.Envelope(:'xmlns:soapenv' => "http://schemas.xmlsoap.org/soap/envelope/") do |xml|
        builder.parent.namespace = builder.parent.namespace_definitions.find { |n| n.prefix == 'soapenv' }
        builder.Body do
          builder.parent.add_child body.doc.root
        end
      end
      builder.to_xml
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
libsaml-2.12.1 lib/saml/xml_helpers.rb
libsaml-2.12.0 lib/saml/xml_helpers.rb
libsaml-2.11.2 lib/saml/xml_helpers.rb
libsaml-2.11.1 lib/saml/xml_helpers.rb
libsaml-2.11.0 lib/saml/xml_helpers.rb
libsaml-2.10.7 lib/saml/xml_helpers.rb
libsaml-2.10.6 lib/saml/xml_helpers.rb
libsaml-2.10.5 lib/saml/xml_helpers.rb
libsaml-2.10.4 lib/saml/xml_helpers.rb
libsaml-2.10.3 lib/saml/xml_helpers.rb
libsaml-2.10.2 lib/saml/xml_helpers.rb
libsaml-2.10.1 lib/saml/xml_helpers.rb
libsaml-2.10.0 lib/saml/xml_helpers.rb
libsaml-2.9.0 lib/saml/xml_helpers.rb