use*_*906 7 spring spring-security spring-boot
所以我需要支持多租户并已在此处阅读相关内容。
我已按照以下步骤添加:身份验证管理器(假 uri):
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver
("https://jwt.com/token.json");
Run Code Online (Sandbox Code Playgroud)
使用新的 oauth2ResourceServer:
.oauth2ResourceServer(oauth2 -> oauth2.
authenticationManagerResolver(authenticationManagerResolver));
Run Code Online (Sandbox Code Playgroud)
但代码总是返回 401。当在单一租户中使用相同的 uri 时,它成功运行,所以我不确定我错过了什么。这是老方法。
yaml:
oauth2:
resourceserver:
jwt:
jwk-set-uri: https://jwt.com/token.json
Run Code Online (Sandbox Code Playgroud)
与实施:
.oauth2ResourceServer(oauth2 -> oauth2.
jwt(Customizer.withDefaults()));
Run Code Online (Sandbox Code Playgroud)
这样就认证成功了。
我也确实在日志中看到了差异。
使用身份验证解析器:
2023-03-21 11:46:11.085 DEBUG 15271 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [cabda122-1] HTTP GET "/api/v1/redacted"
2023-03-21 11:46:11.136 DEBUG 15271 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [cabda122-1] Completed 401 UNAUTHORIZED
Run Code Online (Sandbox Code Playgroud)
而老方式明确调用资源服务器并解码:
2023-03-21 11:41:53.843 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [963bfd7a-1] HTTP GET "/api/v1/redacted"
2023-03-21 11:41:53.932 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.r.f.client.ExchangeFunctions : [4740b9ba] HTTP GET https://jwt.com/token.json
2023-03-21 11:41:54.695 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.r.f.client.ExchangeFunctions : [4740b9ba] [3475d267-1, L:/10.26.8.242:58490 - R:jwt.com/99.64.754.467:443] Response 200 OK
2023-03-21 11:41:54.713 DEBUG 12500 --- [ctor-http-nio-3] o.s.core.codec.StringDecoder : [4740b9ba] [3475d267-1, L:/10.26.8.242:58490 - R:jwt.com/99.64.754.467:443] Decoded "REDACTED"
2023-03-21 11:41:54.736 DEBUG 12500 --- [ parallel-1] o.s.w.s.s.DefaultWebSessionManager : Created new WebSession.
2023-03-21 11:41:55.090 DEBUG 12500 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [963bfd7a-1] Completed 200 OK
Run Code Online (Sandbox Code Playgroud)
那么,为了让多租户方式实际使用资源服务器,我缺少什么呢?我在文档中没有看到任何提及。
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |