|
1 | 1 | /* |
2 | | - * Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com |
| 2 | + * Copyright (C) 2026 Dominik Schadow, dominikschadow@gmail.com |
3 | 3 | * |
4 | 4 | * This file is part of the Java Security project. |
5 | 5 | * |
|
21 | 21 | import org.springframework.context.annotation.Configuration; |
22 | 22 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
23 | 23 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; |
| 24 | +import org.springframework.security.config.Customizer; |
24 | 25 | import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; |
25 | 26 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 27 | +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; |
26 | 28 | import org.springframework.security.core.userdetails.User; |
27 | 29 | import org.springframework.security.core.userdetails.UserDetails; |
28 | 30 | import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl; |
29 | 31 | import org.springframework.security.provisioning.JdbcUserDetailsManager; |
30 | 32 | import org.springframework.security.provisioning.UserDetailsManager; |
31 | 33 | import org.springframework.security.web.SecurityFilterChain; |
32 | | -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
33 | 34 |
|
34 | 35 | import javax.sql.DataSource; |
35 | 36 |
|
@@ -74,22 +75,21 @@ public UserDetailsManager users(DataSource dataSource) { |
74 | 75 | public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
75 | 76 | // @formatter:off |
76 | 77 | http |
77 | | - .authorizeHttpRequests() |
| 78 | + .authorizeHttpRequests(authorize -> authorize |
78 | 79 | .requestMatchers("/*", "/h2-console/**").permitAll() |
79 | 80 | .requestMatchers("/user/**").hasAnyRole("USER", "ADMIN") |
80 | 81 | .requestMatchers("/admin/**").hasRole("ADMIN") |
81 | | - .and() |
82 | | - .csrf() |
| 82 | + ) |
| 83 | + .csrf(csrf -> csrf |
83 | 84 | .ignoringRequestMatchers("/h2-console/*") |
84 | | - .and() |
85 | | - .headers() |
86 | | - .frameOptions().sameOrigin() |
87 | | - .and() |
88 | | - .formLogin() |
89 | | - .and() |
90 | | - .logout() |
91 | | - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) |
92 | | - .logoutSuccessUrl("/"); |
| 85 | + ) |
| 86 | + .headers(headers -> headers |
| 87 | + .frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin) |
| 88 | + ) |
| 89 | + .formLogin(Customizer.withDefaults()) |
| 90 | + .logout(logout -> logout |
| 91 | + .logoutSuccessUrl("/") |
| 92 | + ); |
93 | 93 | // @formatter:on |
94 | 94 |
|
95 | 95 | return http.build(); |
|
0 commit comments