class SAML2::AttributeConsumingService
Attributes
description[R]
@return [LocalizedName]
name[R]
@return [LocalizedName]
requested_attributes[R]
@return [Array<RequestedAttribute>]
Public Class Methods
new(name = nil, requested_attributes = [])
click to toggle source
@param name [String] @param requested_attributes
[::Array<RequestedAttributes>]
Calls superclass method
SAML2::IndexedObject::new
# 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
Public Instance Methods
build(builder)
click to toggle source
(see Base#build
)
Calls superclass method
SAML2::IndexedObject#build
# 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)
click to toggle source
Create an {AttributeStatement} from the given attributes hash.
Given a set of attributes, create and return an {AttributeStatement} with only the attributes that this {AttributeConsumingService} requests.
@param attributes [Hash<String => Object>, Array<Attribute>]
If it's a hash, the elements are run through {Attribute.create} first in order to create proper {Attribute} objects.
@return [AttributeStatement] @raise [InvalidAttributeValue]
If a {RequestedAttribute} specifies that only specific values are permissible, and the provided attribute does not match that value.
@raise [RequiredAttributeMissing]
If a {RequestedAttribute} is tagged as required, but it has not been supplied.
# 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)
click to toggle source
(see Base#from_xml
)
Calls superclass method
SAML2::IndexedObject#from_xml
# 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