Class: Saml::Assertion

Inherits:
Object
  • Object
show all
Includes:
Base, XMLHelpers
Defined in:
lib/saml/assertion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XMLHelpers

#add_signature, #to_soap, #to_xml

Constructor Details

#initialize(*args) ⇒ Assertion

Returns a new instance of Assertion.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/saml/assertion.rb', line 33

def initialize(*args)
  options          = args.extract_options!
  if options[:subject].present?
    @subject = options.delete(:subject)
  else
    @subject         = Saml::Elements::Subject.new(:name_id        => options.delete(:name_id),
                                                   :name_id_format => options.delete(:name_id_format),
                                                   :recipient      => options.delete(:recipient),
                                                   :in_response_to => options.delete(:in_response_to))
  end

  @conditions      = Saml::Elements::Conditions.new(:audience => options.delete(:audience))
  authn_instant    = options.delete(:authn_instant) || Time.now
  @authn_statement = Saml::Elements::AuthnStatement.new(:authn_instant           => authn_instant,
                                                        :address                 => options.delete(:address),
                                                        :authn_context_class_ref => options.delete(:authn_context_class_ref),
                                                        :session_index           => options.delete(:session_index))
  super(*(args << options))
  @_id           ||= Saml.generate_id
  @issue_instant ||= Time.now
  @issuer        ||= Saml.current_provider.entity_id
  @version       ||= Saml::SAML_VERSION
end

Instance Attribute Details

#xml_valueObject

Returns the value of attribute xml_value.



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

def xml_value
  @xml_value
end

Instance Method Details

#add_attribute(key, value, value_attributes = {}) ⇒ Object



62
63
64
65
66
67
# File 'lib/saml/assertion.rb', line 62

def add_attribute(key, value, value_attributes = {})
  self.attribute_statement ||= Saml::Elements::AttributeStatement.new
  self.attribute_statement.attributes ||= []
  attribute_value = Saml::Elements::AttributeValue.new(value_attributes.merge(content: value))
  self.attribute_statement.attributes << Saml::Elements::Attribute.new(name: key, attribute_value: attribute_value)
end

#attribute_statementObject



89
90
91
# File 'lib/saml/assertion.rb', line 89

def attribute_statement
  attribute_statements.try(:first)
end

#attribute_statement=(attribute_statement) ⇒ Object



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

def attribute_statement=(attribute_statement)
  self.attribute_statements = [attribute_statement]
end

#fetch_attribute(key) ⇒ Object



69
70
71
# File 'lib/saml/assertion.rb', line 69

def fetch_attribute(key)
  Array(fetch_attributes(key)).first
end

#fetch_attribute_value(key) ⇒ Object



79
80
81
# File 'lib/saml/assertion.rb', line 79

def fetch_attribute_value(key)
  Array(fetch_attribute_values(key)).first
end

#fetch_attribute_values(key) ⇒ Object



83
84
85
86
87
# File 'lib/saml/assertion.rb', line 83

def fetch_attribute_values(key)
  return unless self.attribute_statements
  return unless self.attribute_statements.flat_map(&:attributes)
  attribute_statements.flat_map { |attribute_statement| attribute_statement.fetch_attribute_values(key) }
end

#fetch_attributes(key) ⇒ Object



73
74
75
76
77
# File 'lib/saml/assertion.rb', line 73

def fetch_attributes(key)
  return unless self.attribute_statements
  return unless self.attribute_statements.flat_map(&:attributes)
  attribute_statements.flat_map { |attribute_statement| attribute_statement.fetch_attributes(key) }
end

#providerSaml::Provider

Returns:



58
59
60
# File 'lib/saml/assertion.rb', line 58

def provider
  @provider ||= Saml.provider(issuer)
end