ffLoveJava
V2EX  ›  问与答

spring oauth2 的 clientId 和 secret 验证为什么封装成 UsernamePasswordAuthenticationToken?

  •  
  •   ffLoveJava · Sep 1, 2020 · 2285 views
    This topic created in 2101 days ago, the information mentioned may be changed or developed.

    spring cloud oauth2 走 /oauth2/token 接口获取 token 时

    首先验证 clientId 和 clientSecret 这时候进入 BasicAuthenticationFilter.doFilterInternal 中把 request 中的 clientId 和 clientSecret 封装成 UsernamePasswordAuthenticationToken,

    然后再验证 用户名密码, 用户名密码也封装成 UsernamePasswordAuthenticationToken 。

    这也太诡异了啊,获取 token 成功后会触发 AuthenticationSuccessEvent, 但是一次请求会触发两次事件,一次是 clientAuthentication, 一次是 userAuthentication , 他们的 authenticationSuccessEvent.getSource() 都是 instance of UsernamePasswordAuthenticationToken

    请问为什么啊

    --- ---- client 验证 的代码

    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)  {    
                UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request);
                if (authRequest == null) {
                    chain.doFilter(request, response);
                    return;
                }
            chain.doFilter(request, response);
        }
    
    ffLoveJava
        1
    ffLoveJava  
    OP
       Sep 1, 2020
    jiushizhe
    ffLoveJava
        2
    ffLoveJava  
    OP
       Sep 1, 2020
    也可参见 : https://github.com/spring-projects/spring-security/issues/6115

    大致是一个意思

    求解
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3374 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:30 · PVG 19:30 · LAX 04:30 · JFK 07:30
    ♥ Do have faith in what you're doing.