Class: Saml::Kit::Assertion

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Translatable
Defined in:
lib/saml/kit/assertion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_hash, configuration:) ⇒ Assertion

Returns a new instance of Assertion.



11
12
13
14
15
# File 'lib/saml/kit/assertion.rb', line 11

def initialize(xml_hash, configuration:)
  @name = "Assertion"
  @xml_hash = xml_hash
  @configuration = configuration
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/saml/kit/assertion.rb', line 9

def name
  @name
end

Instance Method Details

#active?(now = Time.current) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/saml/kit/assertion.rb', line 38

def active?(now = Time.current)
  now > configuration.clock_drift.before(started_at) && !expired?
end

#attributesObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/saml/kit/assertion.rb', line 42

def attributes
  @attributes ||=
    begin
      attrs = assertion.fetch('AttributeStatement', {}).fetch('Attribute', [])
      items = if attrs.is_a? Hash
                [[attrs["Name"], attrs["AttributeValue"]]]
              else
                attrs.map { |item| [item['Name'], item['AttributeValue']] }
              end
      Hash[items].with_indifferent_access
    end
end

#audiencesObject



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

def audiences
  Array(assertion['Conditions']['AudienceRestriction']['Audience'])
rescue => error
  Saml::Kit.logger.error(error)
  []
end

#encrypted?Boolean

Returns:

  • (Boolean)


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

def encrypted?
  @xml_hash.fetch('Response', {}).fetch('EncryptedAssertion', nil).present?
end

#expired?(now = Time.current) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/saml/kit/assertion.rb', line 34

def expired?(now = Time.current)
  now > expired_at
end

#expired_atObject



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

def expired_at
  parse_date(assertion.fetch('Conditions', {}).fetch('NotOnOrAfter', nil))
end

#issuerObject



17
18
19
# File 'lib/saml/kit/assertion.rb', line 17

def issuer
  assertion.fetch('Issuer')
end

#name_idObject



21
22
23
# File 'lib/saml/kit/assertion.rb', line 21

def name_id
  assertion.fetch('Subject', {}).fetch('NameID', nil)
end

#signatureObject



29
30
31
32
# File 'lib/saml/kit/assertion.rb', line 29

def signature
  xml_hash = assertion.fetch('Signature', nil)
  xml_hash ? Signature.new(xml_hash) : nil
end

#signed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/saml/kit/assertion.rb', line 25

def signed?
  signature.present?
end

#started_atObject



55
56
57
# File 'lib/saml/kit/assertion.rb', line 55

def started_at
  parse_date(assertion.fetch('Conditions', {}).fetch('NotBefore', nil))
end