< /ol>
зависимости < /p>
csrf
.disable()
)
.authorizeHttpRequests(auth -> auth
.requestMatchers(HttpMethod.POST, "/auth/v1/login", "/auth/v1/refreshToken", "/auth/v1/signup")
.permitAll()
.anyRequest()
.authenticated()
)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.httpBasic(Customizer.withDefaults())
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.authenticationProvider(authenticationProvider());
return httpSecurity.build();
}
@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userDetailsServiceImpl);
authenticationProvider.setPasswordEncoder(passwordEncoder);
return authenticationProvider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}
}< /code>
< /div>
< /div>
< /p>
jwt filter
< /div>
< /div>
< /p>
Disabling CSRF and CORS via .csrf().disable().cors().disable()
Ensuring permitAll() is on the signup route
Testing from Postman with no Authorization or CSRF headers
Cleaning and rebuilding the project: ./gradlew clean bootRun
Confirming endpoint is hit and mapped correctly
< /code>
Why does Spring Security still return 403 CSRF on POST if CSRF is disabled?
Why is the 401 still triggered even though /auth/v1/signup is permitted?
Any workaround (restructure/filter ordering/config?) that gets this JWT-authenticated API working properly for public endpoints like signup/login?
Подробнее здесь: https://stackoverflow.com/questions/796 ... -on-public