Spring Boot 2.0.0.M4 OAuth2令牌端点抛出org.springframework.web.HttpRequestMethodNotSupportedException

时间:2017-10-04 07:06:23

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

我尝试从Spring Boot 1.5.7迁移到2.0.0.M4

目前我无法在Spring Boot 2.0.0.M4上正确重新配置我的OAuth2 + JWT配置

在启动期间,我注意到日志中/oauth/token端点(throws org.springframework.web.HttpRequestMethodNotSupportedException)出现以下错误:

2017-10-04 09:52:46.841  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/authorize],methods=[POST],params=[user_oauth_approval]}" onto public org.springframework.web.servlet.View org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.approveOrDeny(java.util.Map<java.lang.String, java.lang.String>,java.util.Map<java.lang.String, ?>,org.springframework.web.bind.support.SessionStatus,java.security.Principal)
2017-10-04 09:52:46.842  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/authorize]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.authorize(java.util.Map<java.lang.String, java.lang.Object>,java.util.Map<java.lang.String, java.lang.String>,org.springframework.web.bind.support.SessionStatus,java.security.Principal)
2017-10-04 09:52:46.843  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token],methods=[GET]}" onto public org.springframework.http.ResponseEntity<org.springframework.security.oauth2.common.OAuth2AccessToken> org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.getAccessToken(java.security.Principal,java.util.Map<java.lang.String, java.lang.String>) throws org.springframework.web.HttpRequestMethodNotSupportedException
2017-10-04 09:52:46.844  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token],methods=[POST]}" onto public org.springframework.http.ResponseEntity<org.springframework.security.oauth2.common.OAuth2AccessToken> org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(java.security.Principal,java.util.Map<java.lang.String, java.lang.String>) throws org.springframework.web.HttpRequestMethodNotSupportedException
2017-10-04 09:52:46.845  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/check_token]}" onto public java.util.Map<java.lang.String, ?> org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint.checkToken(java.lang.String)
2017-10-04 09:52:46.845  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/confirm_access]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.WhitelabelApprovalEndpoint.getAccessConfirmation(java.util.Map<java.lang.String, java.lang.Object>,javax.servlet.http.HttpServletRequest) throws java.lang.Exception
2017-10-04 09:52:46.846  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/error]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.WhitelabelErrorEndpoint.handleError(javax.servlet.http.HttpServletRequest)
2017-10-04 09:52:46.848  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token_key],methods=[GET]}" onto public java.util.Map<java.lang.String, java.lang.String> org.springframework.security.oauth2.provider.endpoint.TokenKeyEndpoint.getKey(java.security.Principal)

为了重现这个问题,我创建了GitHub项目 - https://github.com/Artgit/spring-boot-2.0.0.M4-oauth2-token-issue/tree/master/api

我要发出此问题,请尝试执行com.decisionwanted.domain.api.decision.DecisionControllerIT.testCreateDecision()测试

我为代码和pom.xml中的混乱道歉。我已从多模块Maven应用程序编译此测试项目以进行测试。

请帮我修复我的配置,以便能够使用Spring Boot 2.0.0.M4

更新

调试时,我发现来自server.contextPath: /api的{​​{1}}没有考虑到。现在我需要使用application.properties(而不是/oauth/token,就像我使用Spring Boot 1.5.7)来获取令牌。这可能是什么原因以及如何解决它?

1 个答案:

答案 0 :(得分:1)

我找到了问题的原因 - 根据以下文档https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/和Spring Boot 2 *,应该使用以下属性来定义应用程序的上下文路径:

server.servlet.context-path= /api

请注意Spring Boot 1.5。*属性

server.contextPath: /api

不再考虑