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

Instance Method Summary collapse

Methods included from IndexedObject

#build, #default?, #eql?

Methods inherited from Base

from_xml, load_object_array, load_string_array, #to_s, #to_xml

Constructor Details

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

Returns a new instance of AttributeConsumingService.



36
37
38
# File 'lib/saml2/attribute_consuming_service.rb', line 36

def initialize(name = nil, requested_attributes = [])
  @name, @requested_attributes = name, requested_attributes
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/saml2/attribute_consuming_service.rb', line 34

def name
  @name
end

#requested_attributesObject (readonly)

Returns the value of attribute requested_attributes.



34
35
36
# File 'lib/saml2/attribute_consuming_service.rb', line 34

def requested_attributes
  @requested_attributes
end

Instance Method Details

#create_statement(attributes) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/saml2/attribute_consuming_service.rb', line 46

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

  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
    if attr.name_format
      attributes_hash[[attr.name, nil]] = attr
    end
  end

  attributes = []
  requested_attributes.each do |requested_attr|
    attr = attributes_hash[[requested_attr.name, requested_attr.name_format]]
    if requested_attr.name_format
      attr ||= attributes_hash[[requested_attr.name, nil]]
    end
    if attr
      attributes << attr
    elsif requested_attr.required?
      raise RequiredAttributeMissing.new(requested_attr)
    end
  end
  return nil if attributes.empty?
  AttributeStatement.new(attributes)
end

#from_xml(node) ⇒ Object



40
41
42
43
44
# File 'lib/saml2/attribute_consuming_service.rb', line 40

def from_xml(node)
  @name = node['ServiceName']
  @requested_attributes = load_object_array(node, "md:RequestedAttribute", RequestedAttribute)
  super
end