From b49ccbb0c2e36e105300ed38082290eb52a8f29d Mon Sep 17 00:00:00 2001 From: amparab Date: Mon, 15 Jan 2024 01:38:38 +0530 Subject: [PATCH] Improve toString of SslBundle implementations See gh-39137 --- .../autoconfigure/ssl/PropertiesSslBundle.java | 16 ++++++++++++++++ .../boot/web/server/WebServerSslBundle.java | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java index b25b88ad14..102703d142 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.ssl; +import java.util.Arrays; + import org.springframework.boot.autoconfigure.ssl.SslBundleProperties.Key; import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.ssl.SslBundleKey; @@ -26,6 +28,7 @@ import org.springframework.boot.ssl.jks.JksSslStoreBundle; import org.springframework.boot.ssl.jks.JksSslStoreDetails; import org.springframework.boot.ssl.pem.PemSslStoreBundle; import org.springframework.boot.ssl.pem.PemSslStoreDetails; +import org.springframework.core.style.ToStringCreator; /** * {@link SslBundle} backed by {@link JksSslBundleProperties} or @@ -128,4 +131,17 @@ public final class PropertiesSslBundle implements SslBundle { properties.getPassword()); } + @Override + public String toString() { + ToStringCreator creator = new ToStringCreator(this); + creator.append("key-alias", this.key.getAlias()); + creator.append("protocol", this.protocol); + creator.append("keystore-type", this.stores.getKeyStore().getType()); + creator.append("truststore-type", + (this.stores.getTrustStore() != null) ? this.stores.getTrustStore().getType() : ""); + creator.append("ciphers", Arrays.toString(this.options.getCiphers())); + creator.append("enabled-protocols", Arrays.toString(this.options.getEnabledProtocols())); + return creator.toString(); + } + } 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 0e10ace7fd..48865151f7 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 @@ -17,6 +17,7 @@ package org.springframework.boot.web.server; import java.security.KeyStore; +import java.util.Arrays; import org.springframework.boot.ssl.NoSuchSslBundleException; import org.springframework.boot.ssl.SslBundle; @@ -29,6 +30,7 @@ import org.springframework.boot.ssl.jks.JksSslStoreBundle; import org.springframework.boot.ssl.jks.JksSslStoreDetails; import org.springframework.boot.ssl.pem.PemSslStoreBundle; import org.springframework.boot.ssl.pem.PemSslStoreDetails; +import org.springframework.core.style.ToStringCreator; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.util.function.ThrowingSupplier; @@ -284,4 +286,17 @@ public final class WebServerSslBundle implements SslBundle { } + @Override + public String toString() { + ToStringCreator creator = new ToStringCreator(this); + creator.append("key-alias", this.key.getAlias()); + creator.append("protocol", this.protocol); + creator.append("keystore-type", this.stores.getKeyStore().getType()); + creator.append("truststore-type", + (this.stores.getTrustStore() != null) ? this.stores.getTrustStore().getType() : ""); + creator.append("ciphers", Arrays.toString(this.options.getCiphers())); + creator.append("enabled-protocols", Arrays.toString(this.options.getEnabledProtocols())); + return creator.toString(); + } + }