Class: SAML2::Conditions::AudienceRestriction

Inherits:
Condition show all
Defined in:
lib/saml2/conditions.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#xml

Instance Method Summary collapse

Methods inherited from Condition

#valid?

Methods inherited from Base

#decrypt, from_xml, #inspect, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

#initialize(audience = []) ⇒ AudienceRestriction

Returns a new instance of AudienceRestriction.

Parameters:

  • audience (Array<String>) (defaults to: [])


97
98
99
100
# File 'lib/saml2/conditions.rb', line 97

def initialize(audience = [])
  super()
  @audience = audience
end

Instance Attribute Details

#audienceArray<String>

Returns Allowed audiences.

Returns:

  • (Array<String>)

    Allowed audiences



109
110
111
# File 'lib/saml2/conditions.rb', line 109

def audience
  @audience ||= load_string_array(xml, "saml:Audience")
end

Instance Method Details

#build(builder) ⇒ void

This method returns an undefined value.

Serialize this object to XML, as part of a larger document

Parameters:

  • builder (Nokogiri::XML::Builder)

    The builder helper object to serialize to.



125
126
127
128
129
130
131
# File 'lib/saml2/conditions.rb', line 125

def build(builder)
  builder["saml"].AudienceRestriction do |audience_restriction|
    Array.wrap(audience).each do |single_audience|
      audience_restriction["saml"].Audience(single_audience)
    end
  end
end

#from_xml(node) ⇒ void

This method returns an undefined value.

Parse an XML element into this object.

Parameters:

  • node (Nokogiri::XML::Element)


103
104
105
106
# File 'lib/saml2/conditions.rb', line 103

def from_xml(node)
  super
  @audience = nil
end

#validate(audience: nil, ignore_audience_condition: false, **_) ⇒ Object

Parameters:

  • audience (String) (defaults to: nil)


114
115
116
117
118
119
120
121
122
# File 'lib/saml2/conditions.rb', line 114

def validate(audience: nil, ignore_audience_condition: false, **_)
  return [] if ignore_audience_condition

  unless Array.wrap(self.audience).include?(audience)
    return ["audience #{audience} not in allowed list of #{Array.wrap(self.audience).join(", ")}"]
  end

  []
end