diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java index 77a6dc070f3..5b72723e1cb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,11 +16,6 @@ package org.springframework.boot.autoconfigure.couchbase; -import java.io.InputStream; -import java.net.URL; -import java.security.KeyStore; - -import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManagerFactory; import com.couchbase.client.java.Cluster; @@ -52,7 +47,6 @@ import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.util.Assert; -import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; /** @@ -134,45 +128,17 @@ public class CouchbaseAutoConfiguration { "SSL Options cannot be specified with Couchbase"); builder.securityConfig((config) -> { config.enableTls(true); - TrustManagerFactory trustManagerFactory = getTrustManagerFactory(sslProperties, sslBundle); + TrustManagerFactory trustManagerFactory = getTrustManagerFactory(sslBundle); if (trustManagerFactory != null) { config.trustManagerFactory(trustManagerFactory); } }); } - @SuppressWarnings("removal") - private TrustManagerFactory getTrustManagerFactory(CouchbaseProperties.Ssl sslProperties, SslBundle sslBundle) { - if (sslProperties.getKeyStore() != null) { - return loadTrustManagerFactory(sslProperties); - } + private TrustManagerFactory getTrustManagerFactory(SslBundle sslBundle) { return (sslBundle != null) ? sslBundle.getManagers().getTrustManagerFactory() : null; } - @SuppressWarnings("removal") - private TrustManagerFactory loadTrustManagerFactory(CouchbaseProperties.Ssl ssl) { - String resource = ssl.getKeyStore(); - try { - TrustManagerFactory trustManagerFactory = TrustManagerFactory - .getInstance(KeyManagerFactory.getDefaultAlgorithm()); - KeyStore keyStore = loadKeyStore(resource, ssl.getKeyStorePassword()); - trustManagerFactory.init(keyStore); - return trustManagerFactory; - } - catch (Exception ex) { - throw new IllegalStateException("Could not load Couchbase key store '" + resource + "'", ex); - } - } - - private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception { - KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); - URL url = ResourceUtils.getURL(resource); - try (InputStream stream = url.openStream()) { - store.load(stream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null); - } - return store; - } - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(ObjectMapper.class) static class JacksonConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java index d1e93181c57..fbe2d5878ea 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java @@ -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"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.couchbase; import java.time.Duration; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.util.StringUtils; /** @@ -149,61 +148,24 @@ public class CouchbaseProperties { public static class Ssl { /** - * Whether to enable SSL support. Enabled automatically if a "keyStore" or - * "bundle" is provided unless specified otherwise. + * Whether to enable SSL support. Enabled automatically if a "bundle" is provided + * unless specified otherwise. */ private Boolean enabled; - /** - * Path to the JVM key store that holds the certificates. - */ - private String keyStore; - - /** - * Password used to access the key store. - */ - private String keyStorePassword; - /** * SSL bundle name. */ private String bundle; public Boolean getEnabled() { - return (this.enabled != null) ? this.enabled - : StringUtils.hasText(this.keyStore) || StringUtils.hasText(this.bundle); + return (this.enabled != null) ? this.enabled : StringUtils.hasText(this.bundle); } public void setEnabled(Boolean enabled) { this.enabled = enabled; } - @Deprecated(since = "3.1.0", forRemoval = true) - @DeprecatedConfigurationProperty( - reason = "SSL bundle support with spring.ssl.bundle and spring.couchbase.env.ssl.bundle should be used instead", - since = "3.1.0") - public String getKeyStore() { - return this.keyStore; - } - - @Deprecated(since = "3.1.0", forRemoval = true) - public void setKeyStore(String keyStore) { - this.keyStore = keyStore; - } - - @Deprecated(since = "3.1.0", forRemoval = true) - @DeprecatedConfigurationProperty( - reason = "SSL bundle support with spring.ssl.bundle and spring.couchbase.env.ssl.bundle should be used instead", - since = "3.1.0") - public String getKeyStorePassword() { - return this.keyStorePassword; - } - - @Deprecated(since = "3.1.0", forRemoval = true) - public void setKeyStorePassword(String keyStorePassword) { - this.keyStorePassword = keyStorePassword; - } - public String getBundle() { return this.bundle; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java index 20085141e50..6dbf503791d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaProperties.java @@ -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"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.common.serialization.StringSerializer; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException; import org.springframework.boot.convert.DurationUnit; @@ -837,11 +836,6 @@ public class KafkaProperties { */ private List bootstrapServers; - /** - * Maximum memory size to be used for buffering across all threads. - */ - private DataSize cacheMaxSizeBuffering; - /** * Maximum size of the in-memory state store cache across all threads. */ @@ -904,18 +898,6 @@ public class KafkaProperties { this.bootstrapServers = bootstrapServers; } - @DeprecatedConfigurationProperty(replacement = "spring.kafka.streams.state-store-cache-max-size", - since = "3.1.0") - @Deprecated(since = "3.1.0", forRemoval = true) - public DataSize getCacheMaxSizeBuffering() { - return this.cacheMaxSizeBuffering; - } - - @Deprecated(since = "3.1.0", forRemoval = true) - public void setCacheMaxSizeBuffering(DataSize cacheMaxSizeBuffering) { - this.cacheMaxSizeBuffering = cacheMaxSizeBuffering; - } - public DataSize getStateStoreCacheMaxSize() { return this.stateStoreCacheMaxSize; } @@ -957,9 +939,6 @@ public class KafkaProperties { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); map.from(this::getApplicationId).to(properties.in("application.id")); map.from(this::getBootstrapServers).to(properties.in(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)); - map.from(this::getCacheMaxSizeBuffering) - .asInt(DataSize::toBytes) - .to(properties.in("cache.max.bytes.buffering")); map.from(this::getStateStoreCacheMaxSize) .asInt(DataSize::toBytes) .to(properties.in("statestore.cache.max.bytes")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java deleted file mode 100644 index 691064cd5e6..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.mongo; - -import java.util.ArrayList; -import java.util.List; - -import com.mongodb.ConnectionString; -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; - -import org.springframework.core.Ordered; -import org.springframework.util.CollectionUtils; - -/** - * A {@link MongoClientSettingsBuilderCustomizer} that applies properties from a - * {@link MongoProperties} to a {@link MongoClientSettings}. - * - * @author Scott Frederick - * @author Safeer Ansari - * @since 2.4.0 - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of - * {@link StandardMongoClientSettingsBuilderCustomizer} - */ -@Deprecated(since = "3.1.0", forRemoval = true) -public class MongoPropertiesClientSettingsBuilderCustomizer implements MongoClientSettingsBuilderCustomizer, Ordered { - - private final MongoProperties properties; - - private int order = 0; - - public MongoPropertiesClientSettingsBuilderCustomizer(MongoProperties properties) { - this.properties = properties; - } - - @Override - public void customize(MongoClientSettings.Builder settingsBuilder) { - applyUuidRepresentation(settingsBuilder); - applyHostAndPort(settingsBuilder); - applyCredentials(settingsBuilder); - applyReplicaSet(settingsBuilder); - } - - private void applyUuidRepresentation(MongoClientSettings.Builder settingsBuilder) { - settingsBuilder.uuidRepresentation(this.properties.getUuidRepresentation()); - } - - private void applyHostAndPort(MongoClientSettings.Builder settings) { - if (this.properties.getUri() != null) { - settings.applyConnectionString(new ConnectionString(this.properties.getUri())); - return; - } - if (this.properties.getHost() != null || this.properties.getPort() != null) { - String host = getOrDefault(this.properties.getHost(), "localhost"); - int port = getOrDefault(this.properties.getPort(), MongoProperties.DEFAULT_PORT); - List serverAddresses = new ArrayList<>(); - serverAddresses.add(new ServerAddress(host, port)); - if (!CollectionUtils.isEmpty(this.properties.getAdditionalHosts())) { - this.properties.getAdditionalHosts().stream().map(ServerAddress::new).forEach(serverAddresses::add); - } - settings.applyToClusterSettings((cluster) -> cluster.hosts(serverAddresses)); - return; - } - settings.applyConnectionString(new ConnectionString(MongoProperties.DEFAULT_URI)); - } - - private void applyCredentials(MongoClientSettings.Builder builder) { - if (this.properties.getUri() == null && this.properties.getUsername() != null - && this.properties.getPassword() != null) { - String database = (this.properties.getAuthenticationDatabase() != null) - ? this.properties.getAuthenticationDatabase() : this.properties.getMongoClientDatabase(); - builder.credential((MongoCredential.createCredential(this.properties.getUsername(), database, - this.properties.getPassword()))); - } - } - - private void applyReplicaSet(MongoClientSettings.Builder builder) { - if (this.properties.getReplicaSetName() != null) { - builder.applyToClusterSettings( - (cluster) -> cluster.requiredReplicaSetName(this.properties.getReplicaSetName())); - } - } - - private V getOrDefault(V value, V defaultValue) { - return (value != null) ? value : defaultValue; - } - - @Override - public int getOrder() { - return this.order; - } - - /** - * Set the order value of this object. - * @param order the new order value - * @see #getOrder() - */ - public void setOrder(int order) { - this.order = order; - } - -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java deleted file mode 100644 index 343f511caf8..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.security.oauth2.client; - -import java.util.Map; - -import org.springframework.security.oauth2.client.registration.ClientRegistration; - -/** - * Adapter class to convert {@link OAuth2ClientProperties} to a - * {@link ClientRegistration}. - * - * @author Phillip Webb - * @author Thiago Hirata - * @author Madhura Bhave - * @author MyeongHyeon Lee - * @since 2.1.0 - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of - * {@link OAuth2ClientPropertiesMapper} - */ -@Deprecated(since = "3.1.0", forRemoval = true) -public final class OAuth2ClientPropertiesRegistrationAdapter { - - private OAuth2ClientPropertiesRegistrationAdapter() { - } - - public static Map getClientRegistrations(OAuth2ClientProperties properties) { - return new OAuth2ClientPropertiesMapper(properties).asClientRegistrations(); - } - -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 9308b0862e9..c61b327b6ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -670,6 +670,26 @@ "level": "error" } }, + { + "name": "spring.couchbase.env.ssl.key-store", + "type": "java.lang.String", + "description": "Path to the JVM key store that holds the certificates.", + "deprecation": { + "replacement": "spring.couchbase.env.ssl.bundle", + "level": "error", + "since": "3.1.0" + } + }, + { + "name": "spring.couchbase.env.ssl.key-store-password", + "type": "java.lang.String", + "description": "Password used to access the key store.", + "deprecation": { + "replacement": "spring.couchbase.env.ssl.bundle", + "level": "error", + "since": "3.1.0" + } + }, { "name": "spring.couchbase.env.timeouts.socket-connect", "type": "java.time.Duration", @@ -1901,10 +1921,19 @@ "name": "spring.kafka.streams.cache-max-bytes-buffering", "type": "java.lang.Integer", "deprecation": { - "replacement": "spring.kafka.streams.cache-max-size-buffering", + "replacement": "spring.kafka.streams.state-store-cache-max-size", "level": "error" } }, + { + "name": "spring.kafka.streams.cache-max-size-buffering", + "type": "java.lang.Integer", + "deprecation": { + "replacement": "spring.kafka.streams.state-store-cache-max-size", + "level": "error", + "since": "3.1.0" + } + }, { "name": "spring.liquibase.check-change-log-location", "type": "java.lang.Boolean", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java index c76ea994d6c..6b38551d5f8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java @@ -189,15 +189,6 @@ class CouchbaseAutoConfigurationTests { }, "spring.couchbase.env.ssl.enabled=true"); } - @Test - void enableSslWithKeyStore() { - testClusterEnvironment((env) -> { - SecurityConfig securityConfig = env.securityConfig(); - assertThat(securityConfig.tlsEnabled()).isTrue(); - assertThat(securityConfig.trustManagerFactory()).isNotNull(); - }, "spring.couchbase.env.ssl.keyStore=classpath:test.jks", "spring.couchbase.env.ssl.keyStorePassword=secret"); - } - @Test void enableSslWithBundle() { testClusterEnvironment((env) -> { @@ -222,16 +213,6 @@ class CouchbaseAutoConfigurationTests { }); } - @Test - void disableSslEvenWithKeyStore() { - testClusterEnvironment((env) -> { - SecurityConfig securityConfig = env.securityConfig(); - assertThat(securityConfig.tlsEnabled()).isFalse(); - assertThat(securityConfig.trustManagerFactory()).isNull(); - }, "spring.couchbase.env.ssl.enabled=false", "spring.couchbase.env.ssl.keyStore=classpath:test.jks", - "spring.couchbase.env.ssl.keyStorePassword=secret"); - } - @Test void disableSslEvenWithBundle() { testClusterEnvironment((env) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index 4adc774e8d7..56b627bd835 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -396,20 +396,6 @@ class KafkaAutoConfigurationTests { }); } - @SuppressWarnings("deprecation") - @Deprecated(since = "3.1.0", forRemoval = true) - void streamsCacheMaxSizeBuffering() { - this.contextRunner.withUserConfiguration(EnableKafkaStreamsConfiguration.class) - .withPropertyValues("spring.kafka.streams.cache-max-size-buffering=1KB") - .run((context) -> { - Properties configs = context - .getBean(KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME, - KafkaStreamsConfiguration.class) - .asProperties(); - assertThat(configs).containsEntry(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 1024); - }); - } - @SuppressWarnings("unchecked") @Test void streamsApplicationIdUsesMainApplicationNameByDefault() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java deleted file mode 100644 index 021d298523c..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizerTests.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.mongo; - -import java.util.Arrays; -import java.util.List; - -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import org.bson.UuidRepresentation; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link MongoPropertiesClientSettingsBuilderCustomizer}. - * - * @author Scott Frederick - */ -@Deprecated(since = "3.1.0", forRemoval = true) -class MongoPropertiesClientSettingsBuilderCustomizerTests { - - private final MongoProperties properties = new MongoProperties(); - - @Test - void portCanBeCustomized() { - this.properties.setPort(12345); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "localhost", 12345); - } - - @Test - void hostCanBeCustomized() { - this.properties.setHost("mongo.example.com"); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "mongo.example.com", 27017); - } - - @Test - void additionalHostCanBeAdded() { - this.properties.setHost("mongo.example.com"); - this.properties.setAdditionalHosts(Arrays.asList("mongo.example.com:33", "mongo.example2.com")); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(3); - assertServerAddress(allAddresses.get(0), "mongo.example.com", 27017); - assertServerAddress(allAddresses.get(1), "mongo.example.com", 33); - assertServerAddress(allAddresses.get(2), "mongo.example2.com", 27017); - } - - @Test - void credentialsCanBeCustomized() { - this.properties.setUsername("user"); - this.properties.setPassword("secret".toCharArray()); - MongoClientSettings settings = customizeSettings(); - assertMongoCredential(settings.getCredential(), "user", "secret", "test"); - } - - @Test - void replicaSetCanBeCustomized() { - this.properties.setReplicaSetName("test"); - MongoClientSettings settings = customizeSettings(); - assertThat(settings.getClusterSettings().getRequiredReplicaSetName()).isEqualTo("test"); - } - - @Test - void databaseCanBeCustomized() { - this.properties.setDatabase("foo"); - this.properties.setUsername("user"); - this.properties.setPassword("secret".toCharArray()); - MongoClientSettings settings = customizeSettings(); - assertMongoCredential(settings.getCredential(), "user", "secret", "foo"); - } - - @Test - void uuidRepresentationDefaultToJavaLegacy() { - MongoClientSettings settings = customizeSettings(); - assertThat(settings.getUuidRepresentation()).isEqualTo(UuidRepresentation.JAVA_LEGACY); - } - - @Test - void uuidRepresentationCanBeCustomized() { - this.properties.setUuidRepresentation(UuidRepresentation.STANDARD); - MongoClientSettings settings = customizeSettings(); - assertThat(settings.getUuidRepresentation()).isEqualTo(UuidRepresentation.STANDARD); - } - - @Test - void authenticationDatabaseCanBeCustomized() { - this.properties.setAuthenticationDatabase("foo"); - this.properties.setUsername("user"); - this.properties.setPassword("secret".toCharArray()); - MongoClientSettings settings = customizeSettings(); - assertMongoCredential(settings.getCredential(), "user", "secret", "foo"); - } - - @Test - void onlyHostAndPortSetShouldUseThat() { - this.properties.setHost("localhost"); - this.properties.setPort(27017); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "localhost", 27017); - } - - @Test - void onlyUriSetShouldUseThat() { - this.properties.setUri("mongodb://mongo1.example.com:12345"); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345); - } - - @Test - void noCustomAddressAndNoUriUsesDefaultUri() { - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "localhost", 27017); - } - - @Test - void uriCanBeCustomized() { - this.properties.setUri("mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test"); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(2); - assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345); - assertServerAddress(allAddresses.get(1), "mongo2.example.com", 23456); - assertMongoCredential(settings.getCredential(), "user", "secret", "test"); - } - - @Test - void uriOverridesUsernameAndPassword() { - this.properties.setUri("mongodb://127.0.0.1:1234/mydb"); - this.properties.setUsername("user"); - this.properties.setPassword("secret".toCharArray()); - MongoClientSettings settings = customizeSettings(); - assertThat(settings.getCredential()).isNull(); - } - - @Test - void uriOverridesDatabase() { - this.properties.setUri("mongodb://secret:password@127.0.0.1:1234/mydb"); - this.properties.setDatabase("test"); - MongoClientSettings settings = customizeSettings(); - List allAddresses = getAllAddresses(settings); - assertThat(allAddresses).hasSize(1); - assertServerAddress(allAddresses.get(0), "127.0.0.1", 1234); - assertThat(settings.getCredential().getSource()).isEqualTo("mydb"); - } - - @Test - void uriOverridesHostAndPort() { - this.properties.setUri("mongodb://127.0.0.1:1234/mydb"); - this.properties.setHost("localhost"); - this.properties.setPort(4567); - MongoClientSettings settings = customizeSettings(); - List addresses = getAllAddresses(settings); - assertThat(addresses.get(0).getHost()).isEqualTo("127.0.0.1"); - assertThat(addresses.get(0).getPort()).isEqualTo(1234); - } - - @Test - void retryWritesIsPropagatedFromUri() { - this.properties.setUri("mongodb://localhost/test?retryWrites=false"); - MongoClientSettings settings = customizeSettings(); - assertThat(settings.getRetryWrites()).isFalse(); - } - - @SuppressWarnings("removal") - private MongoClientSettings customizeSettings() { - MongoClientSettings.Builder settings = MongoClientSettings.builder(); - new MongoPropertiesClientSettingsBuilderCustomizer(this.properties).customize(settings); - return settings.build(); - } - - private List getAllAddresses(MongoClientSettings settings) { - return settings.getClusterSettings().getHosts(); - } - - protected void assertServerAddress(ServerAddress serverAddress, String expectedHost, int expectedPort) { - assertThat(serverAddress.getHost()).isEqualTo(expectedHost); - assertThat(serverAddress.getPort()).isEqualTo(expectedPort); - } - - protected void assertMongoCredential(MongoCredential credentials, String expectedUsername, String expectedPassword, - String expectedSource) { - assertThat(credentials.getUserName()).isEqualTo(expectedUsername); - assertThat(credentials.getPassword()).isEqualTo(expectedPassword.toCharArray()); - assertThat(credentials.getSource()).isEqualTo(expectedSource); - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java index 3fa38d84391..a74701d8e77 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java @@ -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"); * you may not use this file except in compliance with the License. @@ -100,17 +100,6 @@ public final class ConfigurationPropertiesBean { return this.bindTarget.getType().resolve(); } - /** - * Return the property binding method that was used for the bean. - * @return the bind method - * @deprecated since 3.0.8 for removal in 3.3.0 in favor of {@link #asBindTarget} and - * {@link Bindable#getBindMethod} - */ - @Deprecated(since = "3.0.8", forRemoval = true) - public BindMethod getBindMethod() { - return BindMethod.from(this.bindTarget.getBindMethod()); - } - /** * Return the {@link ConfigurationProperties} annotation for the bean. The annotation * may be defined on the bean itself or from the factory method that create the bean @@ -312,35 +301,4 @@ public final class ConfigurationPropertiesBean { return (bindConstructor != null) ? VALUE_OBJECT_BIND_METHOD : JAVA_BEAN_BIND_METHOD; } - /** - * The binding method that is used for the bean. - * - * @deprecated since 3.0.8 for removal in 3.3.0 in favor of - * {@link org.springframework.boot.context.properties.bind.BindMethod} - */ - @Deprecated(since = "3.0.8", forRemoval = true) - public enum BindMethod { - - /** - * Java Bean using getter/setter binding. - */ - JAVA_BEAN, - - /** - * Value object using constructor binding. - */ - VALUE_OBJECT; - - static BindMethod from(org.springframework.boot.context.properties.bind.BindMethod bindMethod) { - if (bindMethod == null) { - return null; - } - return switch (bindMethod) { - case VALUE_OBJECT -> BindMethod.VALUE_OBJECT; - case JAVA_BEAN -> BindMethod.JAVA_BEAN; - }; - } - - } - } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java index 573cdf48c48..0ef89b5ffcf 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,15 +16,11 @@ package org.springframework.boot.jdbc; -import java.sql.DatabaseMetaData; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Locale; -import javax.sql.DataSource; - -import org.springframework.jdbc.support.JdbcUtils; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -315,23 +311,4 @@ public enum DatabaseDriver { return UNKNOWN; } - /** - * Find a {@link DatabaseDriver} for the given {@code DataSource}. - * @param dataSource data source to inspect - * @return the database driver of {@link #UNKNOWN} if not found - * @since 2.6.0 - * @deprecated since 2.7.15 for removal in 3.3.0 with no replacement - */ - @Deprecated(since = "2.7.15", forRemoval = true) - public static DatabaseDriver fromDataSource(DataSource dataSource) { - try { - String productName = JdbcUtils.commonDatabaseName( - JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName)); - return DatabaseDriver.fromProductName(productName); - } - catch (Exception ex) { - return DatabaseDriver.UNKNOWN; - } - } - } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactory.java index e291716cac7..06840ac2ee4 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactory.java @@ -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"); * you may not use this file except in compliance with the License. @@ -43,7 +43,6 @@ import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.ssl.SslBundles; import org.springframework.boot.web.embedded.netty.SslServerCustomizer; import org.springframework.boot.web.server.Ssl; -import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.boot.web.server.WebServerSslBundle; import org.springframework.http.client.ReactorResourceFactory; import org.springframework.util.Assert; @@ -58,7 +57,6 @@ import org.springframework.util.unit.DataSize; * @author Scott Frederick * @since 2.2.0 */ -@SuppressWarnings("removal") public class NettyRSocketServerFactory implements RSocketServerFactory, ConfigurableRSocketServerFactory { private int port = 9898; @@ -77,8 +75,6 @@ public class NettyRSocketServerFactory implements RSocketServerFactory, Configur private Ssl ssl; - private SslStoreProvider sslStoreProvider; - private SslBundles sslBundles; @Override @@ -106,11 +102,6 @@ public class NettyRSocketServerFactory implements RSocketServerFactory, Configur this.ssl = ssl; } - @Override - public void setSslStoreProvider(SslStoreProvider sslStoreProvider) { - this.sslStoreProvider = sslStoreProvider; - } - @Override public void setSslBundles(SslBundles sslBundles) { this.sslBundles = sslBundles; @@ -204,9 +195,8 @@ public class NettyRSocketServerFactory implements RSocketServerFactory, Configur return TcpServerTransport.create(tcpServer.bindAddress(this::getListenAddress)); } - @SuppressWarnings("deprecation") private SslBundle getSslBundle() { - return WebServerSslBundle.get(this.ssl, this.sslBundles, this.sslStoreProvider); + return WebServerSslBundle.get(this.ssl, this.sslBundles); } private InetSocketAddress getListenAddress() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/ConfigurableRSocketServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/ConfigurableRSocketServerFactory.java index eb48a9ef475..671d4bea200 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/ConfigurableRSocketServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/server/ConfigurableRSocketServerFactory.java @@ -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"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.net.InetAddress; import org.springframework.boot.ssl.SslBundles; import org.springframework.boot.web.server.Ssl; -import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.util.unit.DataSize; /** @@ -65,16 +64,6 @@ public interface ConfigurableRSocketServerFactory { */ void setSsl(Ssl ssl); - /** - * Sets a provider that will be used to obtain SSL stores. - * @param sslStoreProvider the SSL store provider - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of - * {@link #setSslBundles(SslBundles)} - */ - @SuppressWarnings("removal") - @Deprecated(since = "3.1.0", forRemoval = true) - void setSslStoreProvider(SslStoreProvider sslStoreProvider); - /** * Sets an SSL bundle that can be used to get SSL configuration. * @param sslBundles the SSL bundles diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java index 21fa14527ae..b77b4f56c26 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java @@ -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"); * you may not use this file except in compliance with the License. @@ -51,9 +51,6 @@ public abstract class AbstractConfigurableWebServerFactory implements Configurab private Ssl ssl; - @SuppressWarnings("removal") - private SslStoreProvider sslStoreProvider; - private SslBundles sslBundles; private Http2 http2; @@ -135,17 +132,6 @@ public abstract class AbstractConfigurableWebServerFactory implements Configurab this.ssl = ssl; } - @SuppressWarnings("removal") - public SslStoreProvider getSslStoreProvider() { - return this.sslStoreProvider; - } - - @Override - @SuppressWarnings("removal") - public void setSslStoreProvider(SslStoreProvider sslStoreProvider) { - this.sslStoreProvider = sslStoreProvider; - } - /** * Return the configured {@link SslBundles}. * @return the {@link SslBundles} or {@code null} @@ -201,28 +187,12 @@ public abstract class AbstractConfigurableWebServerFactory implements Configurab return this.shutdown; } - /** - * Return the provided {@link SslStoreProvider} or create one using {@link Ssl} - * properties. - * @return the {@code SslStoreProvider} - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of {@link #getSslBundle()} - */ - @Deprecated(since = "3.1.0", forRemoval = true) - @SuppressWarnings("removal") - public final SslStoreProvider getOrCreateSslStoreProvider() { - if (this.sslStoreProvider != null) { - return this.sslStoreProvider; - } - return CertificateFileSslStoreProvider.from(this.ssl); - } - /** * Return the {@link SslBundle} that should be used with this server. * @return the SSL bundle */ - @SuppressWarnings("removal") protected final SslBundle getSslBundle() { - return WebServerSslBundle.get(this.ssl, this.sslBundles, this.sslStoreProvider); + return WebServerSslBundle.get(this.ssl, this.sslBundles); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/CertificateFileSslStoreProvider.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/CertificateFileSslStoreProvider.java deleted file mode 100644 index d3ed1a091ed..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/CertificateFileSslStoreProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.web.server; - -import java.security.KeyStore; - -import org.springframework.boot.ssl.SslBundle; -import org.springframework.boot.ssl.pem.PemSslStoreBundle; - -/** - * An {@link SslStoreProvider} that creates key and trust stores from certificate and - * private key PEM files. - * - * @author Scott Frederick - * @since 2.7.0 - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of registering a - * {@link SslBundle} backed by a {@link PemSslStoreBundle}. - */ -@Deprecated(since = "3.1.0", forRemoval = true) -@SuppressWarnings({ "deprecation", "removal" }) -public final class CertificateFileSslStoreProvider implements SslStoreProvider { - - private final SslBundle delegate; - - private CertificateFileSslStoreProvider(SslBundle delegate) { - this.delegate = delegate; - } - - @Override - public KeyStore getKeyStore() throws Exception { - return this.delegate.getStores().getKeyStore(); - } - - @Override - public KeyStore getTrustStore() throws Exception { - return this.delegate.getStores().getTrustStore(); - } - - @Override - public String getKeyPassword() { - return this.delegate.getKey().getPassword(); - } - - /** - * Create an {@link SslStoreProvider} if the appropriate SSL properties are - * configured. - * @param ssl the SSL properties - * @return an {@code SslStoreProvider} or {@code null} - */ - public static SslStoreProvider from(Ssl ssl) { - SslBundle delegate = WebServerSslBundle.createCertificateFileSslStoreProviderDelegate(ssl); - return (delegate != null) ? new CertificateFileSslStoreProvider(delegate) : null; - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java index c10580aa3dd..bc90e66b760 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java @@ -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"); * you may not use this file except in compliance with the License. @@ -58,16 +58,6 @@ public interface ConfigurableWebServerFactory extends WebServerFactory, ErrorPag */ void setSsl(Ssl ssl); - /** - * Sets a provider that will be used to obtain SSL stores. - * @param sslStoreProvider the SSL store provider - * @deprecated since 3.1.0 for removal in 3.3.0, in favor of - * {@link #setSslBundles(SslBundles)} - */ - @Deprecated(since = "3.1.0", forRemoval = true) - @SuppressWarnings("removal") - void setSslStoreProvider(SslStoreProvider sslStoreProvider); - /** * Sets the SSL bundles that can be used to configure SSL connections. * @param sslBundles the SSL bundles diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslConfigurationValidator.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslConfigurationValidator.java deleted file mode 100644 index d044dfa29dc..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslConfigurationValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.web.server; - -import java.security.KeyStore; - -import org.springframework.boot.ssl.SslBundleKey; - -/** - * Provides utilities around SSL. - * - * @author Chris Bono - * @since 2.1.13 - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of - * {@link SslBundleKey#assertContainsAlias(KeyStore)} - */ -@Deprecated(since = "3.1.0", forRemoval = true) -public final class SslConfigurationValidator { - - private SslConfigurationValidator() { - } - - public static void validateKeyAlias(KeyStore keyStore, String keyAlias) { - SslBundleKey.of(null, keyAlias).assertContainsAlias(keyStore); - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java deleted file mode 100644 index 31f2de86de6..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.web.server; - -import java.security.KeyStore; - -import org.springframework.boot.ssl.SslBundle; - -/** - * Interface to provide SSL key stores for an {@link WebServer} to use. Can be used when - * file based key stores cannot be used. - * - * @author Phillip Webb - * @since 2.0.0 - * @deprecated since 3.1.0 for removal in 3.3.0 in favor of registering an - * {@link SslBundle}. - */ -@Deprecated(since = "3.1.0", forRemoval = true) -public interface SslStoreProvider { - - /** - * Return the key store that should be used. - * @return the key store to use - * @throws Exception on load error - */ - KeyStore getKeyStore() throws Exception; - - /** - * Return the trust store that should be used. - * @return the trust store to use - * @throws Exception on load error - */ - KeyStore getTrustStore() throws Exception; - - /** - * Return the password of the private key in the key store. - * @return the key password - * @since 2.7.2 - */ - default String getKeyPassword() { - return null; - } - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java index adcff6722b0..f5e6f448b74 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerSslBundle.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.boot.web.server; -import java.security.KeyStore; - import org.springframework.boot.ssl.NoSuchSslBundleException; import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.ssl.SslBundleKey; @@ -31,10 +29,9 @@ import org.springframework.boot.ssl.pem.PemSslStoreBundle; import org.springframework.boot.ssl.pem.PemSslStoreDetails; import org.springframework.util.Assert; import org.springframework.util.StringUtils; -import org.springframework.util.function.ThrowingSupplier; /** - * {@link SslBundle} backed by {@link Ssl} or an {@link SslStoreProvider}. + * {@link SslBundle} backed by {@link Ssl}. * * @author Scott Frederick * @author Phillip Webb @@ -109,7 +106,7 @@ public final class WebServerSslBundle implements SslBundle { * @throws NoSuchSslBundleException if a bundle lookup fails */ public static SslBundle get(Ssl ssl) throws NoSuchSslBundleException { - return get(ssl, null, null); + return get(ssl, null); } /** @@ -121,30 +118,8 @@ public final class WebServerSslBundle implements SslBundle { * @throws NoSuchSslBundleException if a bundle lookup fails */ public static SslBundle get(Ssl ssl, SslBundles sslBundles) throws NoSuchSslBundleException { - return get(ssl, sslBundles, null); - } - - /** - * Get the {@link SslBundle} that should be used for the given {@link Ssl} and - * {@link SslStoreProvider} instances. - * @param ssl the source {@link Ssl} instance - * @param sslBundles the bundles that should be used when {@link Ssl#getBundle()} is - * set - * @param sslStoreProvider the {@link SslStoreProvider} to use or {@code null} - * @return a {@link SslBundle} instance - * @throws NoSuchSslBundleException if a bundle lookup fails - * @deprecated since 3.1.0 for removal in 3.3.0 along with {@link SslStoreProvider} - */ - @Deprecated(since = "3.1.0", forRemoval = true) - @SuppressWarnings("removal") - public static SslBundle get(Ssl ssl, SslBundles sslBundles, SslStoreProvider sslStoreProvider) { Assert.state(Ssl.isEnabled(ssl), "SSL is not enabled"); - String keyPassword = (sslStoreProvider != null) ? sslStoreProvider.getKeyPassword() : null; - keyPassword = (keyPassword != null) ? keyPassword : ssl.getKeyPassword(); - if (sslStoreProvider != null) { - SslStoreBundle stores = new SslStoreProviderBundleAdapter(sslStoreProvider); - return new WebServerSslBundle(stores, keyPassword, ssl); - } + String keyPassword = ssl.getKeyPassword(); String bundleName = ssl.getBundle(); if (StringUtils.hasText(bundleName)) { Assert.state(sslBundles != null, @@ -183,33 +158,4 @@ public final class WebServerSslBundle implements SslBundle { || (ssl.getKeyStoreType() != null && ssl.getKeyStoreType().equals("PKCS11")); } - /** - * Class to adapt a {@link SslStoreProvider} into a {@link SslStoreBundle}. - */ - @SuppressWarnings("removal") - private static class SslStoreProviderBundleAdapter implements SslStoreBundle { - - private final SslStoreProvider sslStoreProvider; - - SslStoreProviderBundleAdapter(SslStoreProvider sslStoreProvider) { - this.sslStoreProvider = sslStoreProvider; - } - - @Override - public KeyStore getKeyStore() { - return ThrowingSupplier.of(this.sslStoreProvider::getKeyStore).get(); - } - - @Override - public String getKeyStorePassword() { - return null; - } - - @Override - public KeyStore getTrustStore() { - return ThrowingSupplier.of(this.sslStoreProvider::getTrustStore).get(); - } - - } - } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java index a845ffb1e7e..0c1545b258a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,42 +16,26 @@ package org.springframework.boot.web.embedded.tomcat; -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.util.Set; - -import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tomcat.util.net.SSLHostConfig; -import org.apache.tomcat.util.net.SSLHostConfigCertificate; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.testsupport.system.CapturedOutput; import org.springframework.boot.testsupport.system.OutputCaptureExtension; import org.springframework.boot.testsupport.web.servlet.DirtiesUrlFactories; import org.springframework.boot.web.embedded.test.MockPkcs11Security; import org.springframework.boot.web.embedded.test.MockPkcs11SecurityProvider; import org.springframework.boot.web.server.Ssl; -import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.boot.web.server.WebServerSslBundle; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatNoException; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; /** * Tests for {@link SslConnectorCustomizer} @@ -61,7 +45,6 @@ import static org.mockito.Mockito.mock; * @author Scott Frederick * @author Cyril Dangerville */ -@SuppressWarnings("removal") @ExtendWith(OutputCaptureExtension.class) @DirtiesUrlFactories @MockPkcs11Security @@ -131,62 +114,6 @@ class SslConnectorCustomizerTests { assertThat(sslHostConfig.getEnabledProtocols()).containsExactly("TLSv1.2"); } - @Test - @Deprecated(since = "3.1.0", forRemoval = true) - void customizeWhenSslStoreProviderProvidesOnlyKeyStoreShouldUseDefaultTruststore() throws Exception { - Ssl ssl = new Ssl(); - ssl.setKeyPassword("password"); - ssl.setTrustStore("src/test/resources/test.jks"); - SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class); - KeyStore keyStore = loadStore(); - given(sslStoreProvider.getKeyStore()).willReturn(keyStore); - Connector connector = this.tomcat.getConnector(); - SslConnectorCustomizer customizer = new SslConnectorCustomizer(this.logger, connector, ssl.getClientAuth()); - customizer.customize(WebServerSslBundle.get(ssl, null, sslStoreProvider)); - this.tomcat.start(); - SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0]; - SSLHostConfig sslHostConfigWithDefaults = new SSLHostConfig(); - assertThat(sslHostConfig.getTruststoreFile()).isEqualTo(sslHostConfigWithDefaults.getTruststoreFile()); - Set certificates = sslHostConfig.getCertificates(); - assertThat(certificates).hasSize(1); - assertThat(certificates.iterator().next().getCertificateKeystore()).isEqualTo(keyStore); - } - - @Test - @Deprecated(since = "3.1.0", forRemoval = true) - void customizeWhenSslStoreProviderProvidesOnlyTrustStoreShouldUseDefaultKeystore() throws Exception { - Ssl ssl = new Ssl(); - ssl.setKeyPassword("password"); - ssl.setKeyStore("src/test/resources/test.jks"); - SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class); - KeyStore trustStore = loadStore(); - given(sslStoreProvider.getTrustStore()).willReturn(trustStore); - Connector connector = this.tomcat.getConnector(); - SslConnectorCustomizer customizer = new SslConnectorCustomizer(this.logger, connector, ssl.getClientAuth()); - customizer.customize(WebServerSslBundle.get(ssl, null, sslStoreProvider)); - this.tomcat.start(); - SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0]; - assertThat(sslHostConfig.getTruststore()).isEqualTo(trustStore); - } - - @Test - @Deprecated(since = "3.1.0", forRemoval = true) - void customizeWhenSslStoreProviderPresentShouldIgnorePasswordFromSsl(CapturedOutput output) throws Exception { - System.setProperty("javax.net.ssl.trustStorePassword", "trustStoreSecret"); - Ssl ssl = new Ssl(); - ssl.setKeyPassword("password"); - ssl.setKeyStorePassword("secret"); - SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class); - given(sslStoreProvider.getTrustStore()).willReturn(loadStore()); - given(sslStoreProvider.getKeyStore()).willReturn(loadStore()); - Connector connector = this.tomcat.getConnector(); - SslConnectorCustomizer customizer = new SslConnectorCustomizer(this.logger, connector, ssl.getClientAuth()); - customizer.customize(WebServerSslBundle.get(ssl, null, sslStoreProvider)); - this.tomcat.start(); - assertThat(connector.getState()).isEqualTo(LifecycleState.STARTED); - assertThat(output).doesNotContain("Password verification failed"); - } - @Test void customizeWhenSslIsEnabledWithNoKeyStoreAndNotPkcs11ThrowsException() { assertThatIllegalStateException().isThrownBy(() -> { @@ -221,13 +148,4 @@ class SslConnectorCustomizerTests { assertThatNoException().isThrownBy(() -> customizer.customize(WebServerSslBundle.get(ssl))); } - private KeyStore loadStore() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { - KeyStore keyStore = KeyStore.getInstance("JKS"); - Resource resource = new ClassPathResource("test.jks"); - try (InputStream stream = resource.getInputStream()) { - keyStore.load(stream, "secret".toCharArray()); - return keyStore; - } - } - } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/SslConfigurationValidatorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/SslConfigurationValidatorTests.java deleted file mode 100644 index df969774796..00000000000 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/SslConfigurationValidatorTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.web.server; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.KeyStoreException; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; - -/** - * Tests for {@link SslConfigurationValidator}. - * - * @author Chris Bono - */ -@SuppressWarnings("removal") -@Deprecated(since = "3.1.0", forRemoval = true) -class SslConfigurationValidatorTests { - - private static final String VALID_ALIAS = "test-alias"; - - private static final String INVALID_ALIAS = "test-alias-5150"; - - private KeyStore keyStore; - - @BeforeEach - void loadKeystore() throws Exception { - this.keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - try (InputStream stream = new FileInputStream("src/test/resources/test.jks")) { - this.keyStore.load(stream, "secret".toCharArray()); - } - } - - @Test - void validateKeyAliasWhenAliasFoundShouldNotFail() { - SslConfigurationValidator.validateKeyAlias(this.keyStore, VALID_ALIAS); - } - - @Test - void validateKeyAliasWhenNullAliasShouldNotFail() { - SslConfigurationValidator.validateKeyAlias(this.keyStore, null); - } - - @Test - void validateKeyAliasWhenEmptyAliasShouldNotFail() { - SslConfigurationValidator.validateKeyAlias(this.keyStore, ""); - } - - @Test - void validateKeyAliasWhenAliasNotFoundShouldThrowException() { - assertThatIllegalStateException() - .isThrownBy(() -> SslConfigurationValidator.validateKeyAlias(this.keyStore, INVALID_ALIAS)) - .withMessage("Keystore does not contain alias '" + INVALID_ALIAS + "'"); - } - - @Test - void validateKeyAliasWhenKeyStoreThrowsExceptionOnContains() throws KeyStoreException { - KeyStore uninitializedKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - assertThatIllegalStateException() - .isThrownBy(() -> SslConfigurationValidator.validateKeyAlias(uninitializedKeyStore, "alias")) - .withMessage("Could not determine if keystore contains alias 'alias'"); - } - -} diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/WebServerSslBundleTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/WebServerSslBundleTests.java index c6a22a22fa8..66ce3353d39 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/WebServerSslBundleTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/WebServerSslBundleTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,9 +16,6 @@ package org.springframework.boot.web.server; -import java.io.InputStream; -import java.security.KeyStore; - import org.junit.jupiter.api.Test; import org.springframework.boot.ssl.SslBundle; @@ -27,13 +24,9 @@ import org.springframework.boot.ssl.SslOptions; import org.springframework.boot.ssl.SslStoreBundle; import org.springframework.boot.web.embedded.test.MockPkcs11Security; import org.springframework.boot.web.embedded.test.MockPkcs11SecurityProvider; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; /** * Tests for {@link WebServerSslBundle}. @@ -122,35 +115,6 @@ class WebServerSslBundleTests { assertThat(options.getEnabledProtocols()).containsExactly("TLSv1.1", "TLSv1.2"); } - @Test - @Deprecated(since = "3.1.0", forRemoval = true) - @SuppressWarnings("removal") - void whenFromCustomSslStoreProvider() throws Exception { - SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class); - KeyStore keyStore = loadStore(); - given(sslStoreProvider.getKeyStore()).willReturn(keyStore); - given(sslStoreProvider.getTrustStore()).willReturn(keyStore); - Ssl ssl = new Ssl(); - ssl.setKeyStoreType("PKCS12"); - ssl.setTrustStoreType("PKCS12"); - ssl.setKeyPassword("password"); - ssl.setClientAuth(Ssl.ClientAuth.NONE); - ssl.setCiphers(new String[] { "ONE", "TWO", "THREE" }); - ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" }); - ssl.setProtocol("TLSv1.1"); - SslBundle bundle = WebServerSslBundle.get(ssl, null, sslStoreProvider); - assertThat(bundle).isNotNull(); - SslBundleKey key = bundle.getKey(); - assertThat(key.getPassword()).isEqualTo("password"); - assertThat(key.getAlias()).isNull(); - SslStoreBundle stores = bundle.getStores(); - assertThat(stores.getKeyStore()).isNotNull(); - assertThat(stores.getTrustStore()).isNotNull(); - SslOptions options = bundle.getOptions(); - assertThat(options.getCiphers()).containsExactly("ONE", "TWO", "THREE"); - assertThat(options.getEnabledProtocols()).containsExactly("TLSv1.1", "TLSv1.2"); - } - @Test void whenMissingPropertiesThrowsException() { Ssl ssl = new Ssl(); @@ -158,13 +122,4 @@ class WebServerSslBundleTests { .withMessageContaining("SSL is enabled but no trust material is configured"); } - private KeyStore loadStore() throws Exception { - Resource resource = new ClassPathResource("test.p12"); - try (InputStream stream = resource.getInputStream()) { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - keyStore.load(stream, "secret".toCharArray()); - return keyStore; - } - } - } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index 37ea7ad293e..6db36575b5b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -30,7 +30,6 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.KeyStore; -import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; @@ -134,14 +133,12 @@ import org.springframework.boot.web.server.PortInUseException; import org.springframework.boot.web.server.Shutdown; import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl.ClientAuth; -import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServerException; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.server.Session.SessionTrackingMode; -import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpMethod; @@ -161,9 +158,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -177,7 +172,6 @@ import static org.mockito.Mockito.times; * @author Raja Kolli * @author Scott Frederick */ -@SuppressWarnings("removal") @ExtendWith(OutputCaptureExtension.class) @DirtiesUrlFactories public abstract class AbstractServletWebServerFactoryTests { @@ -682,33 +676,6 @@ public abstract class AbstractServletWebServerFactoryTests { assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test"); } - @Test - @Deprecated(since = "3.1.0", forRemoval = true) - void sslWithCustomSslStoreProvider() throws Exception { - AbstractServletWebServerFactory factory = getFactory(); - addTestTxtFile(factory); - Ssl ssl = new Ssl(); - ssl.setClientAuth(ClientAuth.NEED); - ssl.setKeyPassword("password"); - factory.setSsl(ssl); - SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class); - given(sslStoreProvider.getKeyStore()).willReturn(loadStore()); - given(sslStoreProvider.getTrustStore()).willReturn(loadStore()); - factory.setSslStoreProvider(sslStoreProvider); - this.webServer = factory.getWebServer(); - this.webServer.start(); - KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - loadStore(keyStore, new FileSystemResource("src/test/resources/test.jks")); - SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( - new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()) - .loadKeyMaterial(keyStore, "password".toCharArray()) - .build()); - HttpComponentsClientHttpRequestFactory requestFactory = createHttpComponentsRequestFactory(socketFactory); - assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test"); - then(sslStoreProvider).should(atLeastOnce()).getKeyStore(); - then(sslStoreProvider).should(atLeastOnce()).getTrustStore(); - } - @Test void disableJspServletRegistration() throws Exception { AbstractServletWebServerFactory factory = getFactory(); @@ -1597,13 +1564,6 @@ public abstract class AbstractServletWebServerFactoryTests { } } - private KeyStore loadStore() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { - KeyStore keyStore = KeyStore.getInstance("JKS"); - Resource resource = new ClassPathResource("test.jks"); - loadStore(keyStore, resource); - return keyStore; - } - private void loadStore(KeyStore keyStore, Resource resource) throws IOException, NoSuchAlgorithmException, CertificateException { try (InputStream stream = resource.getInputStream()) {