Polishing.
Simplify variable names. Remove unused internal methods. Use CharSequence instead of String to accept keystore passwords. Closes gh-711 See gh-708
This commit is contained in:
@@ -148,13 +148,13 @@ public class CertificateBundle extends Certificate {
|
||||
*/
|
||||
public String getRequiredPrivateKeyType() {
|
||||
|
||||
String requiredPrivateKeyType = getPrivateKeyType();
|
||||
String type = getPrivateKeyType();
|
||||
|
||||
if (requiredPrivateKeyType == null) {
|
||||
if (type == null) {
|
||||
throw new IllegalStateException("Private key type is not set");
|
||||
}
|
||||
|
||||
return requiredPrivateKeyType;
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,9 +188,9 @@ public class CertificateBundle extends Certificate {
|
||||
* @param keyAlias the key alias to use.
|
||||
* @param password the password to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @since 3.0.0
|
||||
* @since 2.4
|
||||
*/
|
||||
public KeyStore createKeyStore(String keyAlias, String password) {
|
||||
public KeyStore createKeyStore(String keyAlias, CharSequence password) {
|
||||
return createKeyStore(keyAlias, false, password);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ public class CertificateBundle extends Certificate {
|
||||
* @param keyAlias the key alias to use.
|
||||
* @param password the password to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @since 3.0.0
|
||||
* @since 2.4
|
||||
*/
|
||||
public KeyStore createKeyStore(String keyAlias, char[] password) {
|
||||
return createKeyStore(keyAlias, false, password);
|
||||
@@ -227,11 +227,18 @@ public class CertificateBundle extends Certificate {
|
||||
* just the issuer certificate.
|
||||
* @param password the password to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @since 3.0.0
|
||||
* @since 2.4
|
||||
*/
|
||||
public KeyStore createKeyStore(String keyAlias, boolean includeCaChain, String password) {
|
||||
Assert.hasText(password, "Password must not be empty");
|
||||
return createKeyStore(keyAlias, includeCaChain, password.toCharArray());
|
||||
public KeyStore createKeyStore(String keyAlias, boolean includeCaChain, CharSequence password) {
|
||||
|
||||
Assert.notNull(password, "Password must not be null");
|
||||
|
||||
char[] passwordChars = new char[password.length()];
|
||||
for (int i = 0; i < passwordChars.length; i++) {
|
||||
passwordChars[i] = password.charAt(i);
|
||||
}
|
||||
|
||||
return createKeyStore(keyAlias, includeCaChain, passwordChars);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +249,7 @@ public class CertificateBundle extends Certificate {
|
||||
* just the issuer certificate.
|
||||
* @param password the password to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @since 3.0.0
|
||||
* @since 2.4
|
||||
*/
|
||||
public KeyStore createKeyStore(String keyAlias, boolean includeCaChain, char[] password) {
|
||||
|
||||
|
||||
@@ -73,46 +73,6 @@ class KeystoreUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link KeyStore} containing the {@link KeySpec} and {@link X509Certificate
|
||||
* certificates} using the given {@code keyAlias}.
|
||||
* @param keyAlias the key alias to use.
|
||||
* @param privateKeySpec the private key to use.
|
||||
* @param certificates the certificate chain to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @throws GeneralSecurityException if exception occur when creating the instance of
|
||||
* the {@link KeyStore}
|
||||
* @throws IOException if there is an I/O or format problem with the keystore data, if
|
||||
* a password is required but not given, or if the given password was incorrect. If
|
||||
* the error is due to a wrong password, the {@link Throwable#getCause cause} of the
|
||||
* {@code IOException} should be an {@code UnrecoverableKeyException}
|
||||
*/
|
||||
static KeyStore createKeyStore(String keyAlias, KeySpec privateKeySpec, X509Certificate... certificates)
|
||||
throws GeneralSecurityException, IOException {
|
||||
return createKeyStore(keyAlias, privateKeySpec, new char[0], certificates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link KeyStore} containing the {@link KeySpec} and {@link X509Certificate
|
||||
* certificates} using the given {@code keyAlias} and {@code keyPassword}.
|
||||
* @param keyAlias the key alias to use.
|
||||
* @param privateKeySpec the private key to use.
|
||||
* @param keyPassword the password to use.
|
||||
* @param certificates the certificate chain to use.
|
||||
* @return the {@link KeyStore} containing the private key and certificate chain.
|
||||
* @throws GeneralSecurityException if exception occur when creating the instance of
|
||||
* the {@link KeyStore}
|
||||
* @throws IOException if there is an I/O or format problem with the keystore data, if
|
||||
* a password is required but not given, or if the given password was incorrect. If
|
||||
* the error is due to a wrong password, the {@link Throwable#getCause cause} of the
|
||||
* {@code IOException} should be an {@code UnrecoverableKeyException}
|
||||
*/
|
||||
static KeyStore createKeyStore(String keyAlias, KeySpec privateKeySpec, String keyPassword,
|
||||
X509Certificate... certificates) throws GeneralSecurityException, IOException {
|
||||
Assert.hasText(keyPassword, "keyPassword must not be empty");
|
||||
return createKeyStore(keyAlias, privateKeySpec, keyPassword.toCharArray(), certificates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link KeyStore} containing the {@link KeySpec} and {@link X509Certificate
|
||||
* certificates} using the given {@code keyAlias} and {@code keyPassword}.
|
||||
|
||||
@@ -65,6 +65,7 @@ import static org.springframework.vault.util.Settings.*;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Alex Bremora
|
||||
* @author Bogdan Cardos
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = VaultIntegrationTestConfiguration.class)
|
||||
|
||||
Reference in New Issue
Block a user