summaryrefslogtreecommitdiff
path: root/lib/saml/kit/core_ext/metadata.rb
blob: a695cb0c321052babf6ab8a1926ba7e41dd3cde1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module Saml
  module Kit
    class Metadata
      TABLE = {
        'Entity Id' => ->(x) { x.entity_id },
        'Type' => ->(x) { x.name },
        'Valid' => ->(x) { x.valid? },
        'Name Id Formats' => ->(x) { x.name_id_formats.inspect },
        'Organization' => ->(x) { x.organization_name },
        'Url' => ->(x) { x.organization_url },
        'Contact' => ->(x) { x.contact_person_company },
      }.freeze

      SERVICES = %w[
        SingleSignOnService
        SingleLogoutService
        AssertionConsumerService
      ].freeze

      def build_table(table = [])
        TABLE.each { |key, callable| table.push([key, callable.call(self)]) }
        build_services_table(table)
        certificates.each do |certificate|
          table.push(['', certificate.x509.to_text])
        end
        signature.build_table(table)
      end

      def build_services_table(table)
        SERVICES.each do |type|
          services(type).each do |service|
            table.push([type, [service.location, service.binding]])
          end
        end
      end
    end
  end
end