English 中文(简体)
How resolve 401 Unauthorized with EnableWebFluxSecurity
原标题:

My code:

@Configuration
@EnableWebFluxSecurity
@EnableHotmartSecurity
@EnableReactiveMethodSecurity(useAuthorizationManager = true)
class HttpSecurityConfig {

  @Bean
  fun springSecurityFilterChain(http: ServerHttpSecurity
  ): SecurityWebFilterChain {
    return http
      .httpBasic{}
      .cors {}
      .formLogin { configurer -> configurer.disable() }
      .logout { configurer -> configurer.disable() }
      .csrf { configurer -> configurer.disable() }
      .authorizeExchange {
        it.pathMatchers(HttpMethod.OPTIONS).permitAll()
        it.pathMatchers("/management/health").permitAll()
        it.pathMatchers("/management/**").hasRole("ACTUATOR")
      }.build()
  }
}
 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

When call request /block then return 401 Unauthorized

PathMatcherServerWebExchangeMatcher{pattern= /management/** , method=null}
2023-07-21T23:40:28.995-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] athPatternParserServerWebExchangeMatcher : Request  POST /user/block-users  doesn t match  null /management/** 
2023-07-21T23:40:28.996-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] o.s.s.w.s.u.m.OrServerWebExchangeMatcher : No matches found
2023-07-21T23:40:29.001-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] o.s.s.w.s.a.AuthorizationWebFilter       : Authorization failed: Access Denied
2023-07-21T23:40:29.028-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] ebSessionServerSecurityContextRepository : No SecurityContext found in WebSession:  org.springframework.web.server.session.InMemoryWebSessionStore$InMemoryWebSession@35f2c0da 
2023-07-21T23:40:29.029-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] DelegatingServerAuthenticationEntryPoint : Trying to match using org.springframework.security.config.web.server.ServerHttpSecurity$HttpBasicSpec$$Lambda$1297/0x0000000801395e08@13e6577c
2023-07-21T23:40:29.030-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] DelegatingServerAuthenticationEntryPoint : No match found. Using default entry point org.springframework.security.web.server.authentication.HttpBasicServerAuthenticationEntryPoint@5b8b2deb
2023-07-21T23:40:29.032-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] o.s.w.s.adapter.HttpWebHandlerAdapter    : [4984311b-1] Completed 401 UNAUTHORIZED
2023-07-21T23:40:29.060-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] r.n.http.server.HttpServerOperations     : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] Last HTTP response frame
2023-07-21T23:40:29.060-03:00 DEBUG [api-teste,,] 52726 --- [     parallel-1] r.n.http.server.HttpServerOperations     : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] No sendHeaders() called before complete, sending zero-length header
2023-07-21T23:40:29.076-03:00 DEBUG [api-teste,,] 52726 --- [ctor-http-nio-3] r.n.http.server.HttpServerOperations     : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] Decreasing pending responses, now 0
2023-07-21T23:40:29.078-03:00 DEBUG [api-teste,,] 52726 --- [ctor-http-nio-3] r.netty.channel.ChannelOperations        : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] [HttpServer] Channel inbound receiver cancelled (subscription disposed).
2023-07-21T23:40:29.082-03:00 DEBUG [api-teste,,] 52726 --- [ctor-http-nio-3] reactor.netty.channel.FluxReceive        : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] [terminated=true, cancelled=true, pending=0, error=null]: dropping frame LAST_CONTENT(decodeResult: success, content: PooledSlicedByteBuf(ridx: 0, widx: 15, cap: 15/15, unwrapped: PooledUnsafeDirectByteBuf(ridx: 1647, widx: 1647, cap: 2048)))
2023-07-21T23:40:29.083-03:00 DEBUG [api-teste,,] 52726 --- [ctor-http-nio-3] r.n.http.server.HttpServerOperations     : [4984311b-1, L:/[0:0:0:0:0:0:0:1]:8080 - R:/[0:0:0:0:0:0:0:1]:62743] Last HTTP packet was sent, terminating the channel
问题回答

暂无回答




相关问题
IConnectableObservables in Rx

Can someone explain the differences between an Observable and a ConnectableObservable? The Rx Extensions documentation is very sparse and I don t understand in what cases the ConnectableObservable is ...

How to create reactive tasks for programming competitions?

A reactive task is sometimes seen in the IOI programming competition. Unlike batch tasks, reactive solutions take input from another program as well as outputting it. The program typically query the ...

Is the Reactive Framework (RX) available for use in Mono yet?

Been searching but the only thing I found was http://evain.net/blog/articles/2009/07/30/rebasing-system-reactive-to-the-net-clr which I got to work, but it feels like there should be a simpler way, ...

Using MonadPlus in FRP.Reactive.FieldTrip

I m studying FRP at this moment through FieldTrip adaptor. And hit the problem with strange way of frames scheduling and integration. So now I m trying to build own marker Event for aligning Behaviour ...

Examples of useful or non-trival dual interfaces

Recently Erik Meijer and others have show how IObservable/IObserver is the dual of IEnumerable/IEnumerator. The fact that they are dual means that any operation on one interface is valid on the other, ...

Reactive Extensions (Rx) + MVVM =?

One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new event representing deltas during mouse drag: var mouseMoves = from ...

热门标签