public DefaultConfig() { setLoggerFactory(LoggerFactory.DEFAULT); setVersion(readVersionFromProperties()); final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); initKeyExchangeFactories(bouncyCastleRegistered); initRandomFactory(bouncyCastleRegistered); initFileKeyProviderFactories(bouncyCastleRegistered); initCipherFactories(); initCompressionFactories(); initMACFactories(); initSignatureFactories(); setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); }
@Test @Category({SlowTests.class, KnownFailingTests.class}) public void shouldCorrectlyTerminateThreadOnDisconnect() throws IOException, InterruptedException { DefaultConfig defaultConfig = new DefaultConfig(); defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); for (int i = 0; i < 10; i++) { SSHClient sshClient = fixture.setupClient(defaultConfig); fixture.connectClient(sshClient); sshClient.getConnection().getKeepAlive().setKeepAliveInterval(1); try { sshClient.authPassword("bad", "credentials"); fail("Should not auth."); } catch (UserAuthException e) { // OK } fixture.stopClient(); Thread.sleep(2000); } ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); for (long l : threadMXBean.getAllThreadIds()) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(l); if (threadInfo.getThreadName().equals("keep-alive") && threadInfo.getThreadState() != Thread.State.TERMINATED) { fail("Found alive keep-alive thread in state " + threadInfo.getThreadState()); } } } }
@Override public SSHClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt) throws BackgroundException { try { final DefaultConfig configuration = new DefaultConfig(); if("zlib".equals(preferences.getProperty("ssh.compression"))) { configuration.setCompressionFactories(Arrays.asList( new DelayedZlibCompression.Factory(), new ZlibCompression.Factory(), new NoneCompression.Factory())); } else { configuration.setCompressionFactories(Collections.singletonList(new NoneCompression.Factory())); } configuration.setVersion(new PreferencesUseragentProvider().get()); final KeepAliveProvider heartbeat; if(preferences.getProperty("ssh.heartbeat.provider").equals("keep-alive")) { heartbeat = KeepAliveProvider.KEEP_ALIVE; } else { heartbeat = KeepAliveProvider.HEARTBEAT; } configuration.setKeepAliveProvider(heartbeat); return this.connect(key, configuration); } catch(IOException e) { throw new SFTPExceptionMappingService().map(e); } }
switch (this.keepAliveProvider) { case HEARTBEAT_PROVIDER: defaultConfig.setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); break; default: defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); break;
public DefaultConfig() { setLoggerFactory(LoggerFactory.DEFAULT); setVersion(readVersionFromProperties()); final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered(); initKeyExchangeFactories(bouncyCastleRegistered); initRandomFactory(bouncyCastleRegistered); initFileKeyProviderFactories(bouncyCastleRegistered); initCipherFactories(); initCompressionFactories(); initMACFactories(); initSignatureFactories(); setKeepAliveProvider(KeepAliveProvider.HEARTBEAT); }