Merge branch '3.2.x'

Closes gh-41080
This commit is contained in:
Phillip Webb 2024-06-11 13:32:30 -07:00
commit 147240aa0c
42 changed files with 115 additions and 93 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,12 +35,12 @@ public enum UpgradePolicy implements BiPredicate<DependencyVersion, DependencyVe
/** /**
* Minor versions of the current major version. * Minor versions of the current major version.
*/ */
SAME_MAJOR_VERSION((candidate, current) -> candidate.isSameMajor(current)), SAME_MAJOR_VERSION(DependencyVersion::isSameMajor),
/** /**
* Patch versions of the current minor version. * Patch versions of the current minor version.
*/ */
SAME_MINOR_VERSION((candidate, current) -> candidate.isSameMinor(current)); SAME_MINOR_VERSION(DependencyVersion::isSameMinor);
private final BiPredicate<DependencyVersion, DependencyVersion> delegate; private final BiPredicate<DependencyVersion, DependencyVersion> delegate;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,6 +46,7 @@ import org.quartz.Trigger;
import org.quartz.Trigger.TriggerState; import org.quartz.Trigger.TriggerState;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.quartz.impl.matchers.GroupMatcher; import org.quartz.impl.matchers.GroupMatcher;
import org.quartz.utils.Key;
import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.OperationResponseBody;
import org.springframework.boot.actuate.endpoint.SanitizableData; import org.springframework.boot.actuate.endpoint.SanitizableData;
@ -100,7 +101,7 @@ public class QuartzEndpoint {
for (String groupName : this.scheduler.getJobGroupNames()) { for (String groupName : this.scheduler.getJobGroupNames()) {
List<String> jobs = this.scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)) List<String> jobs = this.scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))
.stream() .stream()
.map((key) -> key.getName()) .map(Key::getName)
.toList(); .toList();
result.put(groupName, Collections.singletonMap("jobs", jobs)); result.put(groupName, Collections.singletonMap("jobs", jobs));
} }
@ -121,7 +122,7 @@ public class QuartzEndpoint {
groupDetails.put("triggers", groupDetails.put("triggers",
this.scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName)) this.scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))
.stream() .stream()
.map((key) -> key.getName()) .map(Key::getName)
.toList()); .toList());
result.put(groupName, groupDetails); result.put(groupName, groupDetails);
} }

View File

@ -226,6 +226,8 @@ public class FlywayAutoConfiguration {
* @param properties the properties * @param properties the properties
*/ */
private void configureProperties(FluentConfiguration configuration, FlywayProperties properties) { private void configureProperties(FluentConfiguration configuration, FlywayProperties properties) {
// NOTE: Using method references in the mapper methods can break
// back-compatibilty (see gh-38164)
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
String[] locations = new LocationResolver(configuration.getDataSource()) String[] locations = new LocationResolver(configuration.getDataSource())
.resolveLocations(properties.getLocations()) .resolveLocations(properties.getLocations())

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -148,9 +148,9 @@ public class HibernateProperties {
private void applyNamingStrategies(Map<String, Object> properties) { private void applyNamingStrategies(Map<String, Object> properties) {
applyNamingStrategy(properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY, this.implicitStrategy, applyNamingStrategy(properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY, this.implicitStrategy,
() -> SpringImplicitNamingStrategy.class.getName()); SpringImplicitNamingStrategy.class::getName);
applyNamingStrategy(properties, AvailableSettings.PHYSICAL_NAMING_STRATEGY, this.physicalStrategy, applyNamingStrategy(properties, AvailableSettings.PHYSICAL_NAMING_STRATEGY, this.physicalStrategy,
() -> CamelCaseToUnderscoresNamingStrategy.class.getName()); CamelCaseToUnderscoresNamingStrategy.class::getName);
} }
private void applyNamingStrategy(Map<String, Object> properties, String key, Object strategy, private void applyNamingStrategy(Map<String, Object> properties, String key, Object strategy,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020-2023 the original author or authors. * Copyright 2020-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,6 +45,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity.CsrfSpec;
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
@ -161,7 +162,7 @@ class GraphQlWebFluxSecurityAutoConfigurationTests {
@Bean @Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) { SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
return http.csrf((spec) -> spec.disable()) return http.csrf(CsrfSpec::disable)
// Demonstrate that method security works // Demonstrate that method security works
// Best practice to use both for defense in depth // Best practice to use both for defense in depth
.authorizeExchange((requests) -> requests.anyExchange().permitAll()) .authorizeExchange((requests) -> requests.anyExchange().permitAll())

View File

@ -41,6 +41,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@ -154,7 +155,7 @@ class GraphQlWebMvcSecurityAutoConfigurationTests {
@Bean @Bean
DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception { DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
return http.csrf((c) -> c.disable()) return http.csrf(CsrfConfigurer::disable)
// Demonstrate that method security works // Demonstrate that method security works
// Best practice to use both for defense in depth // Best practice to use both for defense in depth
.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll()) .authorizeHttpRequests((requests) -> requests.anyRequest().permitAll())

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ class ConditionEvaluationReportLoggingListenerTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context); this.initializer.initialize(context);
context.register(Config.class); context.register(Config.class);
withDebugLogging(() -> context.refresh()); withDebugLogging(context::refresh);
assertThat(output).contains("CONDITIONS EVALUATION REPORT"); assertThat(output).contains("CONDITIONS EVALUATION REPORT");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@ -49,7 +50,7 @@ class RemoteDevtoolsSecurityConfiguration {
SecurityFilterChain devtoolsSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain devtoolsSecurityFilterChain(HttpSecurity http) throws Exception {
http.securityMatcher(new AntPathRequestMatcher(this.url)); http.securityMatcher(new AntPathRequestMatcher(this.url));
http.authorizeHttpRequests((requests) -> requests.anyRequest().anonymous()); http.authorizeHttpRequests((requests) -> requests.anyRequest().anonymous());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -297,7 +297,7 @@ class FileSystemWatcherTests {
private void setupWatcher(long pollingInterval, long quietPeriod, SnapshotStateRepository snapshotStateRepository) { private void setupWatcher(long pollingInterval, long quietPeriod, SnapshotStateRepository snapshotStateRepository) {
this.watcher = new FileSystemWatcher(false, Duration.ofMillis(pollingInterval), Duration.ofMillis(quietPeriod), this.watcher = new FileSystemWatcher(false, Duration.ofMillis(pollingInterval), Duration.ofMillis(quietPeriod),
snapshotStateRepository); snapshotStateRepository);
this.watcher.addListener((changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet)); this.watcher.addListener(FileSystemWatcherTests.this.changes::add);
} }
private File startWithNewDirectory() { private File startWithNewDirectory() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -115,7 +115,7 @@ class DefaultRunningServiceTests {
} }
private DefaultRunningService createRunningService(boolean psResponseHasImage) { private DefaultRunningService createRunningService(boolean psResponseHasImage) {
DockerHost host = DockerHost.get("192.168.1.1", () -> Collections.emptyList()); DockerHost host = DockerHost.get("192.168.1.1", Collections::emptyList);
String id = "123"; String id = "123";
String name = "my-service"; String name = "my-service";
String image = "redis"; String image = "redis";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -52,7 +52,7 @@ class DockerHostTests {
private static final Function<String, String> NO_SYSTEM_ENV = (key) -> null; private static final Function<String, String> NO_SYSTEM_ENV = (key) -> null;
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = () -> Collections.emptyList(); private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = Collections::emptyList;
@Test @Test
void getWhenHasHost() { void getWhenHasHost() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,14 +58,14 @@ class TcpConnectServiceReadinessCheckTests {
@Test @Test
void checkWhenServerWritesData() throws Exception { void checkWhenServerWritesData() throws Exception {
withServer((socket) -> socket.getOutputStream().write('!'), (port) -> check(port)); withServer((socket) -> socket.getOutputStream().write('!'), this::check);
} }
@Test @Test
void checkWhenNoSocketOutput() throws Exception { void checkWhenNoSocketOutput() throws Exception {
// Simulate waiting for traffic from client to server. The sleep duration must // Simulate waiting for traffic from client to server. The sleep duration must
// be longer than the read timeout of the ready check! // be longer than the read timeout of the ready check!
withServer((socket) -> sleep(Duration.ofSeconds(10)), (port) -> check(port)); withServer((socket) -> sleep(Duration.ofSeconds(10)), this::check);
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,6 +24,8 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.security.config.Customizer; import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@Profile("dev") @Profile("dev")
@ -35,8 +37,8 @@ public class DevProfileSecurityConfiguration {
SecurityFilterChain h2ConsoleSecurityFilterChain(HttpSecurity http) throws Exception { SecurityFilterChain h2ConsoleSecurityFilterChain(HttpSecurity http) throws Exception {
http.securityMatcher(PathRequest.toH2Console()); http.securityMatcher(PathRequest.toH2Console());
http.authorizeHttpRequests(yourCustomAuthorization()); http.authorizeHttpRequests(yourCustomAuthorization());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.headers((headers) -> headers.frameOptions((frame) -> frame.sameOrigin())); http.headers((headers) -> headers.frameOptions(FrameOptionsConfig::sameOrigin));
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ class ExcludeFilterApplicationContextInitializerTests {
void testConfigurationIsExcluded() { void testConfigurationIsExcluded() {
SpringApplication application = new SpringApplication(TestApplication.class); SpringApplication application = new SpringApplication(TestApplication.class);
application.setWebApplicationType(WebApplicationType.NONE); application.setWebApplicationType(WebApplicationType.NONE);
AssertableApplicationContext applicationContext = AssertableApplicationContext.get(() -> application.run()); AssertableApplicationContext applicationContext = AssertableApplicationContext.get(application::run);
assertThat(applicationContext).hasSingleBean(TestApplication.class); assertThat(applicationContext).hasSingleBean(TestApplication.class);
assertThat(applicationContext).doesNotHaveBean(ExcludedTestConfiguration.class); assertThat(applicationContext).doesNotHaveBean(ExcludedTestConfiguration.class);
} }

View File

@ -111,7 +111,7 @@ class ContainerConnectionDetailsFactoryTests {
void getContainerWhenNotInitializedThrowsException() { void getContainerWhenNotInitializedThrowsException() {
TestContainerConnectionDetailsFactory factory = new TestContainerConnectionDetailsFactory(); TestContainerConnectionDetailsFactory factory = new TestContainerConnectionDetailsFactory();
TestContainerConnectionDetails connectionDetails = getConnectionDetails(factory, this.source); TestContainerConnectionDetails connectionDetails = getConnectionDetails(factory, this.source);
assertThatIllegalStateException().isThrownBy(() -> connectionDetails.callGetContainer()) assertThatIllegalStateException().isThrownBy(connectionDetails::callGetContainer)
.withMessage("Container cannot be obtained before the connection details bean has been initialized"); .withMessage("Container cannot be obtained before the connection details bean has been initialized");
} }

View File

@ -255,7 +255,7 @@ class ImageReferenceTests {
void inTaggedFormWhenHasDigestThrowsException() { void inTaggedFormWhenHasDigestThrowsException() {
ImageReference reference = ImageReference ImageReference reference = ImageReference
.of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"); .of("ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
assertThatIllegalStateException().isThrownBy(() -> reference.inTaggedForm()) assertThatIllegalStateException().isThrownBy(reference::inTaggedForm)
.withMessage( .withMessage(
"Image reference 'docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d' cannot contain a digest"); "Image reference 'docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d' cannot contain a digest");
} }

View File

@ -93,7 +93,7 @@ public class SpringBootExtension {
tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo)); tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
bootBuildInfo.configure((buildInfo) -> buildInfo.getProperties() bootBuildInfo.configure((buildInfo) -> buildInfo.getProperties()
.getArtifact() .getArtifact()
.convention(this.project.provider(() -> determineArtifactBaseName()))); .convention(this.project.provider(this::determineArtifactBaseName)));
}); });
if (configurer != null) { if (configurer != null) {
bootBuildInfo.configure(configurer); bootBuildInfo.configure(configurer);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -152,7 +152,7 @@ public class SpringBootAotPlugin implements Plugin<Project> {
task.getClassesOutput() task.getClassesOutput()
.set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Classes")); .set(project.getLayout().getBuildDirectory().dir("generated/" + sourceSet.getName() + "Classes"));
task.getGroupId().set(project.provider(() -> String.valueOf(project.getGroup()))); task.getGroupId().set(project.provider(() -> String.valueOf(project.getGroup())));
task.getArtifactId().set(project.provider(() -> project.getName())); task.getArtifactId().set(project.provider(project::getName));
configureToolchainConvention(project, task); configureToolchainConvention(project, task);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -719,7 +719,7 @@ class JarFileTests {
Iterator<JarEntry> iterator = this.jarFile.iterator(); Iterator<JarEntry> iterator = this.jarFile.iterator();
iterator.next(); iterator.next();
this.jarFile.close(); this.jarFile.close();
assertThatZipFileClosedIsThrownBy(() -> iterator.hasNext()); assertThatZipFileClosedIsThrownBy(iterator::hasNext);
} }
@Test @Test

View File

@ -240,7 +240,7 @@ class NestedJarFileTests {
void getCommentWhenClosedThrowsException() throws IOException { void getCommentWhenClosedThrowsException() throws IOException {
try (NestedJarFile jar = new NestedJarFile(this.file)) { try (NestedJarFile jar = new NestedJarFile(this.file)) {
jar.close(); jar.close();
assertThatIllegalStateException().isThrownBy(() -> jar.getComment()).withMessage("Zip file closed"); assertThatIllegalStateException().isThrownBy(jar::getComment).withMessage("Zip file closed");
} }
} }
@ -269,7 +269,7 @@ class NestedJarFileTests {
void sizeWhenClosedThrowsException() throws Exception { void sizeWhenClosedThrowsException() throws Exception {
try (NestedJarFile jar = new NestedJarFile(this.file)) { try (NestedJarFile jar = new NestedJarFile(this.file)) {
jar.close(); jar.close();
assertThatIllegalStateException().isThrownBy(() -> jar.size()).withMessage("Zip file closed"); assertThatIllegalStateException().isThrownBy(jar::size).withMessage("Zip file closed");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -242,7 +242,7 @@ class JarUrlConnectionTests {
@Test @Test
void getInputStreamWhenNotNestedAndHasNoEntryThrowsException() throws Exception { void getInputStreamWhenNotNestedAndHasNoEntryThrowsException() throws Exception {
JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file)); JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file));
assertThatIOException().isThrownBy(() -> connection.getInputStream()).withMessage("no entry name specified"); assertThatIOException().isThrownBy(connection::getInputStream).withMessage("no entry name specified");
} }
@Test @Test

View File

@ -37,10 +37,14 @@ class ModifiedClassPathExtensionForkParameterizedTests {
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = { "one", "two", "three" }) @ValueSource(strings = { "one", "two", "three" })
void testIsInvokedOnceForEachArgument(String argument) { void testIsInvokedOnceForEachArgument(String argument) {
switch (argument) { if (argument.equals("one")) {
case "one" -> assertThat(arguments).isEmpty(); assertThat(arguments).isEmpty();
case "two" -> assertThat(arguments).doesNotContain("two", "three"); }
case "three" -> assertThat(arguments).doesNotContain("three"); else if (argument.equals("two")) {
assertThat(arguments).doesNotContain("two", "three");
}
else if (argument.equals("three")) {
assertThat(arguments).doesNotContain("three");
} }
arguments.add(argument); arguments.add(argument);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ class PropertySourcesDeducerTests {
Environment environment = mock(Environment.class); Environment environment = mock(Environment.class);
given(applicationContext.getEnvironment()).willReturn(environment); given(applicationContext.getEnvironment()).willReturn(environment);
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext); PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
assertThatIllegalStateException().isThrownBy(() -> deducer.getPropertySources()) assertThatIllegalStateException().isThrownBy(deducer::getPropertySources)
.withMessage("Unable to obtain PropertySources from PropertySourcesPlaceholderConfigurer or Environment"); .withMessage("Unable to obtain PropertySources from PropertySourcesPlaceholderConfigurer or Environment");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -160,7 +160,7 @@ class LoggerConfigurationTests {
@Test @Test
void getLevelWhenCustomThrowsException() { void getLevelWhenCustomThrowsException() {
LevelConfiguration configuration = LevelConfiguration.ofCustom("FINE"); LevelConfiguration configuration = LevelConfiguration.ofCustom("FINE");
assertThatIllegalStateException().isThrownBy(() -> configuration.getLevel()) assertThatIllegalStateException().isThrownBy(configuration::getLevel)
.withMessage("Unable to provide LogLevel for 'FINE'"); .withMessage("Unable to provide LogLevel for 'FINE'");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.boot.logging.log4j2; package org.springframework.boot.logging.log4j2;
import java.lang.reflect.Method;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -46,8 +47,7 @@ class SpringBootPropertySourceTests {
@Test @Test
void allDefaultMethodsAreImplemented() { void allDefaultMethodsAreImplemented() {
assertThat(Stream.of(SpringBootPropertySource.class.getMethods()).filter((method) -> method.isDefault())) assertThat(Stream.of(SpringBootPropertySource.class.getMethods()).filter(Method::isDefault)).isEmpty();
.isEmpty();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ class LogbackLoggingSystemParallelInitializationTests {
List<Thread> threads = new ArrayList<>(); List<Thread> threads = new ArrayList<>();
List<Throwable> exceptions = new CopyOnWriteArrayList<>(); List<Throwable> exceptions = new CopyOnWriteArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
Thread thread = new Thread(() -> this.loggingSystem.beforeInitialize()); Thread thread = new Thread(this.loggingSystem::beforeInitialize);
thread.setUncaughtExceptionHandler((t, ex) -> exceptions.add(ex)); thread.setUncaughtExceptionHandler((t, ex) -> exceptions.add(ex));
threads.add(thread); threads.add(thread);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ public abstract class AbstractScriptDatabaseInitializerTests<T extends AbstractS
DatabaseInitializationSettings settings = new DatabaseInitializationSettings(); DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
settings.setDataLocations(Arrays.asList("data.sql")); settings.setDataLocations(Arrays.asList("data.sql"));
T initializer = createEmbeddedDatabaseInitializer(settings); T initializer = createEmbeddedDatabaseInitializer(settings);
assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> initializer.initializeDatabase()); assertThatExceptionOfType(DataAccessException.class).isThrownBy(initializer::initializeDatabase);
assertThatDatabaseWasAccessed(initializer); assertThatDatabaseWasAccessed(initializer);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -89,7 +89,7 @@ class DefaultSslManagerBundleTests {
SslStoreBundle storeBundle = SslStoreBundle.of(keyStore, null, null); SslStoreBundle storeBundle = SslStoreBundle.of(keyStore, null, null);
DefaultSslManagerBundle bundle = new TestDefaultSslManagerBundle(storeBundle, DefaultSslManagerBundle bundle = new TestDefaultSslManagerBundle(storeBundle,
SslBundleKey.of("secret", "alias")); SslBundleKey.of("secret", "alias"));
assertThatIllegalStateException().isThrownBy(() -> bundle.getKeyManagerFactory()) assertThatIllegalStateException().isThrownBy(bundle::getKeyManagerFactory)
.withMessage("Keystore does not contain alias 'alias'"); .withMessage("Keystore does not contain alias 'alias'");
} }
@ -100,7 +100,7 @@ class DefaultSslManagerBundleTests {
SslStoreBundle storeBundle = SslStoreBundle.of(keyStore, null, null); SslStoreBundle storeBundle = SslStoreBundle.of(keyStore, null, null);
DefaultSslManagerBundle bundle = new TestDefaultSslManagerBundle(storeBundle, DefaultSslManagerBundle bundle = new TestDefaultSslManagerBundle(storeBundle,
SslBundleKey.of("secret", "alias")); SslBundleKey.of("secret", "alias"));
assertThatIllegalStateException().isThrownBy(() -> bundle.getKeyManagerFactory()) assertThatIllegalStateException().isThrownBy(bundle::getKeyManagerFactory)
.withMessage("Could not determine if keystore contains alias 'alias'"); .withMessage("Could not determine if keystore contains alias 'alias'");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -59,7 +59,7 @@ class ReactiveWebServerApplicationContextTests {
@Test @Test
void whenThereIsNoWebServerFactoryBeanThenContextRefreshWillFail() { void whenThereIsNoWebServerFactoryBeanThenContextRefreshWillFail() {
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining( .withMessageContaining(
"Unable to start ReactiveWebServerApplicationContext due to missing ReactiveWebServerFactory bean"); "Unable to start ReactiveWebServerApplicationContext due to missing ReactiveWebServerFactory bean");
@ -68,7 +68,7 @@ class ReactiveWebServerApplicationContextTests {
@Test @Test
void whenThereIsNoHttpHandlerBeanThenContextRefreshWillFail() { void whenThereIsNoHttpHandlerBeanThenContextRefreshWillFail() {
addWebServerFactoryBean(); addWebServerFactoryBean();
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining("Unable to start ReactiveWebApplicationContext due to missing HttpHandler bean"); .withMessageContaining("Unable to start ReactiveWebApplicationContext due to missing HttpHandler bean");
} }
@ -77,7 +77,7 @@ class ReactiveWebServerApplicationContextTests {
void whenThereAreMultipleWebServerFactoryBeansThenContextRefreshWillFail() { void whenThereAreMultipleWebServerFactoryBeansThenContextRefreshWillFail() {
addWebServerFactoryBean(); addWebServerFactoryBean();
addWebServerFactoryBean("anotherWebServerFactory"); addWebServerFactoryBean("anotherWebServerFactory");
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining( .withMessageContaining(
"Unable to start ReactiveWebApplicationContext due to multiple ReactiveWebServerFactory beans"); "Unable to start ReactiveWebApplicationContext due to multiple ReactiveWebServerFactory beans");
@ -88,7 +88,7 @@ class ReactiveWebServerApplicationContextTests {
addWebServerFactoryBean(); addWebServerFactoryBean();
addHttpHandlerBean("httpHandler1"); addHttpHandlerBean("httpHandler1");
addHttpHandlerBean("httpHandler2"); addHttpHandlerBean("httpHandler2");
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining("Unable to start ReactiveWebApplicationContext due to multiple HttpHandler beans"); .withMessageContaining("Unable to start ReactiveWebApplicationContext due to multiple HttpHandler beans");
} }
@ -164,7 +164,7 @@ class ReactiveWebServerApplicationContextTests {
addWebServerFactoryBean(); addWebServerFactoryBean();
addHttpHandlerBean(); addHttpHandlerBean();
this.context.refresh(); this.context.refresh();
assertThatIllegalStateException().isThrownBy(() -> this.context.refresh()) assertThatIllegalStateException().isThrownBy(this.context::refresh)
.withMessageContaining("multiple refresh attempts"); .withMessageContaining("multiple refresh attempts");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -205,7 +205,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test @Test
void failsWithDoubleRegistration() { void failsWithDoubleRegistration() {
assertThatIllegalStateException().isThrownBy(() -> doubleRegistration()) assertThatIllegalStateException().isThrownBy(this::doubleRegistration)
.withMessage("Failed to register 'filter double-registration' on the " .withMessage("Failed to register 'filter double-registration' on the "
+ "servlet context. Possibly already registered?"); + "servlet context. Possibly already registered?");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,7 +69,7 @@ class ServletRegistrationBeanTests {
@Test @Test
void failsWithDoubleRegistration() { void failsWithDoubleRegistration() {
assertThatIllegalStateException().isThrownBy(() -> doubleRegistration()) assertThatIllegalStateException().isThrownBy(this::doubleRegistration)
.withMessage("Failed to register 'servlet double-registration' on " .withMessage("Failed to register 'servlet double-registration' on "
+ "the servlet context. Possibly already registered?"); + "the servlet context. Possibly already registered?");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -215,7 +215,7 @@ class ServletWebServerApplicationContextTests {
void cannotSecondRefresh() { void cannotSecondRefresh() {
addWebServerFactoryBean(); addWebServerFactoryBean();
this.context.refresh(); this.context.refresh();
assertThatIllegalStateException().isThrownBy(() -> this.context.refresh()); assertThatIllegalStateException().isThrownBy(this.context::refresh);
} }
@Test @Test
@ -229,7 +229,7 @@ class ServletWebServerApplicationContextTests {
@Test @Test
void missingServletWebServerFactory() { void missingServletWebServerFactory() {
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining("Unable to start ServletWebServerApplicationContext due to missing " .withMessageContaining("Unable to start ServletWebServerApplicationContext due to missing "
+ "ServletWebServerFactory bean"); + "ServletWebServerFactory bean");
@ -240,7 +240,7 @@ class ServletWebServerApplicationContextTests {
addWebServerFactoryBean(); addWebServerFactoryBean();
this.context.registerBeanDefinition("webServerFactory2", this.context.registerBeanDefinition("webServerFactory2",
new RootBeanDefinition(MockServletWebServerFactory.class)); new RootBeanDefinition(MockServletWebServerFactory.class));
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> this.context.refresh()) assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(this.context::refresh)
.havingRootCause() .havingRootCause()
.withMessageContaining("Unable to start ServletWebServerApplicationContext due to " .withMessageContaining("Unable to start ServletWebServerApplicationContext due to "
+ "multiple ServletWebServerFactory beans"); + "multiple ServletWebServerFactory beans");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
@ -74,7 +75,7 @@ class ShutdownSampleActuatorApplicationTests {
@Bean @Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception { SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@ -35,7 +36,7 @@ public class SecurityConfig {
@Bean @Bean
public DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception { public DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
return http.csrf((csrf) -> csrf.disable()) return http.csrf(CsrfConfigurer::disable)
// Demonstrate that method security works // Demonstrate that method security works
// Best practice to use both for defense in depth // Best practice to use both for defense in depth
.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll()) .authorizeHttpRequests((requests) -> requests.anyRequest().permitAll())

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults; import static org.springframework.security.config.Customizer.withDefaults;
@ -41,7 +42,7 @@ class SecurityConfiguration {
}); });
http.formLogin(withDefaults()); http.formLogin(withDefaults());
http.httpBasic(withDefaults()); http.httpBasic(withDefaults());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults; import static org.springframework.security.config.Customizer.withDefaults;
@ -41,7 +42,7 @@ class SecurityConfiguration {
}); });
http.formLogin(withDefaults()); http.formLogin(withDefaults());
http.httpBasic(withDefaults()); http.httpBasic(withDefaults());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults; import static org.springframework.security.config.Customizer.withDefaults;
@ -41,7 +42,7 @@ class SecurityConfiguration {
}); });
http.formLogin(withDefaults()); http.formLogin(withDefaults());
http.httpBasic(withDefaults()); http.httpBasic(withDefaults());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults; import static org.springframework.security.config.Customizer.withDefaults;
@ -41,7 +42,7 @@ class SecurityConfiguration {
}); });
http.formLogin(withDefaults()); http.formLogin(withDefaults());
http.httpBasic(withDefaults()); http.httpBasic(withDefaults());
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
return http.build(); return http.build();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.annotation.Secured;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@ -75,7 +76,7 @@ public class SampleMethodSecurityApplication implements WebMvcConfigurer {
@Bean @Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception { SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.authorizeHttpRequests((requests) -> { http.authorizeHttpRequests((requests) -> {
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll(); requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
requests.anyRequest().fullyAuthenticated(); requests.anyRequest().fullyAuthenticated();
@ -94,7 +95,7 @@ public class SampleMethodSecurityApplication implements WebMvcConfigurer {
@Bean @Bean
SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception { SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.securityMatcher(EndpointRequest.toAnyEndpoint()); http.securityMatcher(EndpointRequest.toAnyEndpoint());
http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated()); http.authorizeHttpRequests((requests) -> requests.anyRequest().authenticated());
http.httpBasic(withDefaults()); http.httpBasic(withDefaults());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ -45,7 +46,7 @@ public class SampleWebSecureCustomApplication implements WebMvcConfigurer {
@Bean @Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception { SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.authorizeHttpRequests((requests) -> { http.authorizeHttpRequests((requests) -> {
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll(); requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
requests.anyRequest().fullyAuthenticated(); requests.anyRequest().fullyAuthenticated();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.provisioning.JdbcUserDetailsManager; import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@ -48,7 +49,7 @@ public class SampleWebSecureJdbcApplication implements WebMvcConfigurer {
@Bean @Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception { SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.authorizeHttpRequests((requests) -> { http.authorizeHttpRequests((requests) -> {
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll(); requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();
requests.anyRequest().fullyAuthenticated(); requests.anyRequest().fullyAuthenticated();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
@ -96,7 +97,7 @@ class SampleWebSecureApplicationTests {
@Bean @Bean
SecurityFilterChain configure(HttpSecurity http) throws Exception { SecurityFilterChain configure(HttpSecurity http) throws Exception {
http.csrf((csrf) -> csrf.disable()); http.csrf(CsrfConfigurer::disable);
http.authorizeHttpRequests((requests) -> { http.authorizeHttpRequests((requests) -> {
requests.requestMatchers("/public/**").permitAll(); requests.requestMatchers("/public/**").permitAll();
requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll(); requests.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll();