[英]can I implement both SAML and basic spring security within an application?
[英]In spring security how to implement both SAML and custom authentication handler
我正在實現三種類型的身份驗證機制,它們是 SAML 和兩種自定義身份驗證。 那么,如何實現基於 header 的過濾器,它將檢測身份驗證類型並將路由到適當的身份驗證機制。
SAML
:在 SAML 的情況下,如果 cookie 的密鑰為saml
,則必須進行 SAML 身份驗證。 在 SAML 身份驗證中,每當用戶登錄時,我都會在瀏覽器中插入一個名為 saml 的 cookie,對於進一步的請求,我需要通過傳遞saml
cookie 值來調用 REST API 並檢查身份驗證是否有效。
Custom authentication
:如果 cookie 密鑰具有token1
或token2
,則執行自定義身份驗證,其中涉及調用 Rest API 通過傳遞令牌並檢查用戶是否有效。
我知道具有 spring 安全性的 SAML,但正如我在 SAML 中解釋的那樣,我們如何執行 rest API 調用並實現調用適當身份驗證機制的過濾器。 是否有任何參考可以幫助解決上述情況。
您可以使用 Spring Security AuthenticationManagerBuilder來完成。 使用在別處定義的三個自動連接的身份驗證提供程序創建安全配置
@Autowired
private CustomAuthenticationProvider1 customProvider1;
@Autowired
private CustomAuthenticationProvider2 customProvider2;
@Autowired
private SAMLAuthenticationProvider samlProvider;
然后使用 AuthenticationManagerBuilder 只需添加它們
authenticationManagerBuilder.authenticationProvider(customProvider1);
authenticationManagerBuilder.authenticationProvider(customProvider2);
authenticationManagerBuilder.authenticationProvider(samlProvider);
對於一個完整的例子,你可以看到這篇文章
我假設您使用 Azure 進行 SAML 身份驗證。 按照這種方式實現自定義和saml認證。
username
和password
進行身份驗證。RestTemplate
此令牌。 如果令牌有效,則創建正常的 spring jwt 令牌。現在實際上您正在為所有身份驗證維護單個令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.