main
1# frozen_string_literal: true
2
3module Saml
4 module Kit
5 # This class implements the Composite
6 # design pattern to allow client
7 # component to work with a metadata
8 # that provides an IDPSSODescriptor
9 # and SPSSODescriptor element.
10 class CompositeMetadata < Metadata # :nodoc:
11 include Enumerable
12
13 attr_reader :service_provider, :identity_provider
14
15 def initialize(xml)
16 super('IDPSSODescriptor', xml)
17 @metadatum = [
18 Saml::Kit::ServiceProviderMetadata.new(xml),
19 Saml::Kit::IdentityProviderMetadata.new(xml),
20 ]
21 end
22
23 def organization
24 find { |x| x.organization.present? }.try(:organization)
25 end
26
27 def organization_name
28 organization.name
29 end
30
31 def organization_url
32 organization.url
33 end
34
35 def services(type)
36 xpath = map do |x|
37 "//md:EntityDescriptor/md:#{x.name}/md:#{type}"
38 end.join('|')
39 search(xpath).map do |item|
40 binding = item.attribute('Binding').value
41 location = item.attribute('Location').value
42 Saml::Kit::Bindings.create_for(binding, location)
43 end
44 end
45
46 def certificates
47 flat_map(&:certificates)
48 end
49
50 def each(&block)
51 @metadatum.each(&block)
52 end
53
54 def method_missing(name, *args, **kwargs)
55 if (target = find { |x| x.respond_to?(name) })
56 target.public_send(name, *args, **kwargs)
57 else
58 super
59 end
60 end
61
62 def respond_to_missing?(method, *)
63 find { |x| x.respond_to?(method) }
64 end
65 end
66 end
67end