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 build_endpoint descriptor, [ { tag: 'SingleLogoutService', url: single_logout_service_post_location, bind: 'HTTP-POST' }, { tag: 'SingleLogoutService', url: single_logout_service_redirect_location, bind: 'HTTP-Redirect'} ] build_name_id_formats descriptor build_endpoint descriptor, [ { tag: 'SingleSignOnService', url: single_service_post_location, bind: 'HTTP-POST' }, { tag: 'SingleSignOnService', url: single_service_redirect_location, bind: 'HTTP-Redirect'} ] 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 build_endpoint authority_descriptor, [ { tag: 'AttributeService', url: attribute_service_location, bind: 'HTTP-Redirect' } ] build_name_id_formats authority_descriptor build_attribute authority_descriptor end build_organization entity build_contact entity end end end
Also aliased as: raw
x509_certificate()
click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 154 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 135 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 86 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 109 def build_contact(el) el.ContactPerson contactType: "technical" do |contact| contact.Company technical_contact.company if technical_contact.company contact.GivenName technical_contact.given_name if technical_contact.given_name contact.SurName technical_contact.sur_name if technical_contact.sur_name contact.EmailAddress technical_contact.mail_to_string if technical_contact.mail_to_string contact.TelephoneNumber technical_contact.telephone if technical_contact.telephone end end
build_endpoint(el, end_points)
click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 75 def build_endpoint(el, end_points) end_points.each do |ep| next unless ep[:url].present? el.tag! ep[:tag], Binding: "urn:oasis:names:tc:SAML:2.0:bindings:#{ep[:bind]}", Location: ep[:url] end end
build_key_descriptor(el)
click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 57 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 68 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 100 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 125 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 144 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 130 def protocol_enumeration Saml::XML::Namespaces::PROTOCOL end
raw_algorithm()
click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 149 def raw_algorithm configurator.algorithm end
reference_string()
click to toggle source
# File lib/saml_idp/metadata_builder.rb, line 120 def reference_string "_#{reference_id}" end