Skip to content

Commit 376aad2

Browse files
committed
fix: make docs compile with spring-boot 4
1 parent 0a80f73 commit 376aad2

File tree

7 files changed

+28
-21
lines changed

7 files changed

+28
-21
lines changed

articles/flow/security/enabling-security.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ extends VaadinWebSecurity { // <2>
288288
289289
// Configure your static resources with public access before calling
290290
// super.configure(HttpSecurity) as it adds final anyRequest matcher
291-
http.authorizeHttpRequests(auth -> auth.requestMatchers(new AntPathRequestMatcher("/public/**"))
292-
.permitAll());
291+
http.authorizeHttpRequests(
292+
auth -> auth
293+
.requestMatchers(PathPatternRequestMatcher
294+
.withDefaults().matcher("/public/**"))
295+
.permitAll());
293296
294297
super.configure(http); // <3>
295298

articles/hilla/lit/guides/security/spring-login.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ Public views need to be added to the configuration in [methodname]`securityFilte
147147
@Override
148148
protected void configure(HttpSecurity http) throws Exception {
149149
http.authorizeHttpRequests(registry -> {
150-
registry.requestMatchers(new AntPathRequestMatcher("/public-view")).permitAll(); // custom matcher
150+
registry.requestMatchers(PathPatternRequestMatcher.withDefaults()
151+
.matcher("/public-view")).permitAll(); // custom matcher
151152
});
152153
super.configure(http);
153154
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.springframework.boot</groupId>
2626
<artifactId>spring-boot-starter-parent</artifactId>
27-
<version>3.5.0</version>
27+
<version>4.0.0-M1</version>
2828
</parent>
2929
<!-- end::spring-version[] -->
3030

src/main/java/com/vaadin/demo/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.boot.web.servlet.ServletComponentScan;
5+
import org.springframework.boot.web.server.servlet.context.ServletComponentScan;
66
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
77
import org.springframework.context.annotation.ComponentScan;
88
import org.springframework.context.annotation.FilterType;

src/main/java/com/vaadin/demo/SecurityConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
import org.springframework.context.annotation.Configuration;
55
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
66
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7-
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
7+
import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
88

99
@EnableWebSecurity
1010
@Configuration
1111
public class SecurityConfig extends VaadinWebSecurity {
1212

1313
@Override
1414
protected void configure(HttpSecurity http) throws Exception {
15-
http.csrf().disable();
15+
http.csrf(csrf -> csrf.disable());
1616

1717
/* Disable on docs app, but leave in place to be used as snippet // hidden-source-line
1818
// tag::download[]
1919
// Restrict access to FileDownloadEndpoint to authenticated users
2020
http.authorizeHttpRequests(authorize -> authorize
21-
.requestMatchers(new AntPathRequestMatcher("/download/**")).authenticated());
21+
.requestMatchers(PathPatternRequestMatcher.withDefaults().matcher("/download/**")).authenticated());
2222
// end::download[]
2323
*/ // hidden-source-line
2424
}

src/main/java/com/vaadin/demo/fusion/security/stateless/SecurityConfig.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
99
import org.springframework.security.config.http.SessionCreationPolicy;
1010
import org.springframework.security.oauth2.jose.jws.JwsAlgorithms;
11-
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
11+
import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
1212

1313
import javax.crypto.spec.SecretKeySpec;
1414
import java.util.Base64;
@@ -39,19 +39,23 @@ protected void configure(HttpSecurity http) throws Exception {
3939

4040
// Configure your static resources with public access before calling
4141
// super.configure(HttpSecurity) as it adds final anyRequest matcher
42-
http.authorizeHttpRequests()
43-
.requestMatchers(new AntPathRequestMatcher("/admin-only/**"))
44-
.hasAnyRole("admin");
45-
http.authorizeHttpRequests()
46-
.requestMatchers(new AntPathRequestMatcher("/public/**"))
47-
.permitAll();
42+
http.authorizeHttpRequests(
43+
(requests) -> requests
44+
.requestMatchers(PathPatternRequestMatcher
45+
.withDefaults().matcher("/admin-only/**"))
46+
.hasAnyRole("admin"));
47+
http.authorizeHttpRequests(
48+
(requests) -> requests
49+
.requestMatchers(PathPatternRequestMatcher
50+
.withDefaults().matcher("/public/**"))
51+
.permitAll());
4852

4953
// tag::stateless-configure[]
5054
super.configure(http);
5155

5256
// Disable creating and using sessions in Spring Security
53-
http.sessionManagement()
54-
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
57+
http.sessionManagement((session) -> session
58+
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
5559

5660
// Register your login view to the view access checker mechanism
5761
setLoginView(http, "/login");

src/main/java/com/vaadin/demo/fusion/security/stateless/SecurityConfigurer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
3333
// end::stateless-configure[]
3434
http.authorizeHttpRequests(auth -> auth
3535
.requestMatchers("/admin-only/**").hasAnyRole("admin")
36-
.requestMatchers("/public/**").permitAll()
37-
);
36+
.requestMatchers("/public/**").permitAll());
3837

3938
// tag::stateless-configure[]
4039
// Disable creating and using sessions in Spring Security
41-
http.sessionManagement()
42-
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
40+
http.sessionManagement((session) -> session
41+
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
4342

4443
// Register your login view to the view access checker mechanism
4544
http.with(VaadinSecurityConfigurer.vaadin(),

0 commit comments

Comments
 (0)