Class: Samlr::Condition

Inherits:
Object show all
Defined in:
lib/samlr/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition, options) ⇒ Condition

Returns a new instance of Condition.



5
6
7
8
9
10
# File 'lib/samlr/condition.rb', line 5

def initialize(condition, options)
  @options         = options
  @not_before      = (condition || {})["NotBefore"]
  @not_on_or_after = (condition || {})["NotOnOrAfter"]
  @audience        = extract_audience(condition)
end

Instance Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



3
4
5
# File 'lib/samlr/condition.rb', line 3

def audience
  @audience
end

#not_beforeObject (readonly)

Returns the value of attribute not_before.



3
4
5
# File 'lib/samlr/condition.rb', line 3

def not_before
  @not_before
end

#not_on_or_afterObject (readonly)

Returns the value of attribute not_on_or_after.



3
4
5
# File 'lib/samlr/condition.rb', line 3

def not_on_or_after
  @not_on_or_after
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/samlr/condition.rb', line 3

def options
  @options
end

Instance Method Details

#audience_satisfied?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/samlr/condition.rb', line 36

def audience_satisfied?
  options[:audience].nil? ||
  audience.nil?           ||
  audience.empty?         ||
  audience.any? { |a| options[:audience] === a }
end

#not_before_satisfied?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/samlr/condition.rb', line 28

def not_before_satisfied?
  not_before.nil? || Samlr::Tools::Timestamp.not_before?(Samlr::Tools::Timestamp.parse(not_before))
end

#not_on_or_after_satisfied?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/samlr/condition.rb', line 32

def not_on_or_after_satisfied?
  not_on_or_after.nil? || Samlr::Tools::Timestamp.not_on_or_after?(Samlr::Tools::Timestamp.parse(not_on_or_after))
end

#verify!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/samlr/condition.rb', line 12

def verify!
  unless not_before_satisfied?
    raise Samlr::ConditionsError.new("Not before violation, now #{Samlr::Tools::Timestamp.stamp} vs. earliest #{not_before}")
  end

  unless not_on_or_after_satisfied?
    raise Samlr::ConditionsError.new("Not on or after violation, now #{Samlr::Tools::Timestamp.stamp} vs. at latest #{not_on_or_after}")
  end

  unless audience_satisfied?
    raise Samlr::ConditionsError.new("Audience violation, expected #{options[:audience]} vs. #{audience}")
  end

  true
end