spring用戶通過交互界面登錄成功的實(shí)現(xiàn)
版本
spring-security-web:5.6.7
源碼
用戶通過前端交互界面登錄成功觸發(fā)此事件
org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent
事件觸發(fā)過程
用戶名密碼認(rèn)證過濾器
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
public class UsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter
認(rèn)證處理過濾器
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 { // 嘗試對(duì)請(qǐng)求進(jìn)行認(rèn)證 Authentication authenticationResult = attemptAuthentication(request, response); if (authenticationResult == null) { return; } this.sessionStrategy.onAuthentication(authenticationResult, request, response); // 認(rèn)證成功 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); } } // 默認(rèn)的認(rèn)證成功處理行為 // 1. 將認(rèn)證對(duì)象設(shè)置到安全上下文 // 2. 通知RememberMe服務(wù) // 3. 發(fā)布交互認(rèn)證成功事件 // 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用戶通過交互界面登錄成功的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)spring 交互界面登錄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
IntelliJ IDEA 2019.2 x64的安裝、應(yīng)用與簡(jiǎn)單配置(圖文)
這篇文章主要介紹了IntelliJ IDEA 2019.2 x64的安裝、應(yīng)用與簡(jiǎn)單配置,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10Spring的實(shí)例工廠方法和靜態(tài)工廠方法實(shí)例代碼
這篇文章主要介紹了Spring的實(shí)例工廠方法和靜態(tài)工廠方法實(shí)例代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01快速學(xué)習(xí)JavaWeb中監(jiān)聽器(Listener)的使用方法
這篇文章主要幫助大家快速學(xué)習(xí)JavaWeb中監(jiān)聽器(Listener)的使用方法,感興趣的小伙伴們可以參考一下2016-09-09idea創(chuàng)建maven父子工程導(dǎo)致子工程無法導(dǎo)入父工程依賴
創(chuàng)建maven父子工程時(shí)遇到一個(gè)問題,本文主要介紹了idea創(chuàng)建maven父子工程導(dǎo)致子工程無法導(dǎo)入父工程依賴,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04java 較大數(shù)據(jù)量取差集,list.removeAll性能優(yōu)化詳解
這篇文章主要介紹了java 較大數(shù)據(jù)量取差集,list.removeAll性能優(yōu)化詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09Java適配器模式的實(shí)現(xiàn)及應(yīng)用場(chǎng)景
適配器模式是Java中一種常用的設(shè)計(jì)模式,它通過將一個(gè)類的接口轉(zhuǎn)換成客戶端所期望的另一種接口來實(shí)現(xiàn)不同接口之間的兼容性。適配器模式主要應(yīng)用于系統(tǒng)的接口不兼容、需要擴(kuò)展接口功能以及需要適應(yīng)不同環(huán)境的場(chǎng)景2023-04-04劍指Offer之Java算法習(xí)題精講鏈表專項(xiàng)訓(xùn)練
跟著思路走,之后從簡(jiǎn)單題入手,反復(fù)去看,做過之后可能會(huì)忘記,之后再做一次,記不住就反復(fù)做,反復(fù)尋求思路和規(guī)律,慢慢積累就會(huì)發(fā)現(xiàn)質(zhì)的變化2022-03-03springboot使用線程池(ThreadPoolTaskExecutor)示例
大家好,本篇文章主要講的是springboot使用線程池(ThreadPoolTaskExecutor)示例,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12