非常感谢 @
luomao 老哥提供的思路,按照老哥的思路,要重写 OAuth2AuthenticationProcessingFilter 过滤器其中获取 Authentication 这部分逻辑就可以了,
```java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
ServletException {
final boolean debug = logger.isDebugEnabled();
final HttpServletRequest request = (HttpServletRequest) req;
final HttpServletResponse response = (HttpServletResponse) res;
try {
//重写这里,改成业务模块获取 Authentication 的逻辑,用 token 的话就是要重写 org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor#extract 方法了
Authentication authentication = tokenExtractor.extract(request);
if (authentication == null) {
if (stateless && isAuthenticated()) {
if (debug) {
logger.debug("Clearing security context.");
}
SecurityContextHolder.clearContext();
}
if (debug) {
logger.debug("No token in request, will continue chain.");
}
}
……
```
我准备按照这个思路实践以下,java 小伙伴如果有类似问题可以做个参考,此贴终结了吧。