@Override public void operationComplete(AuthFuture authFuture) { log.info("Authentication completed with " + (authFuture.isSuccess() ? "success" : "failure") + " for " + user + "@" + ip + ":" + port); } });
@Override public void operationComplete(final AuthFuture future) { if (future.isSuccess()) { handleSshAuthenticated(session, ctx); } else { // Exception does not have to be set in the future, add simple exception in such case final Throwable exception = future.getException() == null ? new IllegalStateException("Authentication failed") : future.getException(); handleSshSetupFailure(ctx, exception); } } });
@Override public void operationComplete(final AuthFuture future) { if (future.isSuccess()) { handleSshAuthenticated(session, ctx); } else { // Exception does not have to be set in the future, add simple exception in such case final Throwable exception = future.getException() == null ? new IllegalStateException("Authentication failed") : future.getException(); handleSshSetupFailure(ctx, exception); } } });
AuthFuture authFuture = authFutureHolder.get(); boolean debugEnabled = log.isDebugEnabled(); if ((authFuture != null) && authFuture.isSuccess()) { log.error("process({}) unexpected authenticated client command: {}", session, SshConstants.getCommandMessageName(cmd));
if (this.authFuture.isSuccess()) { log.debug("already authenticated"); throw new IllegalStateException("Already authenticated");
public void operationComplete(AuthFuture arg0) System.out.println("Authentication completed with " + ( arg0.isSuccess() ? "success" : "failure"));
if (this.authFuture.isSuccess()) { log.debug("already authenticated"); throw new IllegalStateException("Already authenticated");
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()); }
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()); }
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()); }
@Override public void process(int cmd, Buffer buffer) throws Exception { if (this.authFuture.isSuccess()) { throw new IllegalStateException("UserAuth message delivered to authenticated client"); } else if (this.authFuture.isDone()) { log.debug("Ignoring random message"); // ignore for now; TODO: random packets } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) { String welcome = buffer.getString(); String lang = buffer.getString(); log.debug("Welcome banner[{}]: {}", lang, welcome); UserInteraction ui = session.getUserInteraction(); if ((ui != null) && ui.isInteractionAllowed(session)) { ui.welcome(session, welcome, lang); } } else { buffer.rpos(buffer.rpos() - 1); processUserAuth(buffer); } }
@Override public void process(int cmd, Buffer buffer) throws Exception { if (this.authFuture.isSuccess()) { throw new IllegalStateException("UserAuth message delivered to authenticated client"); } else if (this.authFuture.isDone()) { log.debug("Ignoring random message"); // ignore for now; TODO: random packets } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) { String welcome = buffer.getString(); String lang = buffer.getString(); log.debug("Welcome banner[{}]: {}", lang, welcome); UserInteraction ui = session.getUserInteraction(); if ((ui != null) && ui.isInteractionAllowed(session)) { ui.welcome(session, welcome, lang); } } else { buffer.rpos(buffer.rpos() - 1); processUserAuth(buffer); } }
@Override public void process(int cmd, Buffer buffer) throws Exception { if (this.authFuture.isSuccess()) { throw new IllegalStateException("UserAuth message delivered to authenticated client"); } else if (this.authFuture.isDone()) { log.debug("Ignoring random message"); // ignore for now; TODO: random packets } else if (cmd == SshConstants.SSH_MSG_USERAUTH_BANNER) { String welcome = buffer.getString(); String lang = buffer.getString(); log.debug("Welcome banner[{}]: {}", lang, welcome); UserInteraction ui = session.getUserInteraction(); if ((ui != null) && ui.isInteractionAllowed(session)) { ui.welcome(session, welcome, lang); } } else { buffer.rpos(buffer.rpos() - 1); processUserAuth(buffer); } }
if (!authFuture.isSuccess()) { throw new SshException("Error establishing ssh connection to [" + username + "@" + host + ":" + port + "]. Authentication failed.");
assertTrue("Authentication failed", auth.isSuccess()); } finally { client.stop();
AuthFuture auth = session.auth(); assertTrue("Failed to complete authentication on time", auth.await(17L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", auth.isSuccess()); assertEquals("Mismatched interactive challenge calls", 1, challengeCount.get()); } finally {
AuthFuture auth = session.auth(); assertTrue("Failed to complete authentication on time", auth.await(17L, TimeUnit.SECONDS)); assertFalse("Unexpected authentication success", auth.isSuccess()); assertEquals("Mismatched interactive challenge calls", 1, challengeCount.get()); } finally {
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }
@Test public void testFailAuthenticationWithFuture() throws Exception { final int maxAllowedAuths = 10; PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths); sshd.start(); client.setServiceFactories(Arrays.asList( new ClientUserAuthServiceOld.Factory(), ClientConnectionServiceFactory.INSTANCE )); client.start(); try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) { int nbTrials = 0; AuthFuture authFuture; do { nbTrials++; assertTrue("Number of trials below max.", nbTrials < 100); authFuture = s.getService(ClientUserAuthServiceOld.class) .auth(new org.apache.sshd.deprecated.UserAuthPassword(s, "ssh-connection", "buggy")); assertTrue("Authentication wait failed", authFuture.await(5L, TimeUnit.SECONDS)); assertTrue("Authentication not done", authFuture.isDone()); assertFalse("Authentication unexpectedly successful", authFuture.isSuccess()); } while (authFuture.getException() == null); Throwable t = authFuture.getException(); assertNotNull("Missing auth future exception", t); assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths); } finally { client.stop(); } }