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: [])

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

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

Instance Attribute Details

#audienceArray<String>

Returns Allowed audiences.

Returns:

  • (Array<String>)

    Allowed audiences


107
108
109
# File 'lib/saml2/conditions.rb', line 107

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.


122
123
124
125
126
127
128
# File 'lib/saml2/conditions.rb', line 122

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)

101
102
103
104
# File 'lib/saml2/conditions.rb', line 101

def from_xml(node)
  super
  @audience = nil
end

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

Parameters:

  • audience (String) (defaults to: nil)

112
113
114
115
116
117
118
119
# File 'lib/saml2/conditions.rb', line 112

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