Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 从/oauth/token筛选器链中删除OAuth2AuthenticationProcessingFilter_Spring_Oauth_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Spring 从/oauth/token筛选器链中删除OAuth2AuthenticationProcessingFilter

Spring 从/oauth/token筛选器链中删除OAuth2AuthenticationProcessingFilter,spring,oauth,spring-security,spring-security-oauth2,Spring,Oauth,Spring Security,Spring Security Oauth2,我正在尝试在我的Spring Boot应用程序中实现OAuth2。当使用密码授权调用/oauth/token时,我能够使用Basic auth使用用户名/密码对数据库进行身份验证。身份验证对象被加载到安全上下文中,筛选器继续。然而,我注意到,接下来调用了OAuth2AuthenticationProcessingFilter,并清除了安全上下文b/c未找到OAuth承载令牌。这最终导致TokenEndpoint.postAccessToken方法(例如/oauth/token)的身份验证失败 在

我正在尝试在我的Spring Boot应用程序中实现OAuth2。当使用密码授权调用
/oauth/token
时,我能够使用Basic auth使用用户名/密码对数据库进行身份验证。身份验证对象被加载到安全上下文中,筛选器继续。然而,我注意到,接下来调用了
OAuth2AuthenticationProcessingFilter
,并清除了安全上下文b/c未找到OAuth承载令牌。这最终导致
TokenEndpoint.postAccessToken
方法(例如
/oauth/token
)的身份验证失败

在调用
/oauth/token
期间,是否预期会调用
OAuth2AuthenticationProcessingFilter
?如果没有,有什么想法为什么?如果预计此问题的最佳修复/解决方法是什么,请将
OAuth2AuthenticationProcessingFilter
上的无状态设置为false?不知道这是不是个好主意

一些相关的信息,我正在使用xml配置进行spring安全设置,其余的使用JavaConfig。授权类型是
/oauth/token
调用上的密码

非常感谢您的帮助。下面是一些关于我所看到内容的日志消息

09/30/15 22:42:50.899 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.c.ClientCredentialsTokenEndpointFilter - Authentication success. Updating SecurityContextHolder to contain: org.springframework.security.oauth2.provider.OAuth2Authentication@9d98054f: Principal: testUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_USER
09/30/15 22:42:50.899 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.BearerTokenExtractor - Token not found in headers. Trying request parameters.
09/30/15 22:42:50.899 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.BearerTokenExtractor - Token not found in request parameters.  Not an OAuth2 request.
09/30/15 22:42:50.899 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter - Clearing security context.
09/30/15 22:42:50.900 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter - No token in request, will continue chain.
09/30/15 22:42:50.900 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.BearerTokenExtractor - Token not found in headers. Trying request parameters.
09/30/15 22:42:50.900 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.BearerTokenExtractor - Token not found in request parameters.  Not an OAuth2 request.
09/30/15 22:42:50.900 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter - No token in request, will continue chain.
09/30/15 22:42:50.934 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.e.FrameworkEndpointHandlerMapping - Looking up handler method for path /oauth/token
09/30/15 22:42:50.937 [http-nio-9931-exec-8] DEBUG o.s.s.o.p.e.FrameworkEndpointHandlerMapping - Returning handler method [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]
09/30/15 22:42:50.958 [http-nio-9931-exec-8] INFO  o.s.s.o.p.endpoint.TokenEndpoint - Handling error: InsufficientAuthenticationException, There is no client authentication. Try adding an appropriate authentication filter.
09/30/15 22:42:51.070 [http-nio-9931-exec-8] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
09/30/15 22:42:51.070 [http-nio-9931-exec-8] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
09/30/15 22:42:50.899[http-nio-9931-exec-8]调试o.s.s.o.p.c.ClientCredentialsTokenEndpointFilter-身份验证成功。正在更新SecurityContextHolder以包含:org.springframework.security.oauth2.provider。OAuth2Authentication@9d98054f:委托人:testUser;凭据:[受保护];认证:正确;详细信息:org.springframework.security.web.authentication。WebAuthenticationDetails@b364:RemoteIP地址:0:0:0:0:0:0:0:0:1;SessionId:null;授予的权限:角色\用户
09/30/15 22:42:50.899[http-nio-9931-exec-8]调试o.s.s.o.p.a.BealerTokenExtractor-在标头中找不到令牌。正在尝试请求参数。
09/30/15 22:42:50.899[http-nio-9931-exec-8]调试o.s.s.o.p.a.BealerTokenExtractor-在请求参数中找不到令牌。不是OAuth2请求。
09/30/15 22:42:50.899[http-nio-9931-exec-8]调试o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter-清除安全上下文。
09/30/15 22:42:50.900[http-nio-9931-exec-8]调试o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter-请求中没有令牌,将继续。
09/30/15 22:42:50.900[http-nio-9931-exec-8]调试o.s.s.o.p.a.BealerTokenExtractor-在标头中找不到令牌。正在尝试请求参数。
09/30/15 22:42:50.900[http-nio-9931-exec-8]调试o.s.s.o.p.a.BealerTokenExtractor-在请求参数中找不到令牌。不是OAuth2请求。
09/30/15 22:42:50.900[http-nio-9931-exec-8]调试o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter-请求中没有令牌,将继续。
09/30/15 22:42:50.934[http-nio-9931-exec-8]调试o.s.s.o.p.e.FrameworkEndpointHandlerMapping-查找路径/oauth/token的处理程序方法
09/30/15 22:42:50.937[http-nio-9931-exec-8]调试o.s.s.o.p.e.FrameworkEndpointHandlerMapping-返回处理程序方法[public org.springframework.http.ResponseEntity org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(java.security.Principal,java.util.Map)抛出org.springframework.web.HttpRequestMethodNotSupportedException]
09/30/15 22:42:50.958[http-nio-9931-exec-8]INFO o.s.s.o.p.endpoint.TokenEndpoint-处理错误:未充分验证异常,没有客户端验证。尝试添加适当的身份验证筛选器。
2015年9月30日22:42:51.070[http-nio-9931-exec-8]调试o.s.s.w.a.例外TranslationFilter-链正常处理
09/30/15 22:42:51.070[http-nio-9931-exec-8]调试o.s.s.w.c.SecurityContextPersistenceFilter-请求处理完成后,SecurityContextHolder现在已清除

您在这方面有什么进展吗?我们有完全相同的问题。如果你找到了一个解决方案,你能发布它吗?@bischoje我对此感到非常失望,我最终放弃了OAuth2,选择了basic auth。但是,我的基本身份验证安全配置也遇到了类似的问题。我的问题是,在我的安全配置xml中,在http部分后面的http部分中,security=“none”,下面的http部分有一个“/**”模式,这是通用匹配模式。在我的配置xml中将其更改为“/*”后,它工作得非常好。我还没有机会回去在我的OAuth2配置中尝试它。让我知道它是否有效。@bischoje这里有一个我打开的类似问题,显示了我对OAuth2的安全xml配置,我认为看到我的坏xml并结合我以前的评论可能会有帮助,以找到可能的修复方法。你在这方面有什么进展吗?我们有完全相同的问题。如果你找到了一个解决方案,你能发布它吗?@bischoje我对此感到非常失望,我最终放弃了OAuth2,选择了basic auth。但是,我的基本身份验证安全配置也遇到了类似的问题。我的问题是,在我的安全配置xml中,在http部分后面的http部分中,security=“none”,下面的http部分有一个“/**”模式,这是通用匹配模式。在我的配置xml中将其更改为“/*”后,它工作得非常好。我还没有机会回去在我的OAuth2配置中尝试它。让我知道它是否有效。@bischoje这里有一个我打开的类似问题,显示了我对OAuth2的安全xml配置,我认为看到我的坏xml并结合我以前的评论可能会有帮助,以找到可能的修复方法。