I need a "/public" endpoint be accessed by unauthenticated users and any other endpoints be accessed by only authenticated users. Why this configuration doesn't work. I configured it according to spring security 6 authorication docs.
When I access "/public" it responses with 401 Unauthorized
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(a ->
a.requestMatchers("/public").permitAll()
.anyRequest().authenticated()
);
return http.build();
}
}