Class: Saml::Kit::ServiceProviderMetadata

Inherits:
Metadata
  • Object
show all
Defined in:
lib/saml/kit/service_provider_metadata.rb

Overview

This class represents a SPSSODescriptor element in a SAML metadata document.

RSpec.describe "Service Provider Metadata" do
  it 'consumes service provider_metadata' do
    raw_xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<EntityDescriptor entityID="myEntityId" xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
  <SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
    <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
  </SPSSODescriptor>
</EntityDescriptor>
    XML

     = Saml::Kit::ServiceProviderMetadata.new(raw_xml)
    expect(.entity_id).to eql('myEntityId')
    expect(.name_id_formats).to match_array([Saml::Kit::Namespaces::PERSISTENT])
  end

  it 'produces service provider metadata' do
     = Saml::Kit::Metadata.build do |builder|
      builder.contact_email = 'hi@example.com'
      builder.organization_name = "Acme, Inc"
      builder.organization_url = 'https://www.example.com'
      builder.build_service_provider do |x|
        x.add_assertion_consumer_service('https://www.example.com/consume', binding: :http_post)
        x.add_single_logout_service('https://www.example.com/logout', binding: :http_post)
      end
    end
    xml = .to_xml(pretty: true)
    expect(xml).to be_present
    expect(xml).to_not have_xpath("//md:EntityDescriptor//md:IDPSSODescriptor")
    expect(xml).to have_xpath("//md:EntityDescriptor//md:SPSSODescriptor")
  end
end

Constant Summary

Constants included from XsdValidatable

XsdValidatable::METADATA_XSD, XsdValidatable::PROTOCOL_XSD

Constants included from XmlParseable

XmlParseable::NAMESPACES

Instance Attribute Summary

Attributes inherited from Metadata

#content, #name

Instance Method Summary collapse

Methods inherited from Metadata

#certificates, #contact_person_company, #encryption_certificates, #entity_id, from, #logout_request_for, #matches?, #name_id_formats, #organization, #organization_name, #organization_url, #service_for, #services, #signature, #signing_certificates, #single_logout_service_for, #single_logout_services, #verify

Methods included from XmlParseable

#present?, #to_h, #to_s, #to_xhtml, #to_xml

Methods included from Validatable

#each_error

Constructor Details

#initialize(xml) ⇒ ServiceProviderMetadata

Returns a new instance of ServiceProviderMetadata.



10
11
12
# File 'lib/saml/kit/service_provider_metadata.rb', line 10

def initialize(xml)
  super('SPSSODescriptor', xml)
end

Instance Method Details

#assertion_consumer_service_for(binding:) ⇒ Object

Returns the AssertionConsumerService for the specified binding.

Parameters:

  • binding (Symbol)

    can be either :http_post or :http_redirect



22
23
24
# File 'lib/saml/kit/service_provider_metadata.rb', line 22

def assertion_consumer_service_for(binding:)
  service_for(binding: binding, type: 'AssertionConsumerService')
end

#assertion_consumer_servicesObject

Returns each of the AssertionConsumerService bindings.



15
16
17
# File 'lib/saml/kit/service_provider_metadata.rb', line 15

def assertion_consumer_services
  services('AssertionConsumerService')
end

#want_assertions_signedObject

Returns true when the metadata demands that Assertions must be signed.



27
28
29
30
31
32
33
# File 'lib/saml/kit/service_provider_metadata.rb', line 27

def want_assertions_signed
  element = at_xpath("/md:EntityDescriptor/md:#{name}")
  attribute = element.attribute('WantAssertionsSigned')
  return true if attribute.nil?

  attribute.text.casecmp('true').zero?
end