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

2020-09-01 11:00:41 +08:00
 ffLoveJava

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);
    }
1805 次点击
所在节点    问与答
2 条回复
ffLoveJava
2020-09-01 13:38:10 +08:00
jiushizhe
ffLoveJava
2020-09-01 13:54:51 +08:00
也可参见 : https://github.com/spring-projects/spring-security/issues/6115

大致是一个意思

求解

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/703054

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX