main
 1# frozen_string_literal: true
 2
 3module Saml
 4  module Kit
 5    module Builders
 6      # {include:file:lib/saml/kit/builders/templates/metadata.builder}
 7      # {include:file:spec/saml/kit/builders/metadata_spec.rb}
 8      class Metadata
 9        include XmlTemplatable
10
11        attr_accessor :entity_id
12        attr_accessor :id
13        attr_accessor :identity_provider
14        attr_accessor :organization_name, :organization_url, :contact_email
15        attr_accessor :service_provider
16        attr_reader :configuration
17
18        def initialize(configuration: Saml::Kit.configuration)
19          @id = ::Xml::Kit::Id.generate
20          @entity_id = configuration.entity_id
21          @configuration = configuration
22        end
23
24        def build_service_provider
25          @service_provider = Saml::Kit::ServiceProviderMetadata.builder(
26            configuration: configuration
27          ) do |x|
28            yield x if block_given?
29          end
30        end
31
32        def build_identity_provider
33          @identity_provider = Saml::Kit::IdentityProviderMetadata.builder(
34            configuration: configuration
35          ) do |x|
36            yield x if block_given?
37          end
38        end
39
40        def build
41          Saml::Kit::Metadata.from(to_xml)
42        end
43
44        private
45
46        def entity_descriptor_options
47          {
48            'xmlns': Namespaces::METADATA,
49            'xmlns:ds': ::Xml::Kit::Namespaces::XMLDSIG,
50            'xmlns:saml': Namespaces::ASSERTION,
51            ID: id,
52            entityID: entity_id,
53          }
54        end
55      end
56    end
57  end
58end