I've got a Spring boot application with this security config:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().frameOptions().sameOrigin().and()
.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/authenticate/**", "/h2-console/**").permitAll()
.anyRequest().authenticated();
}
And in my application code I throw a ResponseStatusException:
if (existingTenant.isPresent()) {
throw new ResponseStatusException(
HttpStatusCode.valueOf(400),
"Tenant with name " + tenant.name() + " already exists");
}
But the api response I get is a 403:
* Mark bundle as not supporting multiuse
< HTTP/1.1 403
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: SAMEORIGIN
< Content-Length: 0
< Date: Sat, 13 Aug 2022 19:26:27 GMT
<
* Connection #0 to host localhost left intact
The only logging I see is:
2022-08-13T12:32:09.260-07:00 WARN 79360 --- [nio-8080-exec-6] .w.s.m.a.ResponseStatusExceptionResolver : Resolved [org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST "Tenant with name tenant1 already exists"]
Why isn't the response getting the 400
response code I set in the exception?