Class: SAML2::AttributeConsumingService

Inherits:
Base
  • Object
show all
Includes:
IndexedObject
Defined in:
lib/saml2/attribute_consuming_service.rb

Instance Attribute Summary collapse

Attributes included from IndexedObject

#index

Attributes inherited from Base

#xml

Instance Method Summary collapse

Methods included from IndexedObject

#default?, #default_defined?, #eql?, included

Methods inherited from Base

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

Constructor Details

#initialize(name = nil, requested_attributes = []) ⇒ AttributeConsumingService

Returns a new instance of AttributeConsumingService.

Parameters:

  • name (String) (defaults to: nil)
  • requested_attributes (::Array<RequestedAttributes>) (defaults to: [])


99
100
101
102
103
104
# File 'lib/saml2/attribute_consuming_service.rb', line 99

def initialize(name = nil, requested_attributes = [])
  super()
  @name = LocalizedName.new("ServiceName", name)
  @description = LocalizedName.new("ServiceDescription")
  @requested_attributes = requested_attributes
end

Instance Attribute Details

#descriptionLocalizedName (readonly)

Returns:



93
94
95
# File 'lib/saml2/attribute_consuming_service.rb', line 93

def description
  @description
end

#nameLocalizedName (readonly)

Returns:



93
94
95
# File 'lib/saml2/attribute_consuming_service.rb', line 93

def name
  @name
end

#requested_attributesArray<RequestedAttribute> (readonly)



95
96
97
# File 'lib/saml2/attribute_consuming_service.rb', line 95

def requested_attributes
  @requested_attributes
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.



168
169
170
171
172
173
174
175
176
177
# File 'lib/saml2/attribute_consuming_service.rb', line 168

def build(builder)
  builder["md"].AttributeConsumingService do |attribute_consuming_service|
    name.build(attribute_consuming_service)
    description.build(attribute_consuming_service)
    requested_attributes.each do |requested_attribute|
      requested_attribute.build(attribute_consuming_service)
    end
  end
  super
end

#create_statement(attributes) ⇒ AttributeStatement

Create an SAML2::AttributeStatement from the given attributes hash.

Given a set of attributes, create and return an SAML2::AttributeStatement with only the attributes that this SAML2::AttributeConsumingService requests.

Parameters:

Returns:

Raises:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/saml2/attribute_consuming_service.rb', line 129

def create_statement(attributes)
  attributes = attributes.map { |k, v| Attribute.create(k, v) } if attributes.is_a?(Hash)

  attributes_hash = {}
  attributes.each do |attr|
    attr.value = attr.value.call if attr.value.respond_to?(:call)
    attributes_hash[[attr.name, attr.name_format]] = attr
    attributes_hash[[attr.name, nil]] = attr if attr.name_format
  end

  attributes = []
  requested_attributes.each do |requested_attr|
    attr = attributes_hash[[requested_attr.name, requested_attr.name_format]]
    attr ||= attributes_hash[[requested_attr.name, nil]] if requested_attr.name_format
    if attr
      if requested_attr.value &&
         !Array.wrap(requested_attr.value).include?(attr.value)
        raise InvalidAttributeValue.new(requested_attr, attr.value)
      end

      attributes << attr
    elsif requested_attr.required?
      # if the metadata includes only one possible value, helpfully set
      # that value
      unless requested_attr.value && !requested_attr.value.is_a?(::Array)
        raise RequiredAttributeMissing, requested_attr
      end

      attributes << Attribute.create(requested_attr.name,
                                     requested_attr.value)

    end
  end
  return nil if attributes.empty?

  AttributeStatement.new(attributes)
end

#from_xml(node) ⇒ void

This method returns an undefined value.

Parse an XML element into this object.

Parameters:

  • node (Nokogiri::XML::Element)


107
108
109
110
111
112
# File 'lib/saml2/attribute_consuming_service.rb', line 107

def from_xml(node)
  super
  name.from_xml(node.xpath("md:ServiceName", Namespaces::ALL))
  description.from_xml(node.xpath("md:ServiceDescription", Namespaces::ALL))
  @requested_attributes = load_object_array(node, "md:RequestedAttribute", RequestedAttribute)
end