@Test public void testOpenConnectionTimeOut() throws Exception { when( connection.authenticateWithPassword( username, password ) ).thenReturn( true ); assertNotNull( SSHData.OpenConnection( server, port, username, password, false, null, null, 100, null, null, proxyPort, proxyUsername, proxyPassword ) ); verify( connection ).connect( isNull( ServerHostKeyVerifier.class ), eq( 0 ), eq( 100 * 1000 ) ); }
public static Connection OpenConnection( String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword ) throws KettleException { Connection conn = null; char[] content = null; boolean isAuthenticated = false; try { if ( useKey ) { if ( Utils.isEmpty( keyFilename ) ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) ); } FileObject keyFileObject = KettleVFS.getFileObject( keyFilename ); if ( !keyFileObject.exists() ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) ); } FileContent keyFileContent = keyFileObject.getContent(); CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() ); try ( InputStream in = keyFileContent.getInputStream() ) { IOUtils.copy( in, charArrayWriter ); } content = charArrayWriter.toCharArray(); } conn = createConnection( serveur, port ); if ( !Utils.isEmpty( proxyhost ) ) { if ( !Utils.isEmpty( proxyusername ) ) { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) ); } else { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) ); } } if ( timeOut == 0 ) { conn.connect(); } else { conn.connect( null, 0, timeOut * 1000 ); } if ( useKey ) { isAuthenticated = conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password ); } if ( isAuthenticated == false ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) ); } } catch ( Exception e ) { if ( conn != null ) { conn.close(); } throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e ); } return conn; }
SSHData extends BaseStepData implements StepDataInterface { public static Connection OpenConnection( String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword ) throws KettleException { Connection conn = null; char[] content = null; boolean isAuthenticated = false; try { if ( useKey ) { if ( Utils.isEmpty( keyFilename ) ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) ); } FileObject keyFileObject = KettleVFS.getFileObject( keyFilename ); if ( !keyFileObject.exists() ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) ); } FileContent keyFileContent = keyFileObject.getContent(); CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() ); try ( InputStream in = keyFileContent.getInputStream() ) { IOUtils.copy( in, charArrayWriter ); } content = charArrayWriter.toCharArray(); } conn = createConnection( serveur, port ); if ( !Utils.isEmpty( proxyhost ) ) { if ( !Utils.isEmpty( proxyusername ) ) { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) ); } else { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) ); } } if ( timeOut == 0 ) { conn.connect(); } else { conn.connect( null, 0, timeOut * 1000 ); } if ( useKey ) { isAuthenticated = conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password ); } if ( isAuthenticated == false ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) ); } } catch ( Exception e ) { if ( conn != null ) { conn.close(); } throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e ); } return conn; } }
SSHData extends BaseStepData implements StepDataInterface { public static Connection OpenConnection( String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword ) throws KettleException { Connection conn = null; char[] content = null; boolean isAuthenticated = false; try { if ( useKey ) { if ( Utils.isEmpty( keyFilename ) ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) ); } FileObject keyFileObject = KettleVFS.getFileObject( keyFilename ); if ( !keyFileObject.exists() ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) ); } FileContent keyFileContent = keyFileObject.getContent(); CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() ); try ( InputStream in = keyFileContent.getInputStream() ) { IOUtils.copy( in, charArrayWriter ); } content = charArrayWriter.toCharArray(); } conn = createConnection( serveur, port ); if ( !Utils.isEmpty( proxyhost ) ) { if ( !Utils.isEmpty( proxyusername ) ) { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) ); } else { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) ); } } if ( timeOut == 0 ) { conn.connect(); } else { conn.connect( null, 0, timeOut * 1000 ); } if ( useKey ) { isAuthenticated = conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password ); } if ( isAuthenticated == false ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) ); } } catch ( Exception e ) { if ( conn != null ) { conn.close(); } throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e ); } return conn; } SSHData(); }
SSHData extends BaseStepData implements StepDataInterface { public static Connection OpenConnection( String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword ) throws KettleException { Connection conn = null; char[] content = null; boolean isAuthenticated = false; try { if ( useKey ) { if ( Utils.isEmpty( keyFilename ) ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) ); } FileObject keyFileObject = KettleVFS.getFileObject( keyFilename ); if ( !keyFileObject.exists() ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) ); } FileContent keyFileContent = keyFileObject.getContent(); CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() ); try ( InputStream in = keyFileContent.getInputStream() ) { IOUtils.copy( in, charArrayWriter ); } content = charArrayWriter.toCharArray(); } conn = createConnection( serveur, port ); if ( !Utils.isEmpty( proxyhost ) ) { if ( !Utils.isEmpty( proxyusername ) ) { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) ); } else { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) ); } } if ( timeOut == 0 ) { conn.connect(); } else { conn.connect( null, 0, timeOut * 1000 ); } if ( useKey ) { isAuthenticated = conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password ); } if ( isAuthenticated == false ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) ); } } catch ( Exception e ) { if ( conn != null ) { conn.close(); } throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e ); } return conn; } SSHData(); static Connection OpenConnection( String serveur, int port, String username, String password,
      boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost,
      int proxyport, String proxyusername, String proxypassword ); }
SSHData extends BaseStepData implements StepDataInterface { public static Connection OpenConnection( String serveur, int port, String username, String password, boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost, int proxyport, String proxyusername, String proxypassword ) throws KettleException { Connection conn = null; char[] content = null; boolean isAuthenticated = false; try { if ( useKey ) { if ( Utils.isEmpty( keyFilename ) ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) ); } FileObject keyFileObject = KettleVFS.getFileObject( keyFilename ); if ( !keyFileObject.exists() ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) ); } FileContent keyFileContent = keyFileObject.getContent(); CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() ); try ( InputStream in = keyFileContent.getInputStream() ) { IOUtils.copy( in, charArrayWriter ); } content = charArrayWriter.toCharArray(); } conn = createConnection( serveur, port ); if ( !Utils.isEmpty( proxyhost ) ) { if ( !Utils.isEmpty( proxyusername ) ) { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) ); } else { conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) ); } } if ( timeOut == 0 ) { conn.connect(); } else { conn.connect( null, 0, timeOut * 1000 ); } if ( useKey ) { isAuthenticated = conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) ); } else { isAuthenticated = conn.authenticateWithPassword( username, password ); } if ( isAuthenticated == false ) { throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) ); } } catch ( Exception e ) { if ( conn != null ) { conn.close(); } throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e ); } return conn; } SSHData(); static Connection OpenConnection( String serveur, int port, String username, String password,
      boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost,
      int proxyport, String proxyusername, String proxypassword ); public int indexOfCommand; public Connection conn; public boolean wroteOneRow; public String commands; public int nrInputFields; public int nrOutputFields; public String stdOutField; public String stdTypeField; public RowMetaInterface outputRowMeta; }