2016-08-24 90 views
1

我有一個使用Spring Security的應用程序,它使用的是自定義身份驗證提供程序。我需要現在添加一個SAML IDP到混音中。因此,我啓動了SAML示例應用程序並開始運行,並使用該安全上下文作爲基礎。我已經定義是這樣,我的經理:Spring Security多重身份驗證提供程序沒有進入第二個

<security:authentication-manager alias="authenticationManager"> 
    <security:authentication-provider ref="myAuthenticationProvider" /> 
    <security:authentication-provider ref="samlAuthenticationProvider"/> 
</security:authentication-manager> 

現在,當我提出我的登錄表單使用用戶名/ passeord,這只是在SAML IDP,我可以從它調用myAuthenticationProvider,然後引發的日誌中看到BadCredentialsException,然後沒有。我沒有看到任何其他異常,也沒有看到SAMLAuthenticationProvider。

我已經閱讀了幾次文檔,它似乎表明這可以完成,但我沒有看到一個示例。有沒有人有使用SAML和BasicAuthentication的例子?

+0

什麼樣的認證支持每個這樣的提供者?他們是否支持相同的認證類型?我想你正在發送一個UsernamePasswordAuthenticationToken,不是嗎? – jlumietu

+0

是的,我是。我從代碼中看到,SAML應該失敗 - 我想。但我在日誌中看不到任何東西。我已經將SAML日誌記錄設置爲FINE,並且我可以看到它對某些東西有約束力......但是沒有錯誤。 – mmaceachran

+0

如果第一個authenticationProvider失敗並引發異常,則應該處理該異常並確保spring安全性繼續執行剩下的過濾器。此鏈接可能有所幫助:http://stackoverflow.com/questions/25794680/multiple-authentication-mechanisms-in-a-single-app-using-java-config – Bryan

回答

0

我不認爲您需要爲新的IDP添加額外的身份驗證提供程序。你只需要添加一個新的?在CachingMetadataManager Bean中。在示例應用程序提供的securityContext.xml:

<!-- IDP Metadata configuration - paths to metadata of IDPs in circle of trust is here --> 
<bean id="metadata" class="org.springframework.security.saml.metadata.CachingMetadataManager"> 
    <constructor-arg> 
     <list> 
      <!-- Example of classpath metadata with Extended Metadata --> 
      <bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate"> 
       <constructor-arg> 
        <bean class="org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider"> 
         <constructor-arg> 
          <bean class="java.util.Timer"/> 
         </constructor-arg> 
         <constructor-arg> 
          <bean class="org.opensaml.util.resource.ClasspathResource"> 
           <constructor-arg value="/metadata/idp.xml"/> 
          </bean> 
         </constructor-arg> 
         <property name="parserPool" ref="parserPool"/> 
        </bean> 
       </constructor-arg> 
       <constructor-arg> 
        <bean class="org.springframework.security.saml.metadata.ExtendedMetadata"> 
        </bean> 
       </constructor-arg> 
      </bean> 

      <!-- Example of HTTP metadata without Extended Metadata --> 
      <bean class="org.opensaml.saml2.metadata.provider.HTTPMetadataProvider"> 
       <!-- URL containing the metadata --> 
       <constructor-arg> 
        <value type="java.lang.String">http://idp.ssocircle.com/idp-meta.xml</value> 
       </constructor-arg> 
       <!-- Timeout for metadata loading in ms --> 
       <constructor-arg> 
        <value type="int">15000</value> 
       </constructor-arg> 
       <property name="parserPool" ref="parserPool"/> 
      </bean> 

      <!-- Example of file system metadata without Extended Metadata --> 
      <bean class="org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"> 
       <constructor-arg> 
        <value type="java.io.File">/usr/local/metadata/idp.xml</value> 
       </constructor-arg> 
       <property name="parserPool" ref="parserPool"/> 
      </bean> 

     </list> 
    </constructor-arg> 

</bean> 

如果取消註釋該列表中的第二個bean,它將使在/usr/local/metadata/idp.xml提供的XML文件中指定的另一IDP。如果您想通過http添加另一個IDP的元數據,只需複製ssocircle的元數據並進行調整即可。

相關問題