BUG-1568 Ssh Handler for netconf client Mina implementation
[controller.git] / opendaylight / netconf / netconf-netty-util / src / main / java / org / opendaylight / controller / netconf / nettyutil / handler / ssh / authentication / LoginPassword.java
index b67aa0f96dcd53a084965fc3766399a26f2a5869..553e5359ffed1cd8b5728734bb5546e3abb0f72e 100644 (file)
@@ -8,10 +8,13 @@
 
 package org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication;
 
-import ch.ethz.ssh2.Connection;
-
 import java.io.IOException;
 
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.client.future.AuthFuture;
+
+import ch.ethz.ssh2.Connection;
+
 /**
  * Class Providing username/password authentication option to
  * {@link org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshHandler}
@@ -27,10 +30,21 @@ public class LoginPassword extends AuthenticationHandler {
 
     @Override
     public void authenticate(Connection connection) throws IOException {
-        boolean isAuthenticated = connection.authenticateWithPassword(username, password);
+        final boolean isAuthenticated = connection.authenticateWithPassword(username, password);
 
         if (!isAuthenticated) {
             throw new IOException("Authentication failed.");
         }
     }
+
+    @Override
+    public String getUsername() {
+        return username;
+    }
+
+    @Override
+    public AuthFuture authenticate(final ClientSession session) throws IOException {
+        session.addPasswordIdentity(password);
+        return session.auth();
+    }
 }