You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/11/26 06:33:10 UTC
[09/10] mina-sshd git commit: [SSHD-600] Propagate actual
authentication error to the AuthFuture
[SSHD-600] Propagate actual authentication error to the AuthFuture
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/be8428a0
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/be8428a0
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/be8428a0
Branch: refs/heads/master
Commit: be8428a03d93447c0daecc90c32198e29a119d45
Parents: af0e783
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Thu Nov 26 07:32:13 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Thu Nov 26 07:32:13 2015 +0200
----------------------------------------------------------------------
.../sshd/client/session/ClientSessionImpl.java | 21 ++++++++--
.../sshd/common/auth/AuthenticationTest.java | 41 ++++++++++++++++++++
2 files changed, 59 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/be8428a0/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
index 58eee3d..103925f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
@@ -59,7 +59,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class ClientSessionImpl extends AbstractClientSession {
- protected AuthFuture authFuture;
+ private AuthFuture authFuture;
/**
* For clients to store their own metadata
@@ -126,12 +126,27 @@ public class ClientSessionImpl extends AbstractClientSession {
ClientUserAuthService authService = getUserAuthService();
synchronized (lock) {
- authFuture = authService.auth(getRegisteredIdentities(), nextServiceName());
+ String serviceName = nextServiceName();
+ authFuture = ValidateUtils.checkNotNull(
+ authService.auth(getRegisteredIdentities(), serviceName),
+ "No auth future generated by service=%s",
+ serviceName);
return authFuture;
}
}
- private String nextServiceName() {
+ @Override
+ public void exceptionCaught(Throwable t) {
+ synchronized (lock) {
+ if (!authFuture.isDone()) {
+ authFuture.setException(t);
+ }
+ }
+
+ super.exceptionCaught(t);
+ }
+
+ protected String nextServiceName() {
synchronized (lock) {
return nextServiceFactory.getName();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/be8428a0/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 3831897..3aec0e7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -40,6 +40,8 @@ import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.buffer.Buffer;
@@ -513,6 +515,45 @@ public class AuthenticationTest extends BaseTestSupport {
}
}
+ @Test // see SSHD-600
+ public void testAuthExceptionPropagation() throws Exception {
+ try (SshClient client = setupTestClient()) {
+ final RuntimeException expected = new RuntimeException("Synthetic exception");
+ final AtomicInteger invocations = new AtomicInteger(0);
+ client.addSessionListener(new SessionListener() {
+ @Override
+ public void sessionCreated(Session session) {
+ // ignored
+ }
+
+ @Override
+ public void sessionEvent(Session session, Event event) {
+ assertEquals("Mismatched invocations count", 1, invocations.incrementAndGet());
+ throw expected;
+ }
+
+ @Override
+ public void sessionClosed(Session session) {
+ // ignored
+ }
+ });
+
+ client.start();
+ try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ s.addPasswordIdentity(getCurrentTestName());
+
+ AuthFuture future = s.auth();
+ assertTrue("Failed to complete auth in allocated time", future.await(11L, TimeUnit.SECONDS));
+ assertFalse("Unexpected authentication success", future.isSuccess());
+
+ Throwable actual = future.getException();
+ assertSame("Mismatched authentication failure reason", expected, actual);
+ } finally {
+ client.stop();
+ }
+ }
+ }
+
private static void assertAuthenticationResult(String message, AuthFuture future, boolean expected) throws IOException {
assertTrue(message + ": failed to get result on time", future.await(5L, TimeUnit.SECONDS));
assertEquals(message + ": mismatched authentication result", expected, future.isSuccess());