this.session.disconnect(); log.error(e.getMessage(), e); throw new FileBasedHelperException("Cannot connect to SFTP source", e);
private static boolean isAuthenticationFailed(JSchException e) { return e.getCause() == null && e.getMessage().equals("Auth fail"); //$NON-NLS-1$ }
private static boolean isAuthenticationCanceled(JSchException e) { return e.getCause() == null && e.getMessage().equals("Auth cancel"); //$NON-NLS-1$ }
throw new TransportException(uri, e.getMessage(), e);
try { session.connect(); } catch (JSchException e) { if ("Auth fail".equals(e.getMessage())) { isSuccess = false; //Auth fail } }
private boolean isAuthenticationFailure(JSchException ee){ return ee.getMessage().equals("Auth fail"); //$NON-NLS-1$ }
private static void doCommonConstructorActions(String userName, String password, String connectionIP, String knownHostsFileName) { jschSSHChannel = new JSch(); try { jschSSHChannel.setKnownHosts(knownHostsFileName); } catch (JSchException jschX) { LOGGER.error(jschX.getMessage()); errorMessage = jschX.getMessage(); } strUserName = userName; strPassword = password; strConnectionIP = connectionIP; }
throw new TransportException(uri, c.getMessage(), je); throw new TransportException(uri, je.getMessage(), je);
private static boolean isAuthenticationCanceled(JSchException e) { return e.getCause() == null && e.getMessage().equals("Auth cancel"); //$NON-NLS-1$ }
public boolean hasSameFingerprint(String pubkey, String fingerprint) { try { byte[] pubKeyDecoded = Base64.getDecoder().decode(pubkey.getBytes()); HostKey hk; hk = new HostKey(HOST, pubKeyDecoded); String pubkeyFingerprint = hk.getFingerPrint(new JSch()); return fingerprint.equals(pubkeyFingerprint); } catch (JSchException e) { log.warn(e.getMessage()); return false; } }
/** * adds server rsa key to known hosts */ private void setKnownHost() { try { connection.setKnownHost(); } catch (JSchException jschX) { String errMsg = String.format("There was an issue with server RSA key setup:%n %s", jschX.getMessage()); LoggingService.logError(MODULE_NAME, errMsg, jschX); } }
protected boolean connect() { boolean success = true; try { session = jsch.getSession(user, host, port); session.setUserInfo(getUserInfo()); session.setConfig(getSessionConfig()); session.setPassword(password); session.connect(TIMEOUT); } catch (JSchException e) { logger.error(e.getMessage().replace("\n", " ")); success = false; } return success; }
static public SshException tryToUnwrap(JSchException e) { Throwable cause = e.getCause(); if (cause != null) { return new SshException(cause.getMessage(), cause); } return new SshException(e.getMessage(), e); }
@Override protected Result doRun() throws BlazeException { Session jschSession = ((JschSession)session).getJschSession(); ObjectHelper.requireNonNull(jschSession, "ssh session must be established first"); try { ChannelSftp channel = (ChannelSftp)jschSession.openChannel("sftp"); channel.connect(); return new Result(this, new JschSftpSession(session, channel)); } catch (JSchException e) { throw new SshException(e.getMessage(), e); } }
@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")); } }
public Session getSession(CommandWritable commandWritable, Command command){ Session session = null; CommandType commandType = command.getCommandType(); String host = commandWritable.getNameNodeHost(); if(host == null){ host = commandWritable.getWorkerHost(); } try { session = JschUtil.createSession(command.getSwitchedIdentity(), host, commandType); } catch (JSchException e) { LOGGER.error("Error [" + e.getMessage() + "] while creating JSchSession for (user, host) pair (" + command.getSwitchedIdentity().getUser() + ", " + host + ")"); } return session; }
private Session getSession(CommandWritable commandWritable, Command command){ Session session = null; CommandType commandType = command.getCommandType(); String host = commandWritable.getNameNodeHost(); if(host == null){ host = commandWritable.getWorkerHost(); } try { session = JschUtil.createSession(command.getSwitchedIdentity(), host, commandType); } catch (JSchException e) { LOGGER.error("Error [" + e.getMessage() + "] while creating JSchSession for (user, host) pair (" + command.getSwitchedIdentity().getUser() + ", " + host + ")"); } return session; }
@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")); } }
ChannelSftp newSftp() throws TransportException { final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0; try { // @TODO: Fix so that this operation is generic and casting to // JschSession is no longer necessary. final Channel channel = ((JschSession) getSession()) .getSftpChannel(); channel.connect(tms); return (ChannelSftp) channel; } catch (JSchException je) { throw new TransportException(uri, je.getMessage(), je); } }
@Test public void testAuthenticationFail() throws Exception { startShell(); for (boolean interactive : new boolean[]{false, true}) { Session session = createSession("paulo", "secret_", interactive); try { session.connect(); fail(); } catch (JSchException e) { String msg = e.getMessage(); assertTrue("Unexpected failure message " + msg, "Auth cancel".equals(msg) || "Auth fail".equals(msg)); } } }