Class: SAML2::Assertion
- Inherits:
-
Object
- Object
- SAML2::Assertion
- Defined in:
- lib/saml2/assertion.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#issue_instant ⇒ Object
readonly
Returns the value of attribute issue_instant.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize ⇒ Assertion
constructor
A new instance of Assertion.
- #sign(x509_certificate, private_key, algorithm_name = :sha256) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize ⇒ Assertion
Returns a new instance of Assertion.
6 7 8 9 10 |
# File 'lib/saml2/assertion.rb', line 6 def initialize @id = "_#{SecureRandom.uuid}" @issue_instant = Time.now.utc @statements = [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/saml2/assertion.rb', line 3 def id @id end |
#issue_instant ⇒ Object (readonly)
Returns the value of attribute issue_instant.
3 4 5 |
# File 'lib/saml2/assertion.rb', line 3 def issue_instant @issue_instant end |
#issuer ⇒ Object
Returns the value of attribute issuer.
4 5 6 |
# File 'lib/saml2/assertion.rb', line 4 def issuer @issuer end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
3 4 5 |
# File 'lib/saml2/assertion.rb', line 3 def statements @statements end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'lib/saml2/assertion.rb', line 4 def subject @subject end |
Instance Method Details
#sign(x509_certificate, private_key, algorithm_name = :sha256) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/saml2/assertion.rb', line 12 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_xml ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/saml2/assertion.rb', line 24 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 |