Class: SAML2::Assertion
- Inherits:
-
Object
- Object
- SAML2::Assertion
- Defined in:
- lib/saml2/assertion.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#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.
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
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/saml2/assertion.rb', line 5 def conditions @conditions end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/saml2/assertion.rb', line 5 def id @id end |
#issue_instant ⇒ Object (readonly)
Returns the value of attribute issue_instant.
5 6 7 |
# File 'lib/saml2/assertion.rb', line 5 def issue_instant @issue_instant end |
#issuer ⇒ Object
Returns the value of attribute issuer.
6 7 8 |
# File 'lib/saml2/assertion.rb', line 6 def issuer @issuer end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
5 6 7 |
# File 'lib/saml2/assertion.rb', line 5 def statements @statements end |
#subject ⇒ Object
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_xml ⇒ Object
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 |