I'm new in spring webflux yesterday I've implemented with jwt and It returns 401 response except for first request, for first request it is authorizing my token and returning the correct response but not after that
@Bean
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
return http.requestCache()
.requestCache(NoOpServerRequestCache.getInstance()).and().securityContextRepository(NoOpServerSecurityContextRepository.getInstance()).exceptionHandling()
.authenticationEntryPoint((swe, e) -> {
return Mono.fromRunnable(() -> {
swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
});
}).accessDeniedHandler((swe, e) -> {
return Mono.fromRunnable(() -> {
swe.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
});
}).and()
.csrf().disable()
.formLogin().disable()
.httpBasic().disable()
.logout().disable()
.authenticationManager(authenticationManager)
.securityContextRepository(securityContextRepository)
.authorizeExchange()
.pathMatchers(adminAccess.toArray(new String[0])).hasAuthority("ADMIN")
.pathMatchers(userAccess.toArray(new String[0])).hasAuthority("USER")
.pathMatchers(guestAccess.toArray(new String[0])).permitAll()
// all other requests need to be authenticated
.anyExchange().authenticated().and().exceptionHandling()
.and().build();
}
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add more detail if you feel this is a genuine bug.