【问题标题】:SpringBoot 2 with oAuth redirection issue带有 oAuth 重定向问题的 Spring Boot 2
【发布时间】:2019-09-18 10:48:26
【问题描述】:

我正在尝试通过公司内部身份验证服务器进行身份验证和身份验证。

使用 ERR_TOO_MANY_REDIRECTS 和 HTTP 302 得到以下错误

2019-09-18 09:23:54.310 TRACE 8 --- [qtp254692047-20] s.n.www.protocol.http.HttpURLConnection  : KeepAlive stream retrieved from the cache, sun.net.www.protocol.https.HttpsClient(https://privateURL/tokeninfo)
2019-09-18 09:23:54.310 TRACE 8 --- [qtp254692047-20] s.n.www.protocol.http.HttpURLConnection  : Proxy used: DIRECT
2019-09-18 09:23:54.310 DEBUG 8 --- [qtp254692047-20] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@3b6fad4e6 pairs: {GET /oauth2/tokeninfo HTTP/1.1: null}{Authorization: Bearer eyJraWQiOi####}{Accept: application/json, application/*+json}{User-Agent: Java/11.0.4}{Host: privateURL.com}{Connection: keep-alive}
2019-09-18 09:23:54.315 DEBUG 8 --- [qtp254692047-20] s.n.www.protocol.http.HttpURLConnection  : sun.net.www.MessageHeader@56d0f8f314 pairs: {null: HTTP/1.1 401 Unauthorized}{Date: Wed, 18 Sep 2019 09:23:54 GMT}{Content-Type: application/problem+json}{Transfer-Encoding: chunked}{Connection: keep-alive}{Cache-Control: no-cache, no-store, max-age=0, must-revalidate}{Expires: 0}{Pragma: no-cache}{Server: unspecified}{Strict-Transport-Security: max-age=31536000 ; includeSubDomains}{X-Content-Type-Options: nosniff}{X-Flow-Id: RiNj7zF0fq3MWJBePUzlkA}{X-Frame-Options: DENY}{X-Xss-Protection: 1; mode=block}
2019-09-18 09:23:54.316 DEBUG 8 --- [qtp254692047-20] s.n.www.protocol.http.HttpURLConnection  : Server Authentication for AuthenticationHeader: prefer null returned null
2019-09-18 09:23:54.316 DEBUG 8 --- [qtp254692047-20] org.springframework.web.HttpLogging      : Response 401 UNAUTHORIZED
2019-09-18 09:23:54.317 DEBUG 8 --- [qtp254692047-20] o.s.w.c.HttpMessageConverterExtractor    : Reading to [org.springframework.security.oauth2.common.exceptions.OAuth2Exception]
2019-09-18 09:23:54.318  WARN 8 --- [qtp254692047-20] o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class org.springframework.web.client.HttpClientErrorException$Unauthorized, 401 Unauthorized
2019-09-18 09:23:54.318 DEBUG 8 --- [qtp254692047-20] o.s.b.a.s.o.r.UserInfoTokenServices      : userinfo returned error: Could not fetch user details
...
2019-09-18 09:23:54.229 DEBUG 8 --- [qtp254692047-18] o.s.b.a.audit.listener.AuditListener     : AuditEvent [timestamp=2019-09-18T09:23:54.229553Z, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@0: RemoteIpAddress: 99.99.99.99; SessionId: xxx, type=org.springframework.security.access.AccessDeniedException, message=Access is denied}]
...
ttp_server_requests_seconds{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",quantile="0.5",} 0.011534336
http_server_requests_seconds{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",quantile="0.75",} 0.014680064
http_server_requests_seconds{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",quantile="0.95",} 0.047710208
http_server_requests_seconds{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",quantile="0.99",} 0.536346624
http_server_requests_seconds_count{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",} 14.0
http_server_requests_seconds_sum{exception="None",method="GET",outcome="REDIRECTION",status="302",uri="REDIRECTION",} 0.719216709```

Any pointers on what could be the problem here ? 

【问题讨论】:

  • 我认为是自我解释ERR_TOO_MANY_REDIRECTS
  • ERR_TOO_MANY_REDIRECTS 是症状,可能是什么原因?
  • 它写在我的回答中。

标签: spring-boot spring-oauth2


【解决方案1】:

ERR_TOO_MANY_REDIRECTS 错误发生在浏览器获取重定向请求时,启动它并因此向浏览器发送另一个重定向请求(通常完全相同)

简单来说,浏览器陷入了无限重定向循环。

最有可能的是,在您点击安全端点后,不会被重定向到允许用户进行身份验证的 UNSECURED 端点,而是重定向到另一个安全端点 - 并且循环关闭

【讨论】:

  • @AbhishekAsh UNSECURED 端点在上述上下文中类似于登录页面,不需要用户已经过身份验证。
猜你喜欢
  • 2019-11-10
  • 1970-01-01
  • 2018-12-26
  • 1970-01-01
  • 1970-01-01
  • 2017-04-24
  • 2019-02-18
  • 2023-03-13
  • 2023-03-08
相关资源
最近更新 更多