欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring用戶通過交互界面登錄成功的實現(xiàn)

 更新時間:2023年07月20日 10:15:45   作者:路過君_P  
本文主要介紹了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)文章

最新評論