Sha256: 048fd97c99aef6c06aba9d7eef185206de9ab9b5d83aa0c0096368382574c9d7

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Saml
  module Kit
    # This class implements the Composite
    # design pattern to allow client
    # component to work with a metadata
    # that provides an IDPSSODescriptor
    # and SPSSODescriptor element.
    class CompositeMetadata < Metadata # :nodoc:
      include Enumerable

      attr_reader :service_provider, :identity_provider

      def initialize(xml)
        super('IDPSSODescriptor', xml)
        @metadatum = [
          Saml::Kit::ServiceProviderMetadata.new(xml),
          Saml::Kit::IdentityProviderMetadata.new(xml),
        ]
      end

      def organization
        find { |x| x.organization.present? }.try(:organization)
      end

      def organization_name
        organization.name
      end

      def organization_url
        organization.url
      end

      def services(type)
        xpath = map do |x|
          "//md:EntityDescriptor/md:#{x.name}/md:#{type}"
        end.join('|')
        search(xpath).map do |item|
          binding = item.attribute('Binding').value
          location = item.attribute('Location').value
          Saml::Kit::Bindings.create_for(binding, location)
        end
      end

      def certificates
        flat_map(&:certificates)
      end

      def each(&block)
        @metadatum.each(&block)
      end

      def method_missing(name, *args, **kwargs)
        if (target = find { |x| x.respond_to?(name) })
          target.public_send(name, *args, **kwargs)
        else
          super
        end
      end

      def respond_to_missing?(method, *)
        find { |x| x.respond_to?(method) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saml-kit-1.3.0 lib/saml/kit/composite_metadata.rb