Skip to content

Commit

Permalink
Polish "Improve toString of SslBundle implementations"
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jan 17, 2024
1 parent b49ccbb commit a7d5222
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,8 +16,6 @@

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;
Expand Down Expand Up @@ -134,13 +132,10 @@ private static JksSslStoreDetails asStoreDetails(JksSslBundleProperties.Store pr
@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("key-alias", this.key.getAlias());
creator.append("key", this.key);
creator.append("options", this.options);
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()));
creator.append("stores", this.stores);
return creator.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,6 +20,7 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.springframework.core.style.ToStringCreator;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -160,6 +161,16 @@ public SslManagerBundle getManagers() {
return managersToUse;
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("key", getKey());
creator.append("options", getOptions());
creator.append("protocol", getProtocol());
creator.append("stores", getStores());
return creator.toString();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,6 +19,7 @@
import java.security.KeyStore;
import java.security.KeyStoreException;

import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -94,6 +95,14 @@ public String getAlias() {
return alias;
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("alias", alias);
creator.append("password", (password != null) ? "******" : null);
return creator.toString();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,6 +24,8 @@

import javax.net.ssl.SSLEngine;

import org.springframework.core.style.ToStringCreator;

/**
* Configuration options that should be applied when establishing an SSL connection.
*
Expand Down Expand Up @@ -81,6 +83,14 @@ public String[] getEnabledProtocols() {
return enabledProtocols;
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("ciphers", ciphers);
creator.append("enabledProtocols", enabledProtocols);
return creator.toString();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,6 +18,8 @@

import java.security.KeyStore;

import org.springframework.core.style.ToStringCreator;

/**
* A bundle of key and trust stores that can be used to establish an SSL connection.
*
Expand Down Expand Up @@ -75,6 +77,15 @@ public String getKeyStorePassword() {
return keyStorePassword;
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("keyStore.type", (keyStore != null) ? keyStore.getType() : "none");
creator.append("keyStorePassword", (keyStorePassword != null) ? "******" : null);
creator.append("trustStore.type", (trustStore != null) ? trustStore.getType() : "none");
return creator.toString();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -26,6 +26,7 @@
import java.security.cert.CertificateException;

import org.springframework.boot.ssl.SslStoreBundle;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -123,4 +124,14 @@ private void loadKeyStore(KeyStore store, String location, char[] password) {
}
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("keyStore.type", (this.keyStore != null) ? this.keyStore.getType() : "none");
String keyStorePassword = getKeyStorePassword();
creator.append("keyStorePassword", (keyStorePassword != null) ? "******" : null);
creator.append("trustStore.type", (this.trustStore != null) ? this.trustStore.getType() : "none");
return creator.toString();
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,6 +22,7 @@
import java.security.cert.X509Certificate;

import org.springframework.boot.ssl.SslStoreBundle;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -110,4 +111,13 @@ private void addCertificates(KeyStore keyStore, X509Certificate[] certificates,
}
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("keyStore.type", (this.keyStore != null) ? this.keyStore.getType() : "none");
creator.append("keyStorePassword", null);
creator.append("trustStore.type", (this.trustStore != null) ? this.trustStore.getType() : "none");
return creator.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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;
Expand Down Expand Up @@ -225,6 +224,16 @@ private static boolean hasJksTrustStoreProperties(Ssl ssl) {
|| (ssl.getTrustStoreType() != null && ssl.getTrustStoreType().equals("PKCS11")));
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("key", this.key);
creator.append("protocol", this.protocol);
creator.append("stores", this.stores);
creator.append("options", this.options);
return creator.toString();
}

/**
* Class to adapt a {@link SslStoreProvider} into a {@link SslStoreBundle}.
*/
Expand Down Expand Up @@ -252,6 +261,17 @@ public KeyStore getTrustStore() {
return ThrowingSupplier.of(this.sslStoreProvider::getTrustStore).get();
}

@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
KeyStore keyStore = getKeyStore();
creator.append("keyStore.type", (keyStore != null) ? keyStore.getType() : "none");
creator.append("keyStorePassword", null);
KeyStore trustStore = getTrustStore();
creator.append("trustStore.type", (trustStore != null) ? trustStore.getType() : "none");
return creator.toString();
}

}

private static final class WebServerSslStoreBundle implements SslStoreBundle {
Expand Down Expand Up @@ -284,19 +304,15 @@ public String getKeyStorePassword() {
return this.keyStorePassword;
}

}
@Override
public String toString() {
ToStringCreator creator = new ToStringCreator(this);
creator.append("keyStore.type", (this.keyStore != null) ? this.keyStore.getType() : "none");
creator.append("keyStorePassword", (this.keyStorePassword != null) ? "******" : null);
creator.append("trustStore.type", (this.trustStore != null) ? this.trustStore.getType() : "none");
return creator.toString();
}

@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();
}

}

0 comments on commit a7d5222

Please sign in to comment.