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

#name ⇒ Object (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? ⇒ Boolean

Returns:

  • (Boolean)


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

def active?
  Time.current > started_at && !expired?
end

#attributes ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/saml/kit/assertion.rb', line 38

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

#audiences ⇒ Object



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

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

#encrypted? ⇒ Boolean

Returns:

  • (Boolean)


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

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

#expired? ⇒ Boolean

Returns:

  • (Boolean)


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

def expired?
  Time.current > expired_at
end

#expired_at ⇒ Object



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

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

#name_id ⇒ Object



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

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

#signature ⇒ Object



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

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

#signed? ⇒ Boolean

Returns:

  • (Boolean)


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

def signed?
  signature.present?
end

#started_at ⇒ Object



51
52
53
# File 'lib/saml/kit/assertion.rb', line 51

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