spring-projects / spring-security

Spring Security
http://spring.io/projects/spring-security
Apache License 2.0
8.82k stars 5.9k forks source link

Between WebFlux and MVC support saved request for login #7653

Closed 13940344135 closed 4 years ago

13940344135 commented 4 years ago

can I save the request to redis in spring mvc and then restore the request after webflux authentication?

Added: I used two services, mvc and webflux. When webflux is not authenticated, it will be redirected to the mvc login page. However, an exception will occur at this time. java.lang.ClassCastException: class java.lang.String cannot be cast to class org.springframework.security.web.savedrequest.SavedRequest

jzheaux commented 4 years ago

Thanks for reaching out, @13940344135. Sorry, but there is no support for combining WebFlux and MVC in the same application.

rodrigorodrigues commented 1 year ago

Hi all,

I found a hack way to make that work, basically need to apply this https://github.com/spring-cloud/spring-cloud-gateway/issues/474#issuecomment-533429469 and also disable the request cache on downstream service.

Spring Cloud Gateway(Redis Session) -> Downstream Backend Service(Redis)

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    return http.csrf().disable()
            .authorizeHttpRequests()
            .antMatchers("/actuator/**", "/error").permitAll()
            .anyRequest()
            .authenticated()
            .and()
                .formLogin().disable()
            .requestCache().disable()
            .build();
}