Class: RSAML::Assertion

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/rsaml/assertion.rb

Overview

An assertion is a package of information that supplies zero or more statements made by a SAML authority.

Instance Attribute Summary collapse

Attributes included from Validatable

#verbose

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#valid?

Constructor Details

#initialize(issuer) ⇒ Assertion

Construct a new assertion from the given issuer



103
104
105
106
107
108
# File 'lib/rsaml/assertion.rb', line 103

def initialize(issuer)
  @issuer = issuer
  @version = "2.0"
  @id = UUID.new.generate
  @issue_instant = Time.now.utc
end

Instance Attribute Details

#conditionsObject

Conditions collection



100
101
102
# File 'lib/rsaml/assertion.rb', line 100

def conditions
  @conditions
end

#idObject

The identifier for this assertion.



83
84
85
# File 'lib/rsaml/assertion.rb', line 83

def id
  @id
end

#issue_instantObject

The time instant of issue in UTC



86
87
88
# File 'lib/rsaml/assertion.rb', line 86

def issue_instant
  @issue_instant
end

#issuerObject

The SAML authority that is making the claim(s) in the assertion. The issuer SHOULD be unambiguous to the intended relying parties.



90
91
92
# File 'lib/rsaml/assertion.rb', line 90

def issuer
  @issuer
end

#signatureObject

A signature that protects the integrity of and authenticates the issuer of the assertion.



93
94
95
# File 'lib/rsaml/assertion.rb', line 93

def signature
  @signature
end

#subjectObject

The subject of the statement(s) in the assertion.



77
78
79
# File 'lib/rsaml/assertion.rb', line 77

def subject
  @subject
end

#versionObject

The version of this assertion.



80
81
82
# File 'lib/rsaml/assertion.rb', line 80

def version
  @version
end

Class Method Details

.from_xml(element) ⇒ Object

Construct an Action instance from the given XML Element or fragment.



173
174
175
176
177
178
179
180
181
# File 'lib/rsaml/assertion.rb', line 173

def self.from_xml(element)
  element = REXML::Document.new(element).root if element.is_a?(String)
  issuer = Identifier::Issuer.from_xml(element.get_elements('saml:Issuer').first)
  assertion = Assertion.new(issuer)
  if (subject = element.get_elements('saml:Subject').first)
    assertion.subject = Subject.from_xml(subject)
  end
  assertion
end

Instance Method Details

#adviceObject

Additional information related to the assertion that assists processing in certain situations but which MAY be ignored by applications that do not understand the advice or do not wish to make use of it.



122
123
124
# File 'lib/rsaml/assertion.rb', line 122

def advice
  @advice ||= []
end

#assertObject

Assert the assertion.



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rsaml/assertion.rb', line 127

def assert
  # rule: if there is a signature it must be asserted
  signature.assert if signature
  
  # rule: if there are conditions then they must be asserted
  if conditions
    # rule: an assertion cache should be kept if conditions allow it
    assertion_cache << self unless conditions.cache?
    conditions.assert
  end
end

#statementsObject

Assertion statements



116
117
118
# File 'lib/rsaml/assertion.rb', line 116

def statements
  @statements ||= []
end

#to_xml(xml = Builder::XmlMarkup.new) ⇒ Object

Construct an XML fragment representing the assertion



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rsaml/assertion.rb', line 160

def to_xml(xml=Builder::XmlMarkup.new)
  attributes = {'Version' => version, 'ID' => id, 'IssueInstant' => issue_instant.xmlschema}
  xml.tag!('saml:Assertion', attributes) {
    xml << issuer.to_xml
    xml << signature.to_xml unless signature.nil?
    xml << subject.to_xml unless subject.nil?
    xml << conditions.to_xml unless conditions.nil? || conditions.empty?
    advice.each { |a| xml << a.to_xml }
    statements.each { |s| xml << s.to_xml }
  }
end

#validateObject

Validate the assertion. This validates the structural integrity of the assertion, not the validity of the assertion itself. To “assert” the assertion use the assert method.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rsaml/assertion.rb', line 141

def validate
  # rule: if there are no statements there must be a subject
  if statements.length == 0 && subject.nil?
    raise ValidationError, "An assertion with no statements must have a subject"
  end
  
  # rule: if there is an authentication then there must be a subject
  statements.each do |statement|           
    if statement_classes.include?(statement.class)
      if subject.nil?
        raise ValidationError, "An assertion with an #{statement.class.name} must have a subject"
      else
        break
      end
    end
  end
end