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, lookup_qname, #to_s, #to_xml

Constructor Details

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

Returns a new instance of AttributeConsumingService.



49
50
51
52
# File 'lib/saml2/attribute_consuming_service.rb', line 49

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



47
48
49
# File 'lib/saml2/attribute_consuming_service.rb', line 47

def name
  @name
end

#requested_attributesObject (readonly)

Returns the value of attribute requested_attributes.



47
48
49
# File 'lib/saml2/attribute_consuming_service.rb', line 47

def requested_attributes
  @requested_attributes
end

Instance Method Details

#create_statement(attributes) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/saml2/attribute_consuming_service.rb', line 59

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
      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
      if requested_attr.value && !requested_attr.value.is_a?(::Array)
        attributes << Attribute.create(requested_attr.name,
                                       requested_attr.value)
      else
        raise RequiredAttributeMissing.new(requested_attr)
      end
    end
  end
  return nil if attributes.empty?
  AttributeStatement.new(attributes)
end

#from_xml(node) ⇒ Object



54
55
56
57
# File 'lib/saml2/attribute_consuming_service.rb', line 54

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