@Override protected JSch createDefaultJSch(FS fs) throws JSchException { if (GitMonitoringService.this.isJschLoggerEnabled) { JSch.setLogger(new JschLogger()); } JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.getIdentityRepository().removeAll(); if (GitMonitoringService.this.privateKeyPath != null) { defaultJSch.addIdentity(GitMonitoringService.this.privateKeyPath, GitMonitoringService.this.passphrase); } else { defaultJSch.addIdentity("gaas-git", GitMonitoringService.this.privateKey, null, GitMonitoringService.this.passphrase.getBytes(Charset.forName("UTF-8"))); } if (!Strings.isNullOrEmpty(GitMonitoringService.this.knownHosts)) { defaultJSch.setKnownHosts(new ByteArrayInputStream(GitMonitoringService.this.knownHosts.getBytes(Charset.forName("UTF-8")))); } else if (!Strings.isNullOrEmpty(GitMonitoringService.this.knownHostsFile)) { defaultJSch.setKnownHosts(GitMonitoringService.this.knownHostsFile); } return defaultJSch; } };
user = hc.getUser(); Session session = createSession(credentialsProvider, fs, user, pass, host, port, hc); session = null; knownHosts(getJSch(hc, fs), fs); if (isAuthenticationCanceled(e)) { throw e; } else if (isAuthenticationFailed(e) && credentialsProvider != null) { session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } else try { Thread.sleep(1000); session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } catch (InterruptedException e1) {
Session createSession(CredentialsProvider credentialsProvider, FS fs, String user, final String pass, String host, int port, final OpenSshConfig.Host hc) throws JSchException { final Session session = createSession(hc, user, host, port, fs); setUserName(session, user); credentialsProvider)); safeConfig(session, hc.getConfig()); if (hc.getConfig().getValue("HostKeyAlgorithms") == null) { //$NON-NLS-1$ setPreferredKeyTypesOrder(session); configure(hc, session); return session;
/** * Create default instance of jsch * * @param fs * the file system abstraction which will be necessary to perform * certain file system operations. * @return the new default JSch implementation. * @throws com.jcraft.jsch.JSchException * known host keys cannot be loaded. */ protected JSch createDefaultJSch(FS fs) throws JSchException { final JSch jsch = new JSch(); JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa")); //$NON-NLS-1$ //$NON-NLS-2$ JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss")); //$NON-NLS-1$ //$NON-NLS-2$ configureJSch(jsch); knownHosts(jsch, fs); identities(jsch, fs); return jsch; }
defaultJSch = createDefaultJSch(fs); if (defaultJSch.getConfigRepository() == null) { defaultJSch.setConfigRepository( if (jsch == null) { jsch = new JSch(); configureJSch(jsch); if (jsch.getConfigRepository() == null) { jsch.setConfigRepository(defaultJSch.getConfigRepository());
/** * Create a new remote session for the requested address. * * @param hc * host configuration * @param user * login to authenticate as. * @param host * server name to connect to. * @param port * port number of the SSH daemon (typically 22). * @param fs * the file system abstraction which will be necessary to * perform certain file system operations. * @return new session instance, but otherwise unconfigured. * @throws com.jcraft.jsch.JSchException * the session could not be created. */ protected Session createSession(final OpenSshConfig.Host hc, final String user, final String host, final int port, FS fs) throws JSchException { return getJSch(hc, fs).getSession(user, host, port); }
private Session createSession(CredentialsProvider credentialsProvider, FS fs, String user, final String pass, String host, int port, final OpenSshConfig.Host hc) throws JSchException { final Session session = createSession(hc, user, host, port, fs); // We retry already in getSession() method. JSch must not retry // on its own. session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$ if (pass != null) session.setPassword(pass); final String strictHostKeyCheckingPolicy = hc .getStrictHostKeyChecking(); if (strictHostKeyCheckingPolicy != null) session.setConfig("StrictHostKeyChecking", //$NON-NLS-1$ strictHostKeyCheckingPolicy); final String pauth = hc.getPreferredAuthentications(); if (pauth != null) session.setConfig("PreferredAuthentications", pauth); //$NON-NLS-1$ if (credentialsProvider != null && (!hc.isBatchMode() || !credentialsProvider.isInteractive())) { session.setUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)); } configure(hc, session); return session; }
defaultJSch = createDefaultJSch(fs); for (Object name : defaultJSch.getIdentityNames()) byIdentityFile.put((String) name, defaultJSch); if (jsch == null) { jsch = new JSch(); configureJSch(jsch); jsch.setHostKeyRepository(defaultJSch.getHostKeyRepository()); jsch.addIdentity(identityKey);
/** * Create a new remote session for the requested address. * * @param hc * host configuration * @param user * login to authenticate as. * @param host * server name to connect to. * @param port * port number of the SSH daemon (typically 22). * @param fs * the file system abstraction which will be necessary to * perform certain file system operations. * @return new session instance, but otherwise unconfigured. * @throws JSchException * the session could not be created. */ protected Session createSession(final OpenSshConfig.Host hc, final String user, final String host, final int port, FS fs) throws JSchException { return getJSch(hc, fs).getSession(user, host, port); }
/** * @param fs * the file system abstraction which will be necessary to * perform certain file system operations. * @return the new default JSch implementation. * @throws JSchException * known host keys cannot be loaded. */ protected JSch createDefaultJSch(FS fs) throws JSchException { final JSch jsch = new JSch(); configureJSch(jsch); knownHosts(jsch, fs); identities(jsch, fs); return jsch; }
@Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch jSch = super.createDefaultJSch(fs); // apply customized private key if (privateKeyPath != null) { jSch.removeAllIdentity(); jSch.addIdentity(privateKeyPath.toString()); } return jSch; } };
defaultJSch = createDefaultJSch(fs); if (defaultJSch.getConfigRepository() == null) { defaultJSch.setConfigRepository( if (jsch == null) { jsch = new JSch(); configureJSch(jsch); if (jsch.getConfigRepository() == null) { jsch.setConfigRepository(defaultJSch.getConfigRepository());
user = hc.getUser(); Session session = createSession(credentialsProvider, fs, user, pass, host, port, hc); session = null; knownHosts(getJSch(hc, fs), fs); if (isAuthenticationCanceled(e)) { throw e; } else if (isAuthenticationFailed(e) && credentialsProvider != null) { session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } else try { Thread.sleep(1000); session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } catch (InterruptedException e1) {
/** * Create a new remote session for the requested address. * * @param hc * host configuration * @param user * login to authenticate as. * @param host * server name to connect to. * @param port * port number of the SSH daemon (typically 22). * @param fs * the file system abstraction which will be necessary to * perform certain file system operations. * @return new session instance, but otherwise unconfigured. * @throws com.jcraft.jsch.JSchException * the session could not be created. */ protected Session createSession(final OpenSshConfig.Host hc, final String user, final String host, final int port, FS fs) throws JSchException { return getJSch(hc, fs).getSession(user, host, port); }
Session createSession(CredentialsProvider credentialsProvider, FS fs, String user, final String pass, String host, int port, final OpenSshConfig.Host hc) throws JSchException { final Session session = createSession(hc, user, host, port, fs); setUserName(session, user); credentialsProvider)); safeConfig(session, hc.getConfig()); if (hc.getConfig().getValue("HostKeyAlgorithms") == null) { //$NON-NLS-1$ setPreferredKeyTypesOrder(session); configure(hc, session); return session;
/** * Create default instance of jsch * * @param fs * the file system abstraction which will be necessary to perform * certain file system operations. * @return the new default JSch implementation. * @throws com.jcraft.jsch.JSchException * known host keys cannot be loaded. */ protected JSch createDefaultJSch(FS fs) throws JSchException { final JSch jsch = new JSch(); JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa")); //$NON-NLS-1$ //$NON-NLS-2$ JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss")); //$NON-NLS-1$ //$NON-NLS-2$ configureJSch(jsch); knownHosts(jsch, fs); identities(jsch, fs); return jsch; }
@Override protected JSch createDefaultJSch(FS fs) throws JSchException { if (privateKey != null) { JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath()); return defaultJSch; } else { return super.createDefaultJSch(fs); } } };
user = hc.getUser(); Session session = createSession(credentialsProvider, fs, user, pass, host, port, hc); session = null; knownHosts(getJSch(hc, fs), fs); if (isAuthenticationCanceled(e)) { throw e; } else if (isAuthenticationFailed(e) && credentialsProvider != null) { session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } else try { Thread.sleep(1000); session = createSession(credentialsProvider, fs, user, pass, host, port, hc); } catch (InterruptedException e1) {
@Override protected JSch getJSch(OpenSshConfig.Host hc, FS fs) throws JSchException { JSch jsch = super.getJSch(hc, fs); if (StringUtils.hasValue(passphrase)) { // If passphrase is set, add it to identity File sshDir = new File(fs.userHome(), ".ssh"); if (sshDir.isDirectory()) { updateIdentity(jsch, new File(sshDir, "identity")); updateIdentity(jsch, new File(sshDir, "id_rsa")); updateIdentity(jsch, new File(sshDir, "id_dsa")); } } return jsch; }
@Override protected JSch createDefaultJSch(FS fs) throws JSchException { if (privateKey != null) { JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath()); return defaultJSch; } else { return super.createDefaultJSch(fs); } } };