protected void signalAuthFailure(AuthFuture future, Throwable t) { boolean signalled = false; synchronized (lock) { if ((future != null) && (!future.isDone())) { future.setException(t); signalled = true; } } if (log.isDebugEnabled()) { log.debug("signalAuthFailure({}) type={}, signalled={}, message=\"{}\"", this, t.getClass().getSimpleName(), signalled, t.getMessage()); } }
protected void signalAuthFailure(AuthFuture future, Throwable t) { boolean signalled = false; synchronized (lock) { if ((future != null) && (!future.isDone())) { future.setException(t); signalled = true; } } if (log.isDebugEnabled()) { log.debug("signalAuthFailure({}) type={}, signalled={}, message=\"{}\"", this, t.getClass().getSimpleName(), signalled, t.getMessage()); } }
@Override protected void preClose() { AuthFuture authFuture = authFutureHolder.get(); if ((authFuture != null) && (!authFuture.isDone())) { authFuture.setException(new SshException("Session is closed")); } super.preClose(); } }
@Override protected void preClose() { AuthFuture authFuture = authFutureHolder.get(); if ((authFuture != null) && (!authFuture.isDone())) { authFuture.setException(new SshException("Session is closed")); } super.preClose(); } }
session, SshConstants.getCommandMessageName(cmd)); throw new IllegalStateException("UserAuth message delivered to authenticated client"); } else if ((authFuture != null) && authFuture.isDone()) {
session, SshConstants.getCommandMessageName(cmd)); throw new IllegalStateException("UserAuth message delivered to authenticated client"); } else if ((authFuture != null) && authFuture.isDone()) {
boolean debugEnabled = log.isDebugEnabled(); if (currentFuture != null) { if (currentFuture.isDone()) { if (debugEnabled) { log.debug("auth({})[{}] request new authentication", session, service);
boolean debugEnabled = log.isDebugEnabled(); if (currentFuture != null) { if (currentFuture.isDone()) { if (debugEnabled) { log.debug("auth({})[{}] request new authentication", session, service);
private boolean readyForAuth(UserAuth userAuth) { while (!this.authFuture.isDone()) { log.debug("waiting to send authentication"); try {
@Override protected void preClose() { if (!authFuture.isDone()) { authFuture.setException(new SshException("Session is closed")); } super.preClose(); }
private boolean readyForAuth(UserAuth userAuth) { while (!this.authFuture.isDone()) { log.debug("waiting to send authentication"); try {
@Override protected void preClose() { if (!authFuture.isDone()) { authFuture.setException(new SshException("Session is closed")); } super.preClose(); }
@Override protected void preClose() { if (!authFuture.isDone()) { authFuture.setException(new SshException("Session is closed")); } super.preClose(); }
private boolean readyForAuth(UserAuth userAuth) { while (!this.authFuture.isDone()) { log.debug("waiting to send authentication"); try {
@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); } }
@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(); } }