Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I implement WebSecurityConfigurerAdapter on Spring WebFlux

I'm currently using Springs' WebFlux and I wanted to implement Spring Security. I am struggling to make any of my WebSecurityConfigurerAdapter http rules work and I am thinking it is because HttpSecurity changes have no effect. I'll explain what I mean:

I have chosen to implement WebSecurityConfigurerAdapter which has the method signature.

protected void configure(HttpSecurity http) throws Exception

This has been correctly configured but all of my endpoints receive 401 unauthorized (which is typical of a Configuration not being picked up and a default configuration being used instead). Instead, when I look at the implementations for WebFluxSecurity they usually implement a Bean with the following signature:

public SecurityWebFilterChain securitygWebFilterChain(
  ServerHttpSecurity http)

I know a lot of the WebFlux architecture implements a different set of Requests and Response objects to typical Spring so I am wondering whether I have to implement the WebFlux security way of doing things or if the more standard WebSecurityConfigurerAdapter way of implementing security should still work

Cheers

like image 622
DWB Avatar asked Jul 08 '18 17:07

DWB


People also ask

Why is WebSecurityConfigurerAdapter deprecated?

0-M2 we deprecated the WebSecurityConfigurerAdapter , as we encourage users to move towards a component-based security configuration. To assist with the transition to this new style of configuration, we have compiled a list of common use-cases and the suggested alternatives going forward.

Can I use Springmvc and WebFlux together?

both infrastructure will compete for the same job (for example, serving static resources, the mappings, etc) mixing both runtime models within the same container is not a good idea and is likely to perform badly or just not work at all.

What is the use of WebSecurityConfigurerAdapter in spring boot?

configure. Deprecated. Used by the default implementation of authenticationManager() to attempt to obtain an AuthenticationManager . If overridden, the AuthenticationManagerBuilder should be used to specify the AuthenticationManager .

When should I use spring WebFlux?

If you are looking to develop a web application or Rest web service on non-blocking reactive model, then you can look into Spring WebFlux. Spring WebFlux is supported on Tomcat, Jetty, Servlet 3.1+ containers, as well as on non-Servlet runtimes such as Netty and Undertow.


1 Answers

WebFluxSecurity use ServerHttpSecurity that use WebFilter to filter request. WebSecurity use HttpSecurity that javax.servlet.Filter to filter request.

it's different class and different implementation, overwrite:

protected void configure(HttpSecurity http) throws Exception

won't work

like image 96
Itay Avatar answered Oct 02 '22 08:10

Itay