webflux 文件服务器,java - Spring Webflux资源服务器和Oauth2 - 堆栈内存溢出

我有两个单独的微服务:身份验证服务器和带有资源的服务。 我需要的是从身份验证服务器获取令牌,并使用此令牌向资源服务发出请求(并对其进行验证并将其交换为用户名)。 此时,我得到了无法正常运行的实现。

application.yml

spring:

security:

oauth2:

client:

registration:

custom:

client-id: SampleClientId

client-secret: secret

scopes: USER

authorization-grant-type: authorization_code

redirect-uri-template: http://localhost:8082/ui/login

provider:

custom:

authorization-uri: http://localhost:8081/auth/oauth/authorize

token-uri: http://localhost:8081/auth/oauth/token

user-info-uri: http://localhost:8081/auth/authenticate

SecurityConfig.class

@EnableWebFluxSecurity

public class SecurityConfig {

@Bean

public SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {

return http.authorizeExchange()

.pathMatchers("/health").permitAll()

.anyExchange().authenticated()

.and().oauth2Login()

.and().build();

}

}

和简单的端点来检索资源服务器中的用户名

@GetMapping("/username")

public Mono getHesalth(@RegisteredOAuth2AuthorizedClient("custom") OAuth2AuthorizedClient authorizedClient){

return Mono.just(authorizedClient.getPrincipalName());

}

当我用令牌头发出请求时:

curl -X GET \

http://localhost:8605/username \

-H 'Authorization: Bearer {token-from-auth-server}' \

-H 'Content-Type: application/json'

资源服务器不返回任何内容并记录日志:

2019-10-20 21:44:38.641 DEBUG 29768 --- [or-http-epoll-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [edd1881d] HTTP GET "/username"

2019-10-20 21:44:38.704 DEBUG 29768 --- [or-http-epoll-3] .s.u.m.MediaTypeServerWebExchangeMatcher : httpRequestMediaTypes=[*/*]

2019-10-20 21:44:38.705 DEBUG 29768 --- [or-http-epoll-3] .s.u.m.MediaTypeServerWebExchangeMatcher : Processing */*

2019-10-20 21:44:38.705 DEBUG 29768 --- [or-http-epoll-3] .s.u.m.MediaTypeServerWebExchangeMatcher : Ignoring

2019-10-20 21:44:38.705 DEBUG 29768 --- [or-http-epoll-3] .s.u.m.MediaTypeServerWebExchangeMatcher : Did not match any media types

2019-10-20 21:44:38.705 DEBUG 29768 --- [or-http-epoll-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [edd1881d] Completed 302 FOUND

2019-10-20 21:44:38.711 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Last HTTP response frame

2019-10-20 21:44:38.711 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] No sendHeaders() called before complete, sending zero-length header

2019-10-20 21:44:38.714 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Decreasing pending responses, now 0

2019-10-20 21:44:38.715 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Last HTTP packet was sent, terminating the channel

2019-10-20 21:44:38.715 DEBUG 29768 --- [or-http-epoll-3] r.n.channel.ChannelOperationsHandler : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] No ChannelOperation attached. Dropping: EmptyLastHttpContent

2019-10-20 21:44:38.717 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Increasing pending responses, now 1

2019-10-20 21:44:38.717 DEBUG 29768 --- [or-http-epoll-3] reactor.netty.http.server.HttpServer : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@3ec155e2

2019-10-20 21:44:38.717 DEBUG 29768 --- [or-http-epoll-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [edd1881d] HTTP GET "/oauth2/authorization/custom"

2019-10-20 21:44:38.732 DEBUG 29768 --- [or-http-epoll-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [edd1881d] Completed 302 FOUND

2019-10-20 21:44:38.734 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Last HTTP response frame

2019-10-20 21:44:38.735 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] No sendHeaders() called before complete, sending zero-length header

2019-10-20 21:44:38.735 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Decreasing pending responses, now 0

2019-10-20 21:44:38.735 DEBUG 29768 --- [or-http-epoll-3] r.n.http.server.HttpServerOperations : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] Last HTTP packet was sent, terminating the channel

2019-10-20 21:44:38.735 DEBUG 29768 --- [or-http-epoll-3] r.n.channel.ChannelOperationsHandler : [id: 0xedd1881d, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33452] No ChannelOperation attached. Dropping: EmptyLastHttpContent

2019-10-20 21:44:38.738 DEBUG 29768 --- [or-http-epoll-4] r.n.http.server.HttpServerOperations : [id: 0x93302880, L:/0:0:0:0:0:0:0:1%0:8605 - R:/0:0:0:0:0:0:0:1%0:33454] New http connection, requesting read

看来资源服务器看不到令牌和重定向。 有人针对这种情况配置正确吗? 还是我在哪里弄错了?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值