Class: SAML2::AttributeConsumingService
- Includes:
- IndexedObject
- Defined in:
- lib/saml2/attribute_consuming_service.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#requested_attributes ⇒ Object
readonly
Returns the value of attribute requested_attributes.
Attributes included from IndexedObject
Attributes inherited from Base
Instance Method Summary collapse
- #build(builder) ⇒ Object
- #create_statement(attributes) ⇒ Object
- #from_xml(node) ⇒ Object
-
#initialize(name = nil, requested_attributes = []) ⇒ AttributeConsumingService
constructor
A new instance of AttributeConsumingService.
Methods included from IndexedObject
#default?, #default_defined?, #eql?
Methods inherited from Base
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.
67 68 69 70 71 72 |
# File 'lib/saml2/attribute_consuming_service.rb', line 67 def initialize(name = nil, requested_attributes = []) super() @name = LocalizedName.new('ServiceName', name) @description = LocalizedName.new('ServiceDescription') @requested_attributes = requested_attributes end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
65 66 67 |
# File 'lib/saml2/attribute_consuming_service.rb', line 65 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
65 66 67 |
# File 'lib/saml2/attribute_consuming_service.rb', line 65 def name @name end |
#requested_attributes ⇒ Object (readonly)
Returns the value of attribute requested_attributes.
65 66 67 |
# File 'lib/saml2/attribute_consuming_service.rb', line 65 def requested_attributes @requested_attributes end |
Instance Method Details
#build(builder) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/saml2/attribute_consuming_service.rb', line 122 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) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/saml2/attribute_consuming_service.rb', line 81 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
74 75 76 77 78 79 |
# File 'lib/saml2/attribute_consuming_service.rb', line 74 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 |