From 241dc2063166c0eec1d8cf0647ecf0c97c445ae5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 9 Sep 2022 14:03:17 +0200 Subject: [PATCH] Clean up SslHandlerFactoryImpl a bit Use an instanceof pattern and if/else chain instead of a checkArgument. Also prefer Set.of(). Change-Id: I643fd75bd5191f1f9d9f434844d1b0e924433ad2 Signed-off-by: Robert Varga --- .../sal/connect/util/SslHandlerFactoryImpl.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/SslHandlerFactoryImpl.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/SslHandlerFactoryImpl.java index 5e84533739..6165869eed 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/SslHandlerFactoryImpl.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/SslHandlerFactoryImpl.java @@ -7,7 +7,6 @@ */ package org.opendaylight.netconf.sal.connect.util; -import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import com.google.common.collect.Sets; @@ -15,7 +14,6 @@ import io.netty.handler.ssl.SslHandler; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyStore; -import java.util.Collections; import java.util.Set; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -42,11 +40,11 @@ public final class SslHandlerFactoryImpl implements SslHandlerFactory { @Override public SslHandler createSslHandler() { - return createSslHandler(Collections.emptySet()); + return createSslHandler(Set.of()); } @Override - public SslHandler createSslHandler(Set allowedKeys) { + public SslHandler createSslHandler(final Set allowedKeys) { try { final KeyStore keyStore = keystoreAdapter.getJavaKeyStore(allowedKeys); @@ -64,14 +62,14 @@ public final class SslHandlerFactoryImpl implements SslHandlerFactory { final String[] engineProtocols = engine.getSupportedProtocols(); final String[] enabledProtocols; - if (specification != null) { - checkArgument(specification instanceof TlsCase, "Cannot get TLS specification from: %s", specification); - + if (specification instanceof TlsCase tlsSpecification) { final Set protocols = Sets.newHashSet(engineProtocols); - protocols.removeAll(((TlsCase)specification).getTls().getExcludedVersions()); + protocols.removeAll(tlsSpecification.getTls().getExcludedVersions()); enabledProtocols = protocols.toArray(new String[0]); - } else { + } else if (specification == null) { enabledProtocols = engineProtocols; + } else { + throw new IllegalArgumentException("Cannot get TLS specification from: " + specification); } engine.setEnabledProtocols(enabledProtocols); -- 2.36.6