I have Spring Boot RestAPI and I if I throw any Exception in the endpoint method Spring automatically returns 403 instead of 500. Also if a parameter is missing or the endpoint does not exist it returns 403 and not 400 or a 404
I think the problem is in my Spring Security Configuration. My SecurityConfigurer looks like this:
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfigurer {
private final JwtRequestFilter jwtRequestFilter;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
final String BASE = APP.API_BASE_URL;
http
.csrf().disable()
.authorizeHttpRequests()
.requestMatchers(BASE + "/login").permitAll()
.anyRequest().authenticated()
.and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(15);
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
}