Class: SAML2::Assertion

Inherits:
Object
  • Object
show all
Defined in:
lib/saml2/assertion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssertion

Returns a new instance of Assertion.



8
9
10
11
12
13
# File 'lib/saml2/assertion.rb', line 8

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

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/saml2/assertion.rb', line 5

def conditions
  @conditions
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/saml2/assertion.rb', line 5

def id
  @id
end

#issue_instantObject (readonly)

Returns the value of attribute issue_instant.



5
6
7
# File 'lib/saml2/assertion.rb', line 5

def issue_instant
  @issue_instant
end

#issuerObject

Returns the value of attribute issuer.



6
7
8
# File 'lib/saml2/assertion.rb', line 6

def issuer
  @issuer
end

#statementsObject (readonly)

Returns the value of attribute statements.



5
6
7
# File 'lib/saml2/assertion.rb', line 5

def statements
  @statements
end

#subjectObject

Returns the value of attribute subject.



6
7
8
# File 'lib/saml2/assertion.rb', line 6

def subject
  @subject
end

Instance Method Details

#sign(x509_certificate, private_key, algorithm_name = :sha256) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/saml2/assertion.rb', line 15

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}")
  # the Signature element must be right after the Issuer, so put it there
  issuer = @xml.at_xpath("saml:Issuer", Namespaces::ALL)
  signature = @xml.at_xpath("dsig:Signature", Namespaces::ALL)
  issuer.add_next_sibling(signature)
  self
end

#to_xmlObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/saml2/assertion.rb', line 27

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)

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