Always getting 403 Forbidden error even thought it should return 404 Not Exists (Java Spring application problem)

I am having the problem with Java 17 Spring Maven application because it always returns to me 403 Forbidden status in Postman when I test my code. I locate the problem within securityFilterChain() method but I am not sure how could I fix this.

public class SecurityConfiguration {

    private final JwtAuthenticationFilter jwtAuthFilter;

    private final AuthenticationProvider authenticationProvider;
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
                .authorizeHttpRequests(auth -> auth
                .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);


Has anyone experienced similar problem.

Thanks in advance!

When I disabled: .authenticationProvider(authenticationProvider) .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); and .requestMatchers("/api/v1/city/**").permitAll() .requestMatchers("/api/v1/auth/**").permitAll() Then it gives right response but then i dissable JWT Authentication

Example of problem

Example of problem


  • You are being redirected to /error page which is secured by spring-security. so you should permit it