Every endpoint is now protected, and a generated password is printed at startup. That
default is a reminder to configure it, not a setup.
A filter chain
@Configuration@EnableWebSecuritypublicclassSecurityConfig{@BeanSecurityFilterChainapi(HttpSecurityhttp)throwsException{returnhttp.authorizeHttpRequests(auth->auth.requestMatchers("/actuator/health","/public/**").permitAll().requestMatchers(HttpMethod.GET,"/api/books/**").hasRole("USER").requestMatchers("/api/**").hasRole("ADMIN").anyRequest().authenticated()).csrf(csrf->csrf.disable())// stateless API with tokens only.httpBasic(Customizer.withDefaults()).build();}}
Rules are matched top to bottom — put the specific ones first.
Do not disable CSRF blindly
Turn it off only for stateless APIs authenticated by a token or basic auth. A session-cookie
app needs CSRF protection.