Vojtěch
Vojtěch

Reputation: 12416

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?

Upvotes: 7

Views: 766

Answers (2)

funkygono
funkygono

Reputation: 420

I had the same problem, which was fixed by adding an implementation of the AbstractSecurityWebApplicationInitializer (see: Why is Spring Security not working?).

Upvotes: 0

Vojtěch
Vojtěch

Reputation: 12416

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()

Upvotes: 2

Related Questions