spring用戶通過交互界面登錄成功的實現(xiàn)
版本
spring-security-web:5.6.7
源碼
用戶通過前端交互界面登錄成功觸發(fā)此事件
org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent
事件觸發(fā)過程
用戶名密碼認證過濾器
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
public class UsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter
認證處理過濾器
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { if (!requiresAuthentication(request, response)) { chain.doFilter(request, response); return; } try { // 嘗試對請求進行認證 Authentication authenticationResult = attemptAuthentication(request, response); if (authenticationResult == null) { return; } this.sessionStrategy.onAuthentication(authenticationResult, request, response); // 認證成功 if (this.continueChainBeforeSuccessfulAuthentication) { chain.doFilter(request, response); } successfulAuthentication(request, response, chain, authenticationResult); } catch (InternalAuthenticationServiceException failed) { this.logger.error("An internal error occurred while trying to authenticate the user.", failed); unsuccessfulAuthentication(request, response, failed); } catch (AuthenticationException ex) { // Authentication failed unsuccessfulAuthentication(request, response, ex); } } // 默認的認證成功處理行為 // 1. 將認證對象設(shè)置到安全上下文 // 2. 通知RememberMe服務(wù) // 3. 發(fā)布交互認證成功事件 // 4. 執(zhí)行成功處理器 protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(authResult); SecurityContextHolder.setContext(context); if (this.logger.isDebugEnabled()) { this.logger.debug(LogMessage.format("Set SecurityContextHolder to %s", authResult)); } this.rememberMeServices.loginSuccess(request, response, authResult); if (this.eventPublisher != null) { this.eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass())); } this.successHandler.onAuthenticationSuccess(request, response, authResult); }
到此這篇關(guān)于spring用戶通過交互界面登錄成功的實現(xiàn)的文章就介紹到這了,更多相關(guān)spring 交互界面登錄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
IntelliJ IDEA 2019.2 x64的安裝、應(yīng)用與簡單配置(圖文)
這篇文章主要介紹了IntelliJ IDEA 2019.2 x64的安裝、應(yīng)用與簡單配置,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10快速學習JavaWeb中監(jiān)聽器(Listener)的使用方法
這篇文章主要幫助大家快速學習JavaWeb中監(jiān)聽器(Listener)的使用方法,感興趣的小伙伴們可以參考一下2016-09-09idea創(chuàng)建maven父子工程導致子工程無法導入父工程依賴
創(chuàng)建maven父子工程時遇到一個問題,本文主要介紹了idea創(chuàng)建maven父子工程導致子工程無法導入父工程依賴,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-04-04java 較大數(shù)據(jù)量取差集,list.removeAll性能優(yōu)化詳解
這篇文章主要介紹了java 較大數(shù)據(jù)量取差集,list.removeAll性能優(yōu)化詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09springboot使用線程池(ThreadPoolTaskExecutor)示例
大家好,本篇文章主要講的是springboot使用線程池(ThreadPoolTaskExecutor)示例,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12