From 1884c5645fec56f01bd151c717e74629dd41a2b2 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Wed, 11 Dec 2024 09:11:31 +0100 Subject: [PATCH] make auth nullable again to avoid empty strings in the config that can not be parsed back. --- .../opcua/client/OpcUaClientConfigurator.java | 36 ++++++++++--------- .../config/OpcUaSpecificAdapterConfig.java | 6 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/OpcUaClientConfigurator.java b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/OpcUaClientConfigurator.java index a7e57e1031..c92c48d74e 100644 --- a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/OpcUaClientConfigurator.java +++ b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/client/OpcUaClientConfigurator.java @@ -16,6 +16,7 @@ package com.hivemq.edge.adapters.opcua.client; import com.google.common.collect.ImmutableList; +import com.hivemq.edge.adapters.opcua.config.Auth; import com.hivemq.edge.adapters.opcua.config.BasicAuth; import com.hivemq.edge.adapters.opcua.config.Keystore; import com.hivemq.edge.adapters.opcua.config.OpcUaSpecificAdapterConfig; @@ -50,8 +51,8 @@ public class OpcUaClientConfigurator implements Function identityProviderBuilder = ImmutableList.builder(); - final X509Auth x509Auth = adapterConfig.getAuth().getX509Auth(); - final boolean x509AuthEnabled = x509Auth != null && x509Auth.isEnabled(); - if (x509AuthEnabled && tlsEnabled && keyPairWithChain != null) { - identityProviderBuilder.add(new X509IdentityProvider(Arrays.asList(keyPairWithChain.getCertificateChain()), - keyPairWithChain.getPrivateKey())); - } + final Auth auth = adapterConfig.getAuth(); + + if (auth != null) { + final X509Auth x509Auth = auth.getX509Auth(); + final boolean x509AuthEnabled = x509Auth != null && x509Auth.isEnabled(); + if (x509AuthEnabled && tlsEnabled && keyPairWithChain != null) { + identityProviderBuilder.add(new X509IdentityProvider(Arrays.asList(keyPairWithChain.getCertificateChain()), + keyPairWithChain.getPrivateKey())); + } - if (adapterConfig.getAuth().getBasicAuth() != null) { - final BasicAuth basicAuth = adapterConfig.getAuth().getBasicAuth(); - identityProviderBuilder.add(new UsernameProvider(basicAuth.getUsername(), basicAuth.getPassword())); + if (auth.getBasicAuth() != null) { + final BasicAuth basicAuth = auth.getBasicAuth(); + identityProviderBuilder.add(new UsernameProvider(basicAuth.getUsername(), basicAuth.getPassword())); + } } final ImmutableList identityProviders = identityProviderBuilder.build(); @@ -145,7 +149,7 @@ private void configureIdentityProvider( } @NotNull - private DefaultClientCertificateValidator createServerCertificateValidator(@NotNull Tls tlsConfig) { + private DefaultClientCertificateValidator createServerCertificateValidator(@NotNull final Tls tlsConfig) { final List trustedCerts; final boolean truststoreAvailable = checkTruststoreAvailable(tlsConfig); if (truststoreAvailable) { diff --git a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java index e01ada01dc..335b50387f 100644 --- a/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java +++ b/modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java @@ -56,9 +56,9 @@ public class OpcUaSpecificAdapterConfig implements ProtocolSpecificAdapterConfig defaultValue = "false") private final boolean overrideUri; - // @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("auth") - private final @NotNull Auth auth; + @JsonInclude(JsonInclude.Include.NON_NULL) + private final @Nullable Auth auth; @JsonProperty("tls") private final @NotNull Tls tls; @@ -94,7 +94,7 @@ public OpcUaSpecificAdapterConfig( return uri; } - public @NotNull Auth getAuth() { + public @Nullable Auth getAuth() { return auth; }