V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ffLoveJava
V2EX  ›  问与答

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

  •  
  •   ffLoveJava · 2020-09-01 11:00:41 +08:00 · 1772 次点击
    这是一个创建于 1305 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
       2020-09-01 13:38:10 +08:00
    jiushizhe
    ffLoveJava
        2
    ffLoveJava  
    OP
       2020-09-01 13:54:51 +08:00
    也可参见 : https://github.com/spring-projects/spring-security/issues/6115

    大致是一个意思

    求解
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5265 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:23 · PVG 17:23 · LAX 02:23 · JFK 05:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.