如何调试Spring Security Oath2和Jwt以了解其工作原理

时间:2019-07-08 10:45:15

标签: spring-boot spring-security-oauth2 jwt-auth

我已经在Spring Boot应用程序中成功实现了Spring Boot Oath2和Jwt。很好用现在我想知道它是如何工作的,特别是当服务器收到任何命中时它将如何处理访问令牌,但要这样做,我无法在其中放置断点的类上找到它,因为它在内部处理所有工作。 因此,要调试我的应用程序以了解其如何处理来自客户端的每个请求,需要在哪里或在哪个类中放置断点?我可以在我创建的类中放置断点,但这不是风景,因为默认情况下,Sprint Boot Oath2和Jwt在内部执行该任务,因此我需要在其中插入断点。

2 个答案:

答案 0 :(得分:1)

您应该在 spring.security.oauth2 中添加一个断点 在 org.springframework.security.oauth2.provider.endpoint.TokenEndpoint 方法 getAccessToken postAccessToken 中 并在 org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter 方法 doFilter 中 并且在 org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint 方法 checkToken

答案 1 :(得分:0)

如果要调试生成访问令牌和刷新令牌的/oauth/token,则需要根据请求方法类型在TokenEndpoint.postAccessTokenTokenEndpoint.getAccessToken方法中添加一个断点。

如果要调试验证访问令牌并对用户进行身份验证/授权的过程,则需要在OAuth2AuthenticationProcessingFilter.doFilter方法中添加一个断点,该断点负责从Authorization标头中提取访问令牌并进行身份验证/授权用户。