You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/04 15:43:25 UTC

[2/2] karaf git commit: Make sure authentication is also retried

Make sure authentication is also retried


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/d00f282b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/d00f282b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/d00f282b

Branch: refs/heads/master
Commit: d00f282b6109cbebd5d799bac947f34ee9f4a80e
Parents: 4573155
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Aug 4 17:43:18 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Aug 4 17:43:18 2017 +0200

----------------------------------------------------------------------
 .../karaf/itests/ssh/SshCommandTestBase.java      | 18 +++++++++---------
 .../org/apache/karaf/shell/ssh/Activator.java     |  1 -
 .../karaf/shell/ssh/keygenerator/PemWriter.java   |  6 +++---
 3 files changed, 12 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/d00f282b/itests/src/test/java/org/apache/karaf/itests/ssh/SshCommandTestBase.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ssh/SshCommandTestBase.java b/itests/src/test/java/org/apache/karaf/itests/ssh/SshCommandTestBase.java
index e9c628f..66339f9 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ssh/SshCommandTestBase.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ssh/SshCommandTestBase.java
@@ -111,18 +111,18 @@ public class SshCommandTestBase extends KarafTestSupport {
             ConnectFuture future = client.connect(username, "localhost", Integer.parseInt(sshPort));
             future.await();
             session = future.getSession();
+            Set<ClientSessionEvent> ret = EnumSet.of(ClientSessionEvent.WAIT_AUTH);
+            while (ret.contains(ClientSessionEvent.WAIT_AUTH)) {
+                session.addPasswordIdentity(password);
+                session.auth().verify();
+                ret = session.waitFor(EnumSet.of(ClientSessionEvent.WAIT_AUTH, ClientSessionEvent.CLOSED, ClientSessionEvent.AUTHED), 0);
+            }
+            if (ret.contains(ClientSessionEvent.CLOSED)) {
+                throw new Exception("Could not open SSH channel");
+            }
             return true;
         });
 
-        Set<ClientSessionEvent> ret = EnumSet.of(ClientSessionEvent.WAIT_AUTH);
-        while (ret.contains(ClientSessionEvent.WAIT_AUTH)) {
-            session.addPasswordIdentity(password);
-            session.auth().verify();
-            ret = session.waitFor(EnumSet.of(ClientSessionEvent.WAIT_AUTH, ClientSessionEvent.CLOSED, ClientSessionEvent.AUTHED), 0);
-        }
-        if (ret.contains(ClientSessionEvent.CLOSED)) {
-            throw new Exception("Could not open SSH channel");
-        }
         channel = session.createChannel("shell");
         PipedOutputStream pipe = new PipedOutputStream();
         channel.setIn(new PipedInputStream(pipe));

http://git-wip-us.apache.org/repos/asf/karaf/blob/d00f282b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
index 1006af7..584771f 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/Activator.java
@@ -166,7 +166,6 @@ public class Activator extends BaseActivator implements ManagedService {
         
         Path serverKeyPath = Paths.get(hostKey);
         if (!serverKeyPath.toFile().exists()) {
-            
             createServerKey(serverKeyPath.toFile(), algorithm, keySize);
         }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/d00f282b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/keygenerator/PemWriter.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/keygenerator/PemWriter.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/keygenerator/PemWriter.java
index 960570d..078a125 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/keygenerator/PemWriter.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/keygenerator/PemWriter.java
@@ -40,8 +40,8 @@ public class PemWriter {
         Collection<Object> items = new ArrayList<>();
         items.add(new PEMItem(kp.getPrivate().getEncoded(), "PRIVATE KEY"));
         byte[] bytes = PEMUtil.encode(items);
-        FileOutputStream os = new FileOutputStream(keyFile);
-        os.write(bytes);
-        os.close();
+        try (FileOutputStream os = new FileOutputStream(keyFile)) {
+            os.write(bytes);
+        }
     }
 }