spring-boot spring-security oauth2 /oauth/token报401,403 问题

2024-03-10 12:20:55.281 INFO 58776 --- [nio-8002-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-03-10 12:20:55.283 INFO 58776 --- [nio-8002-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2024-03-10 12:20:55.292 DEBUG 58776 --- [nio-8002-exec-2] o.s.security.web.FilterChainProxy : Securing POST /oauth/token
2024-03-10 12:21:00.952 DEBUG 58776 --- [nio-8002-exec-2] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2024-03-10 12:21:01.683 DEBUG 58776 --- [nio-8002-exec-2] s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
2024-03-10 12:21:01.689 ERROR 58776 --- [nio-8002-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/authorization] threw exception [Filter execution threw an exception] with root cause

java.lang.StackOverflowError: null
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.31.jar:5.3.31]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.31.jar:5.3.31]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.31.jar:5.3.31]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.31.jar:5.3.31]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.31.jar:5.3.31]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.31.jar:5.3.31]

 

问题原因:

 1.没有加 @Qualifier("ClientDetailsServiceImpl"),走到其他ClientDetailsService实现类了,一直达不到断点。

 // 管理客户端应用程序的信息和凭据

    @Autowired
// @Qualifier("ClientDetailsServiceImpl")
private ClientDetailsService clientDetailsService;

2. 没有设置密码,参数遗漏; clientDetails.setClientSecret(oauthClient.getClientSecret());

参考:https://github.com/workeritagent1/itagent1-braincells.git

 

posted @ 2024-03-10 12:37  星回中道  阅读(409)  评论(0编辑  收藏  举报