現在讓我們來探討在Web應用程序中使用Spring Security的情況(未啟用web.xml安全性)。 如何對用戶進行身份驗證并建立安全上下文?
考慮典型的Web應用程序的身份驗證過程:
1. 您訪問主頁,然后單擊鏈接。
2. 請求轉到服務器,服務器確定您已請求受保護的資源。
3. 由于您目前尚未通過身份驗證,因此服務器會發回一個響應,指示您必須進行身份驗證。響應將是HTTP響應代碼,或重定向到特定網頁。
4. 根據身份驗證機制,您的瀏覽器將重定向到特定的網頁,以便您可以填寫表單,或者瀏覽器將以某種方式檢索您的身份(通過BASIC身份驗證對話框,cookie,X.509證書等) )。
5. 瀏覽器將向服務器發回響應。這將是包含您填寫的表單內容的HTTP POST,或者包含您的身份驗證詳細信息的HTTP標頭。
6. 接下來,服務器將決定所呈現的憑證是否有效。如果它們有效,則下一步將會發生。如果它們無效,通常會要求您的瀏覽器再次嘗試(因此您將返回上面的第二步)。
7. 將重試您進行身份驗證過程的原始請求。希望您已通過足夠授權的權限進行身份驗證以訪問受保護資源。如果您有足夠的訪問權限,請求將成功。否則,您將收到HTTP錯誤代碼403,這意味著“禁止”。
Spring Security具有不同的類,負責上述大多數步驟。 主要參與者(按照它們使用的順序)是`ExceptionTranslationFilter`,`AuthenticationEntryPoint`和“認證機制”,它負責調用我們在上一節中看到的AuthenticationManager。
- 架構
- 9.技術概述
- 9.1 運行環境
- 9.2 核心組件
- 9.2.1 SecurityContextHolder, SecurityContext and Authentication Objects
- 9.2.2 The UserDetailsService
- 9.2.3 GrantedAuthority
- 9.2.4 總結
- 9.3 驗證
- 9.3.1 在Spring Security中驗證是什么
- 9.3.2 直接設置SecurityContextHolder內容
- 9.4 web應用中的驗證
- 9.4.1 ExceptionTranslationFilter
- 9.4.2 AuthenticationEntryPoint
- 9.4.3 驗證機制
- 9.4.4 在請求之間存儲SecurityContext
- 9.5 Spring Security中的訪問控制(授權)
- 9.5.1 Security and AOP Advice
- 9.5.2 Secure Objects and the AbstractSecurityInterceptor
- 什么是配置屬性
- RunAsManager
- AfterInvocationManager
- 擴展安全對象模型
- 9.6 本地化
- 10 核心服務
- 10.1 The AuthenticationManager, ProviderManager and AuthenticationProvider
- 10.1.1 成功驗證時擦除憑據
- 10.1.2 DaoAuthenticationProvider
- 10.2 UserDetailsService實現
- 10.2.1 In-Memory Authentication
- 10.2.2 JdbcDaoImpl
- Authority Groups
- 10.3 Password Encoding
- 10.3.1 密碼發展史
- 10.3.2 DelegatingPasswordEncoder
- 密碼存儲格式
- 密碼編碼
- 密碼比對
- 入門體驗
- 排除故障
- 10.3.3 BCryptPasswordEncoder
- 10.3.4 Pbkdf2PasswordEncoder
- 10.3.5 SCryptPasswordEncoder
- 10.3.6 其他PasswordEncoders
- 10.4 Jackson的支持
- 11 測試方法安全
- 12 集成spring mvc測試
- 13 webflux支持
- 14 安全過濾器鏈
- 14.1 DelegatingFilterProxy
- 14.2 FilterChainProxy
- 14.2.1 繞過過濾鏈
- 14.3 過濾器順序
- 14.4 匹配請求和http防火墻
- 14.5 與其他基于過濾器的框架一起使用
- 14.6 Advanced Namespace Configuration
- 15. 核心的安全過濾器
- 15.1 FilterSecurityInterceptor
- 15.2 ExceptionTranslationFilter
- 15.3 SecurityContextPersistenceFilter
- 15.4 UsernamePasswordAuthenticationFilter