class SamlIdp::MetadataBuilder

Attributes

configurator[RW]

Public Class Methods

new(configurator = SamlIdp.config) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 11
def initialize(configurator = SamlIdp.config)
  self.configurator = configurator
end

Public Instance Methods

fresh() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 15
def fresh
  builder = Builder::XmlMarkup.new
  generated_reference_id do
    builder.EntityDescriptor ID: reference_string,
      xmlns: Saml::XML::Namespaces::METADATA,
      "xmlns:saml" => Saml::XML::Namespaces::ASSERTION,
      "xmlns:ds" => Saml::XML::Namespaces::SIGNATURE,
      entityID: entity_id do |entity|
        sign entity

        entity.IDPSSODescriptor protocolSupportEnumeration: protocol_enumeration do |descriptor|
          build_key_descriptor descriptor
          descriptor.SingleLogoutService Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
            Location: single_logout_service_post_location
          build_name_id_formats descriptor
          descriptor.SingleSignOnService Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            Location: single_service_post_location
          build_attribute descriptor
        end

        entity.AttributeAuthorityDescriptor protocolSupportEnumeration: protocol_enumeration do |authority_descriptor|
          build_key_descriptor authority_descriptor
          build_organization authority_descriptor
          build_contact authority_descriptor
          authority_descriptor.AttributeService Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
            Location: attribute_service_location
          build_name_id_formats authority_descriptor
          build_attribute authority_descriptor
        end

        build_organization entity
        build_contact entity
      end
  end
end
Also aliased as: raw
raw()
Alias for: fresh
x509_certificate() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 137
def x509_certificate
  SamlIdp.config.x509_certificate
  .to_s
  .gsub(/-----BEGIN CERTIFICATE-----/,"")
  .gsub(/-----END CERTIFICATE-----/,"")
  .gsub(/\n/, "")
end

Private Instance Methods

attributes() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 118
def attributes
  @attributes ||= configurator.attributes.inject([]) do |list, (key, opts)|
    opts[:friendly_name] = key
    list << AttributeDecorator.new(opts)
    list
  end
end
build_attribute(el) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 70
def build_attribute(el)
  attributes.each do |attribute|
    el.tag! "saml:Attribute",
      NameFormat: attribute.name_format,
      Name: attribute.name,
      FriendlyName: attribute.friendly_name do |attribute_xml|
        attribute.values.each do |value|
          attribute_xml.tag! "saml:AttributeValue", value
        end
      end
  end
end
build_contact(el) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 93
def build_contact(el)
  el.ContactPerson contactType: "technical" do |contact|
    %w[company given_name sur_name telephone mail_to_string].each do |section|
      section_value = technical_contact.public_send(section)
      contact.Company section_value if section_value.present?
    end
  end
end
build_key_descriptor(el) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 52
def build_key_descriptor(el)
  el.KeyDescriptor use: "signing" do |key_descriptor|
    key_descriptor.KeyInfo xmlns: Saml::XML::Namespaces::SIGNATURE do |key_info|
      key_info.X509Data do |x509|
        x509.X509Certificate x509_certificate
      end
    end
  end
end
build_name_id_formats(el) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 63
def build_name_id_formats(el)
  name_id_formats.each do |format|
    el.NameIDFormat format
  end
end
build_organization(el) click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 84
def build_organization(el)
  el.Organization do |organization|
    organization.OrganizationName organization_name, "xml:lang" => "en"
    organization.OrganizationDisplayName organization_name, "xml:lang" => "en"
    organization.OrganizationURL organization_url, "xml:lang" => "en"
  end
end
entity_id() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 108
def entity_id
  configurator.entity_id.presence || configurator.base_saml_location
end
name_id_formats() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 127
def name_id_formats
  @name_id_formats ||= NameIdFormatter.new(configurator.name_id.formats).all
end
protocol_enumeration() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 113
def protocol_enumeration
  Saml::XML::Namespaces::PROTOCOL
end
raw_algorithm() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 132
def raw_algorithm
  configurator.algorithm
end
reference_string() click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 103
def reference_string
  "_#{reference_id}"
end