class SAML2::Conditions
Attributes
not_before[RW]
@return [Time, nil]
not_on_or_after[RW]
@return [Time, nil]
xml[R]
(see Base#xml
)
Public Class Methods
from_xml(node)
click to toggle source
(see Base.from_xml
)
# File lib/saml2/conditions.rb, line 13 def self.from_xml(node) return nil unless node result = new result.from_xml(node) result end
Public Instance Methods
build(builder)
click to toggle source
(see Base#build
)
# File lib/saml2/conditions.rb, line 70 def build(builder) builder["saml"].Conditions do |conditions| conditions.parent["NotBefore"] = not_before.iso8601 if not_before conditions.parent["NotOnOrAfter"] = not_on_or_after.iso8601 if not_on_or_after each do |condition| condition.build(conditions) end end end
from_xml(node)
click to toggle source
(see Base#from_xml
)
# File lib/saml2/conditions.rb, line 22 def from_xml(node) @xml = node @not_before = Time.parse(node["NotBefore"]) if node["NotBefore"] @not_on_or_after = Time.parse(node["NotOnOrAfter"]) if node["NotOnOrAfter"] replace(node.element_children.map do |restriction| klass = if self.class.const_defined?(restriction.name, false) self.class.const_get(restriction.name, false) else Condition end klass.from_xml(restriction) end) end
valid?(now: Time.now.utc, **options)
click to toggle source
Use validate instead. @deprecated
# File lib/saml2/conditions.rb, line 65 def valid?(now: Time.now.utc, **options) validate(verification_time: now, **options).empty? end
validate(verification_time: Time.now.utc, **options)
click to toggle source
Evaluate these conditions.
@param verification_time optional [Time] @param options
Additional options to pass to specific {Condition}s
@return [Array<>]
It's only valid if every sub-condition is completely valid. If any sub-condition is invalid, the whole statement is invalid. If the validity can't be determined due to an unsupported condition, +nil+ will be returned (which is false-ish)
# File lib/saml2/conditions.rb, line 47 def validate(verification_time: Time.now.utc, **options) options[:verification_time] ||= verification_time errors = [] if not_before && verification_time < not_before errors << "not_before #{not_before} is later than now (#{verification_time})" end if not_on_or_after && verification_time >= not_on_or_after errors << "not_on_or_after #{not_on_or_after} is earlier than now (#{verification_time})" end each do |condition| errors.concat(condition.validate(**options)) end errors end