authorization 授權
authentication 身份認證
用戶認證流程:
1.用戶使用username和password登錄
2.系統驗證這個password對於該username是正確的
3.假設第二步驗證成功,獲取該用戶的上下文信息(如他的角色列表)
4.圍繞該用戶建立安全上下文(security context)
5.用戶可能繼續進行的一些操作被一個驗證控制機制潛在的管理,這個驗證機制會根據當前用戶的安全上下文來驗證權限。
認證過程是前三步。
在Spring Security中是這樣處理這三部分的:
1.username和password被獲得后封裝到一個UsernamePasswordAuthenticationToken(Authentication接口的實例)的實例中
2.這個token被傳遞給AuthenticationManager進行驗證
3.成功認證后AuthenticationManager將返回一個得到完整填充的Authentication實例
4.通過調用SecurityContextHolder.getContext().setAuthentication(...),參數傳遞authentication對象,來建立安全上下文(security context)
僅供學習參考,侵權刪
原文地址:https://www.cnblogs.com/shiyu404/p/6530894.html