From 357a26286edb82f4c21f4d4e4f0c12a463d7b859 Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Wed, 5 Jun 2024 13:51:31 +0200 Subject: [PATCH] Remove the usage of lambdas in the TLS registry code --- .../java/io/quarkus/tls/runtime/CertificateRecorder.java | 7 ++++++- .../io/quarkus/tls/runtime/VertxCertificateHolder.java | 6 ++++-- .../io/quarkus/tls/runtime/keystores/JKSKeyStores.java | 8 ++++++-- .../io/quarkus/tls/runtime/keystores/P12KeyStores.java | 8 ++++++-- .../io/quarkus/tls/runtime/keystores/TrustAllOptions.java | 7 ++++++- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java index 75118d98ccef6..dd03427795f1a 100644 --- a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java +++ b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/CertificateRecorder.java @@ -138,7 +138,12 @@ public void register(String name, TlsConfiguration configuration) { } public Supplier getSupplier() { - return () -> this; + return new Supplier() { + @Override + public TlsConfigurationRegistry get() { + return CertificateRecorder.this; + } + }; } public void register(String name, Supplier supplier) { diff --git a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/VertxCertificateHolder.java b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/VertxCertificateHolder.java index d8f62dc0fd73f..c71b45168bfab 100644 --- a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/VertxCertificateHolder.java +++ b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/VertxCertificateHolder.java @@ -16,7 +16,6 @@ import javax.net.ssl.TrustManagerFactory; import io.quarkus.tls.TlsConfiguration; -import io.quarkus.tls.runtime.config.KeyStoreConfig; import io.quarkus.tls.runtime.config.TlsBucketConfig; import io.quarkus.tls.runtime.config.TlsConfigUtils; import io.vertx.core.Vertx; @@ -138,7 +137,10 @@ public Optional getHostnameVerificationAlgorithm() { @Override public boolean usesSni() { - return config.keyStore().map(KeyStoreConfig::sni).orElse(false); + if (config.keyStore().isPresent()) { + return config.keyStore().get().sni(); + } + return false; } @Override diff --git a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/JKSKeyStores.java b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/JKSKeyStores.java index 4982000fc7e4d..347127541b1f9 100644 --- a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/JKSKeyStores.java +++ b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/JKSKeyStores.java @@ -58,7 +58,9 @@ private static JksOptions toOptions(JKSKeyStoreConfig config, + "' - the key store password is not set and cannot be retrieved from the credential provider."); } options.setPassword(p); - config.alias().ifPresent(options::setAlias); + if (config.alias().isPresent()) { + options.setAlias(config.alias().get()); + } String ap = CredentialProviders.getAliasPassword(config.aliasPassword(), keyStoreCredentialProviderConfig) .orElse(null); options.setAliasPassword(ap); @@ -83,7 +85,9 @@ private static JksOptions toOptions(JKSTrustStoreConfig config, + "' - the trust store password is not set and cannot be retrieved from the credential provider."); } options.setPassword(password); - config.alias().ifPresent(options::setAlias); + if (config.alias().isPresent()) { + options.setAlias(config.alias().get()); + } } catch (UncheckedIOException e) { throw new IllegalStateException("Invalid JKS trust store configuration for certificate '" + name + "' - cannot read the trust store file '" + config.path() + "'", e); diff --git a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/P12KeyStores.java b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/P12KeyStores.java index ae04f82473f6a..70f875be2568d 100644 --- a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/P12KeyStores.java +++ b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/P12KeyStores.java @@ -57,7 +57,9 @@ private static PfxOptions toOptions(P12KeyStoreConfig config, KeyStoreCredential + "' - the key store password is not set and cannot be retrieved from the credential provider."); } options.setPassword(password); - config.alias().ifPresent(options::setAlias); + if (config.alias().isPresent()) { + options.setAlias(config.alias().get()); + } String ap = CredentialProviders.getAliasPassword(config.aliasPassword(), pc).orElse(null); options.setAliasPassword(ap); } catch (UncheckedIOException e) { @@ -80,7 +82,9 @@ private static PfxOptions toOptions(P12TrustStoreConfig config, TrustStoreCreden + "' - the trust store password is not set and cannot be retrieved from the credential provider."); } options.setPassword(password); - config.alias().ifPresent(options::setAlias); + if (config.alias().isPresent()) { + options.setAlias(config.alias().get()); + } } catch (UncheckedIOException e) { throw new IllegalStateException("Invalid P12 trust store configuration for certificate '" + name + "' - cannot read the trust store file '" + config.path() + "'", e); diff --git a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/TrustAllOptions.java b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/TrustAllOptions.java index 0092cad3f257d..2258f004f2d22 100644 --- a/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/TrustAllOptions.java +++ b/extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/keystores/TrustAllOptions.java @@ -68,6 +68,11 @@ protected TrustManager[] engineGetTrustManagers() { @Override public Function trustManagerMapper(Vertx vertx) { - return name -> new TrustManager[] { TRUST_ALL_MANAGER }; + return new Function() { + @Override + public TrustManager[] apply(String name) { + return new TrustManager[] { TRUST_ALL_MANAGER }; + } + }; } }