@Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { throw new AsyncAuth(); } };
private boolean asyncAuth(int cmd, Buffer buffer, Exception e) { if (e instanceof AsyncAuth) { async = (AsyncAuth) e; async.setListener(authenticated -> { async = null; try { if (authenticated) { handleAuthenticationSuccess(cmd, buffer); } else { handleAuthenticationFailure(cmd, buffer); } } catch (Exception e1) { // HANDLE THIS BETTER e1.printStackTrace(); } }); return true; } else { return false; } }
@Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { final AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(false); } } }.start(); throw auth; } };
private boolean asyncAuth(int cmd, Buffer buffer, Exception e) { if (e instanceof AsyncAuth) { async = (AsyncAuth) e; async.setListener(authenticated -> { async = null; try { if (authenticated) { handleAuthenticationSuccess(cmd, buffer); } else { handleAuthenticationFailure(cmd, buffer); } } catch (Exception e1) { // HANDLE THIS BETTER e1.printStackTrace(); } }); return true; } else { return false; } }
@Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { final AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; } };
@Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { final AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; } };
@Test public void testAsyncAuthTimeout() throws Exception { startServer(500); authenticator = (username, password, sess) -> { throw new AsyncAuth(); }; try { authenticate(); } catch (JSchException e) { assertTrue("Unexpected failure " + e.getMessage(), e.getMessage().startsWith("SSH_MSG_DISCONNECT")); } }
@Test public void testAsyncAuthTimeout() throws Exception { startServer(500); authenticator = (username, password, sess) -> { throw new AsyncAuth(); }; try { authenticate(); } catch (JSchException e) { assertTrue("Unexpected failure " + e.getMessage(), e.getMessage().startsWith("SSH_MSG_DISCONNECT")); } }
@Test public void testAsyncAuthSucceeded() throws Exception { startServer(); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; }; assertTrue(authenticate()); }
@Test public void testAsyncAuthSucceeded() throws Exception { startServer(); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; }; assertTrue(authenticate()); }
@Test public void testAsyncAuthSucceededAfterTimeout() throws Exception { startServer(500); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; }; try { authenticate(); } catch (JSchException e) { assertTrue("Unexpected failure " + e.getMessage(), e.getMessage().startsWith("SSH_MSG_DISCONNECT")); } }
@Test public void testAsyncAuthFailed() throws Exception { startServer(); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(false); } } }.start(); throw auth; }; assertFalse(authenticate()); }
@Test public void testAsyncAuthFailed() throws Exception { startServer(); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(200); } catch (InterruptedException ignore) { } finally { auth.setAuthed(false); } } }.start(); throw auth; }; assertFalse(authenticate()); }
@Test public void testAsyncAuthSucceededAfterTimeout() throws Exception { startServer(500); authenticator = (username, password, sess) -> { AsyncAuth auth = new AsyncAuth(); new Thread() { @Override public void run() { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } finally { auth.setAuthed(true); } } }.start(); throw auth; }; try { authenticate(); } catch (JSchException e) { assertTrue("Unexpected failure " + e.getMessage(), e.getMessage().startsWith("SSH_MSG_DISCONNECT")); } }