title: Spring Security SAML2 dynamic selection of IDPs or dynamic URLs for them
body: <p>We're trying to configure several identity providers in the application to support different types of SSO.
  The problem is that for a non-authenticated request the application doesn't know which IDP to redirect to.
  We can figure out which IDP to use based on the domain name. That's not a problem.
  The problem is to change filters the way to redirect to that specific IDP instead of the first found one.</p>
  
  <p>I wonder if there's an easy way to support it in Spring Security or its SAML2 library.</p>
  
  <p>I can either somehow modify metadata to redirect it to my own URL (and then have some custom code there) or make the authentication filter pick the right IDP based on some criteria.</p>
  
  <p>UPDATE</p>
  
  <p>Current yaml configuration:</p>
  
  <pre><code>spring:
    security:
      saml2:
        relyingparty:
          registration:
            idpone:
              identityprovider:
                entity-id: https://idpone.com
                sso-url: https://idpone.com
                verification: 
                  credentials:
                  - certificate-location: "classpath:saml/idpone.crt"
            idptwo:
              identityprovider:
                entity-id: https://idptwo.com
                sso-url: https://idptwo.com
                verification: 
                  credentials:
                  - certificate-location: "classpath:saml/idptwo.crt"
  </code></pre>