Sha256: 49752c1192518dcd8f9158ca4b0a491bfe09f2137b5eff890deee5020aa93821

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

module SAML2
  class Assertion
    attr_reader :id, :issue_instant, :statements
    attr_accessor :issuer, :subject

    def initialize
      @id = "_#{SecureRandom.uuid}"
      @issue_instant = Time.now.utc
      @statements = []
    end

    def sign(x509_certificate, private_key, algorithm_name = :sha256)
      to_xml

      @xml.set_id_attribute('ID')
      @xml.sign!(cert: x509_certificate, key: private_key, digest_alg: algorithm_name.to_s, signature_alg: "rsa-#{algorithm_name}", uri: "##{id}")
      self
    end

    def to_xml
      @xml ||= Nokogiri::XML::Builder.new do |builder|
        builder['saml'].Assertion(
            'xmlns:saml' => Namespaces::SAML,
            ID: id,
            Version: '2.0',
            IssueInstant: issue_instant.iso8601
        ) do |builder|
          issuer.build(builder, element: 'Issuer')

          subject.build(builder)

          statements.each { |stmt| stmt.build(builder) }
        end
      end.doc.root
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saml2-1.0.0 lib/saml2/assertion.rb