Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring security filter is never invoked

I am trying to implement a Spring security filter as follows:

@Configuration
@EnableWebSecurity
open class OpenApiConfigurer : WebSecurityConfigurerAdapter() {

    override fun configure(http: HttpSecurity) {
        http.addFilter(object : FilterSecurityInterceptor() {
            override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain?) {
                super.doFilter(request, response, chain)
            }
        })
    }
    ...
}

I can confirm the @Configuration is loaded because, the configure method is invoked and the filter is added. However the method doFilter is never invoked – I can call whichever requests, but it never does anything inside of it.

What might be wrong? Do I need to do something special?

like image 426
Vojtěch Avatar asked Dec 23 '20 11:12

Vojtěch


1 Answers

The reason was following:

// Even though this class is not a bean/service/configuration, it must be defined for
// the Spring-Security to work - otherwise the filters are never invoked with no error.
open class SecurityInitializer : AbstractSecurityWebApplicationInitializer()
like image 128
Vojtěch Avatar answered Oct 16 '22 16:10

Vojtěch