title: Configuring multiple metadata.xml with its own entityid in SAML
body: <p>We have a requirement of having multiple metadata.xml and its entity to enable SSO as we have multiple country sites running from a same instance and same code base.</p>
  
  <p>What we did so far</p>
  
  <blockquote>
    <p>Customised the metadatageneratorfilter to set proper entity based on the request url (we have country code coming in the domain of url).</p>
  </blockquote>
  
  <p>In Spring XML,</p>
  
  <pre><code>     &lt;pre&gt;
  [bean id="metadata"  class="org.springframework.security.saml.metadata.CachingMetadataManager"&gt;
          [constructor-arg&gt;
              [list&gt;
              [bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate"&gt;
                       [constructor-arg&gt;
                  [bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"&gt;
  
                      [constructor-arg&gt;
                          [value type="java.io.File"&gt;${sso.metadata.location:classpath:security/metadata_se.xml}[/value&gt;
                      [/constructor-arg&gt;
                      [property name="parserPool" ref="parserPool"/&gt;
                  [/bean&gt;
                  [/constructor-arg&gt;
                   [!-- added section starts --&gt;
                      [constructor-arg&gt;
                          [bean class="org.springframework.security.saml.metadata.ExtendedMetadata"&gt;
                                  [property name="signingKey" value="ssoIDPCertr"/&gt;
                          [/bean&gt;
                      [/constructor-arg&gt;
                      [!-- added section ends--&gt;
                   [/bean&gt;
                   [bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate"&gt;
                       [constructor-arg&gt;
                  [bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"&gt;
  
                      [constructor-arg&gt;
                          [value type="java.io.File"&gt;${sso.metadata.location:classpath:security/metadata_es.xml}[/value&gt;
                      [/constructor-arg&gt;
                      [property name="parserPool" ref="parserPool"/&gt;
                  [/bean&gt;
                  [/constructor-arg&gt;
                   [!-- added section starts --&gt;
                      [constructor-arg&gt;
                          [bean class="org.springframework.security.saml.metadata.ExtendedMetadata"&gt;
                                  [property name="signingKey" value="ssoIDPCertr"/&gt;
                          [/bean&gt;
                      [/constructor-arg&gt;
                      [!-- added section ends--&gt;
                   [/bean&gt;
                   [bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate"&gt;
                       [constructor-arg&gt;
                  [bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"&gt;
  
                      [constructor-arg&gt;
                          [value type="java.io.File"&gt;${sso.metadata.location:classpath:security/metadata_de.xml}[/value&gt;
                      [/constructor-arg&gt;
                      [property name="parserPool" ref="parserPool"/&gt;
                  [/bean&gt;
                  [/constructor-arg&gt;
                   [!-- added section starts --&gt;
                      [constructor-arg&gt;
                          [bean class="org.springframework.security.saml.metadata.ExtendedMetadata"&gt;
                                  [property name="signingKey" value="ssoIDPCertr"/&gt;
                          [/bean&gt;
                      [/constructor-arg&gt;
                      [!-- added section ends--&gt;
                   [/bean&gt;
              [/list&gt;
          [/constructor-arg&gt;
      [/bean&gt;
  
  &lt;/pre&gt;
  
  
  But this approach is not working as we dont have set providers against any unique values to identify the proper providers for countries.
  
  our urls will be like 
  &lt;pre&gt;
  https://xy.brand.com
  
  https://yy.brand.com
  &lt;/pre&gt;
  </code></pre>
  
  <p>Each site has separate metadata.xml.</p>
  
  <p>we need to store metadata.xml with countryCode as identifiers and retrieve it based on request url before forming SAML request &amp; response.</p>
  
  <p>Any help will be much appreciated.</p>
  
  <p>Thanks,
  Siva</p>