Plus, alle Artikel, die ich verwendet habe. autorizeHttprequests aber ich bin zu sehr investiert, um das Problem damit zu finden. Es ist wahrscheinlich auch etwas wirklich kleines, das ich missverstanden habe. Ich verwende Java 24 mit Spring Boot 3.4.5.
Code: Select all
@Controller
@RequestMapping("/")
public class AppController {
@GetMapping
@PreAuthorize("hasRole('ANONYMOUS')")
public String home() {
return "home"; // template file in classpath:/templates
}
}
Code: Select all
@EnableWebSecurity(debug = true)
@EnableMethodSecurity
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain filter(HttpSecurity http) throws Exception {
var whitelist = new String[]{
"/styles/**",
"/listing-images/**",
"/thumbnail-images/**",
"/login",
"/favicon.ico"
};
return http
.authorizeHttpRequests(a -> a
.requestMatchers(whitelist).permitAll()
.anyRequest().authenticated()
)
.formLogin(Customizer.withDefaults())
.build();
}
}
Code: Select all
spring:
datasource:
url: jdbc:postgresql://localhost:9056/db
username: my_user
password: my_password
logging:
level:
org.springframework.security: debug
server:
port: 8090
Ordnerstruktur:
