title: Tag authentication-manager with optional provider bean
body: <p>I have two spring profiles that are independent from each other, like below:</p>
  
  <pre><code>&lt;beans profile="prof1"&gt;
      &lt;security:authentication-manager id="authenticationManager" erase-credentials="true"&gt;
          &lt;security:authentication-provider ref="1" /&gt;
          &lt;security:authentication-provider ref="2" /&gt;
          &lt;security:authentication-provider ref="3" /&gt;
      &lt;/security:authentication-manager&gt;
  &lt;/beans&gt;
  
  &lt;beans profile="prof2" &gt;
      &lt;security:authentication-manager id="authenticationManager" erase-credentials="true"&gt;
          &lt;security:authentication-provider ref="0" /&gt;
          &lt;security:authentication-provider ref="1" /&gt;
          &lt;security:authentication-provider ref="2" /&gt;
          &lt;security:authentication-provider ref="3" /&gt;
      &lt;/security:authentication-manager&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>For instance, I can enable profile in the following way:</p>
  
  <pre><code>|prof1|prof2|
  |true |true |
  |true |false|
  |false|true |
  |false|false|
  </code></pre>
  
  <p>When the last option is specified spring complain that <strong>authentication-manager</strong> is missed.</p>
  
  <p>In order to fix this I looked for something like <strong>"optional reference to spring bean"</strong>.</p>
  
  <p>Namely the idea was to extract manager from the profile like below:</p>
  
  <pre><code> &lt;security:authentication-manager id="authenticationManager" erase-credentials="true"&gt;
              &lt;security:authentication-provider ref="0-optional-reference" /&gt;
              &lt;security:authentication-provider ref="1" /&gt;
              &lt;security:authentication-provider ref="2" /&gt;
              &lt;security:authentication-provider ref="3" /&gt;
          &lt;/security:authentication-manager&gt;
  </code></pre>
  
  <p>Then make bean with name "0" as optional bean. I've found the following post <a href="https://stackoverflow.com/questions/3957430/optional-spring-bean-references">Optional Spring bean references</a> but it looks like any options does not work for me because I cannot replace "ref" attribute with "value" because of spring xsd.</p>
  
  <p>It would be good to know any options how can I specify optional bean for <strong>authentication-provider</strong> spring tag.</p>