Commit 216d5a0
Changed files (2)
lib
saml
spec
lib/saml/kit/service_provider_metadata.rb
@@ -10,11 +10,16 @@ module Saml
end
class Builder
- attr_accessor :id, :entity_id, :acs_url
+ attr_accessor :id, :entity_id, :acs_urls
def initialize(configuration = Saml::Kit.configuration)
@id = SecureRandom.uuid
@configuration = configuration
+ @acs_urls = []
+ end
+
+ def add_acs_url(url, binding: :post)
+ @acs_urls.push(location: url, binding: binding_namespace_for(binding))
end
def to_xml
@@ -25,7 +30,14 @@ module Saml
signature.template(xml)
xml.tag! "md:SPSSODescriptor", descriptor_options do
xml.tag! "md:NameIDFormat", Namespaces::Formats::NameId::PERSISTENT
- xml.tag! "md:AssertionConsumerService", Binding: Namespaces::Bindings::POST, Location: acs_url, index: "0", isDefault: "true"
+ acs_urls.each_with_index do |item, index|
+ xml.tag! "md:AssertionConsumerService", {
+ Binding: item[:binding],
+ Location: item[:location],
+ index: index,
+ isDefault: index == 0 ? true : false,
+ }
+ end
xml.tag! "md:KeyDescriptor", use: "signing" do
xml.tag! "ds:KeyInfo", "xmlns:ds": Saml::Kit::Signature::XMLDSIG do
xml.tag! "ds:X509Data" do
@@ -59,6 +71,14 @@ module Saml
protocolSupportEnumeration: Namespaces::PROTOCOL,
}
end
+
+ def binding_namespace_for(binding)
+ if :post == binding
+ Namespaces::Bindings::POST
+ else
+ Namespaces::Bindings::HTTP_REDIRECT
+ end
+ end
end
end
end
spec/saml/service_provider_metadata_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata do
XML
it 'builds the service provider metadata' do
subject.entity_id = entity_id
- subject.acs_url = acs_url
+ subject.add_acs_url(acs_url, binding: :post)
result = Hash.from_xml(subject.build.to_xml)
expect(result['EntityDescriptor']['xmlns:md']).to eql("urn:oasis:names:tc:SAML:2.0:metadata")