I'm trying to migrate from Spring Boot 1.5.7
to 2.0.0.M4
Right now I'm unable to properly reconfigure my OAuth2 + JWT configuration on Spring Boot 2.0.0.M4
During startup, I noticed following errors for /oauth/token
endpoint (throws org.springframework.web.HttpRequestMethodNotSupportedException
) in the log:
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)
In order to reproduce this issue I hve created GitHub project - https://github.com/Artgit/spring-boot-2.0.0.M4-oauth2-token-issue/tree/master/api
I order to produce this issue please try to execute com.decisionwanted.domain.api.decision.DecisionControllerIT.testCreateDecision()
test
I apologize for the mess in the code and pom.xml. I have compiled this test project from the multimodule Maven application for test purpose.
Please help me fix my configs in order to be able work with Spring Boot 2.0.0.M4
UPDATED
While debugging, I found that server.contextPath: /api
from application.properties
is not taking into account. Right now I need to use /oauth/token
(instead of /api/oauth/token
like I use with Spring Boot 1.5.7) in order to obtain the token. What can be a reason of this and how to fix it ?
I found the reason of the issue - according to the following documentation https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ with Spring Boot 2* the following property should be used in order to define context path of the application:
server.servlet.context-path= /api
Please note that Spring Boot 1.5.* property
server.contextPath: /api
is not more taken into account
来源:https://stackoverflow.com/questions/46558921/spring-boot-2-0-0-m4-oauth2-token-endpoint-throws-org-springframework-web-httpre