addFilterBefore

inline fun <T : Filter> addFilterBefore(filter: Filter)

Adds the Filter before the location of the specified Filter class. Variant that is leveraging Kotlin reified type parameters.

Example:

@Configuration
@EnableWebSecurity
class SecurityConfig {

@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
addFilterBefore<UsernamePasswordAuthenticationFilter>(CustomFilter())
}
return http.build()
}
}

Parameters

filter

the Filter to register

Type Parameters

T

the location of another Filter that is already registered (i.e. known) with Spring Security.


fun addFilterBefore(filter: Filter, beforeFilter: Class<out Filter>)

Deprecated

Use 'addFilterBefore<T>(filter)' instead.

Adds the Filter before the location of the specified Filter class.

Example:

@Configuration
@EnableWebSecurity
class SecurityConfig {

@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
addFilterBefore(CustomFilter(), UsernamePasswordAuthenticationFilter::class.java)
}
return http.build()
}
}

Parameters

filter

the Filter to register

beforeFilter

the location of another Filter that is already registered (i.e. known) with Spring Security.