I would like to configure my webapp, to reject all requests that don't have proper "Content-Type". for example: any content-type other than "application/json" should be rejected.
Currently I am doing it by a custom filter, but I would like to know how it can be done by "RequestHeaderRequestMatcher" in security config directly?
Lets' take the following example security config:
EnableWebSecurity
class SecurityConfig : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.authorizeRequests()
.requestMatchers(matcher)
.denyAll()
.antMatchers("/css/**", "/index")
.permitAll()
.antMatchers("/user/**")
.hasRole("USER")
http.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
}
}
How should I add the new request matcher to check all requests for valid content type?