Add a dedicated AuthenticationFailedException 64/89164/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 19 Apr 2020 11:18:47 +0000 (13:18 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 21 Apr 2020 09:04:14 +0000 (09:04 +0000)
When we have a failure to authenticate, we want the client to be
able to discern this state.

Add a dedicated exception and report it instead of straight
exception from SSH (which may be anything) or a generic ISE.

JIRA: NETCONF-665
Change-Id: I1f113d5aaff6bf4482d9725adaa06b5d2479304c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 027c3087a288cc7291cdfe265711dfaaa907bf9b)

netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AuthenticationFailedException.java [new file with mode: 0644]

index 6a3f07b2109391d5a6fd133cc6c4bb6dc29b27be..d5dec5d50e21c1b484ce291e17285508d00b7ddb 100644 (file)
@@ -127,10 +127,8 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
                 if (future1.isSuccess()) {
                     handleSshAuthenticated(localSession, ctx);
                 } else {
-                    // Exception does not have to be set in the future, add simple exception in such case
-                    final Throwable exception = future1.getException() == null
-                            ? new IllegalStateException("Authentication failed") : future1.getException();
-                    handleSshSetupFailure(ctx, exception);
+                    handleSshSetupFailure(ctx, new AuthenticationFailedException("Authentication failed",
+                        future1.getException()));
                 }
             });
         } catch (final IOException e) {
diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AuthenticationFailedException.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AuthenticationFailedException.java
new file mode 100644 (file)
index 0000000..07f391b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.nettyutil.handler.ssh.client;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import org.apache.sshd.common.SshException;
+
+/**
+ * Exception reported when endpoint authentication fails.
+ */
+@Beta
+public class AuthenticationFailedException extends SshException {
+    private static final long serialVersionUID = 1L;
+
+    public AuthenticationFailedException(final String message) {
+        super(requireNonNull(message));
+    }
+
+    public AuthenticationFailedException(final String message, final Throwable cause) {
+        super(requireNonNull(message), cause);
+    }
+}