Java Code Examples for org.pentaho.di.core.util.Utils#resolvePassword()

The following examples show how to use org.pentaho.di.core.util.Utils#resolvePassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTTP.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (HTTPMeta) smi;
  data = (HTTPData) sdi;

  if ( super.init( smi, sdi ) ) {
    // get authentication settings once
    data.realProxyHost = environmentSubstitute( meta.getProxyHost() );
    data.realProxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 );
    data.realHttpLogin = environmentSubstitute( meta.getHttpLogin() );
    data.realHttpPassword = Utils.resolvePassword( variables, meta.getHttpPassword() );

    data.realSocketTimeout = Const.toInt( environmentSubstitute( meta.getSocketTimeout() ), -1 );
    data.realConnectionTimeout = Const.toInt( environmentSubstitute( meta.getSocketTimeout() ), -1 );

    return true;
  }
  return false;
}
 
Example 2
Source File: HTTPPOST.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (HTTPPOSTMeta) smi;
  data = (HTTPPOSTData) sdi;

  if ( super.init( smi, sdi ) ) {
    // get authentication settings once
    data.realProxyHost = environmentSubstitute( meta.getProxyHost() );
    data.realProxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 );
    data.realHttpLogin = environmentSubstitute( meta.getHttpLogin() );
    data.realHttpPassword = Utils.resolvePassword( variables, meta.getHttpPassword() );

    data.realSocketTimeout = Const.toInt( environmentSubstitute( meta.getSocketTimeout() ), -1 );
    data.realConnectionTimeout = Const.toInt( environmentSubstitute( meta.getSocketTimeout() ), -1 );
    data.realcloseIdleConnectionsTime =
      Const.toInt( environmentSubstitute( meta.getCloseIdleConnectionsTime() ), -1 );

    return true;
  }
  return false;
}
 
Example 3
Source File: ExcelWriterStep.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * transformation run initialize, may create the output file if specified by user options
 *
 * @see org.pentaho.di.trans.step.BaseStep#init(org.pentaho.di.trans.step.StepMetaInterface,
 * org.pentaho.di.trans.step.StepDataInterface)
 */
@Override
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (ExcelWriterStepMeta) smi;
  data = (ExcelWriterStepData) sdi;
  if ( super.init( smi, sdi ) ) {
    data.splitnr = 0;
    data.datalines = 0;
    data.realSheetname = environmentSubstitute( meta.getSheetname() );
    data.realTemplateSheetName = environmentSubstitute( meta.getTemplateSheetName() );
    data.realTemplateFileName = environmentSubstitute( meta.getTemplateFileName() );
    data.realStartingCell = environmentSubstitute( meta.getStartingCell() );
    data.realPassword = Utils.resolvePassword( variables, meta.getPassword() );
    data.realProtectedBy = environmentSubstitute( meta.getProtectedBy() );

    data.shiftExistingCells = ExcelWriterStepMeta.ROW_WRITE_PUSH_DOWN.equals( meta.getRowWritingMethod() );
    data.createNewSheet = ExcelWriterStepMeta.IF_SHEET_EXISTS_CREATE_NEW.equals( meta.getIfSheetExists() );
    data.createNewFile = ExcelWriterStepMeta.IF_FILE_EXISTS_CREATE_NEW.equals( meta.getIfFileExists() );
    return true;
  }
  return false;
}
 
Example 4
Source File: LdapSslProtocol.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public LdapSslProtocol( LogChannelInterface log, VariableSpace variableSpace, LdapMeta meta,
  Collection<String> binaryAttributes ) {
  super( log, variableSpace, meta, binaryAttributes );
  String trustStorePath = null;
  String trustStorePassword = null;
  boolean trustAllCertificates = false;

  if ( meta.isUseCertificate() ) {
    trustStorePath = variableSpace.environmentSubstitute( meta.getTrustStorePath() );
    trustStorePassword =  Utils.resolvePassword( variableSpace,
            meta.getTrustStorePassword() );
    trustAllCertificates = meta.isTrustAllCertificates();
  }

  this.trustAllCertificates = trustAllCertificates;
  this.trustStorePath = trustStorePath;
  this.trustStorePassword = trustStorePassword;
}
 
Example 5
Source File: SalesforceInsertDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private SalesforceConnection getConnection() throws KettleException {
  String url = transMeta.environmentSubstitute( wURL.getText() );
  // Define a new Salesforce connection
  SalesforceConnection connection =
    new SalesforceConnection( log, url, transMeta.environmentSubstitute( wUserName.getText() ),
      Utils.resolvePassword( transMeta, wPassword.getText() ) );
  int realTimeOut = Const.toInt( transMeta.environmentSubstitute( wTimeOut.getText() ), 0 );
  connection.setTimeOut( realTimeOut );
  // connect to Salesforce
  connection.connect();

  return connection;
}
 
Example 6
Source File: SalesforceUpsertDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private String[] getModuleFields() throws KettleException {
  if ( moduleFields != null ) {
    return moduleFields;
  } else if ( skipFetchModules() || Utils.isEmpty( wModule.getText() ) ) {
    getModulesListError = false;
    return new String[0];
  }

  getModulesListError = true;
  SalesforceUpsertMeta meta = new SalesforceUpsertMeta();
  getInfo( meta );
  String url = transMeta.environmentSubstitute( meta.getTargetURL() );
  String selectedModule = transMeta.environmentSubstitute( meta.getModule() );
  // Define a new Salesforce connection
  SalesforceConnection connection =
    new SalesforceConnection( log, url, transMeta.environmentSubstitute( meta.getUsername() ),
            Utils.resolvePassword( transMeta, meta.getPassword() ) );
  int realTimeOut = Const.toInt( transMeta.environmentSubstitute( meta.getTimeout() ), 0 );
  connection.setTimeOut( realTimeOut );
  Cursor busy = new Cursor( shell.getDisplay(), SWT.CURSOR_WAIT );
  try {
    shell.setCursor( busy );

    // connect to Salesforce
    connection.connect();
    moduleFields = connection.getFields( selectedModule, excludeNonUpdatableFields );
    getModulesListError = false;
    return moduleFields;
  } finally {
    if ( connection != null ) {
      try {
        connection.close();
      } catch ( Exception e ) { /* Ignore */
      }
    }
    shell.setCursor( null );
    busy.dispose();
  }
}
 
Example 7
Source File: MailInputDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private boolean connect() {
  String errordescription = null;
  boolean retval = false;
  if ( mailConn != null && mailConn.isConnected() ) {
    retval = mailConn.isConnected();
  }

  if ( !retval ) {
    String realserver = transMeta.environmentSubstitute( wServerName.getText() );
    String realuser = transMeta.environmentSubstitute( wUserName.getText() );
    String realpass = Utils.resolvePassword( transMeta, wPassword.getText() );
    String realProxyUsername = transMeta.environmentSubstitute( wProxyUsername.getText() );
    int realport = Const.toInt( transMeta.environmentSubstitute( wPort.getText() ), -1 );

    try {
      mailConn =
        new MailConnection(
          LogChannel.UI, MailConnectionMeta.getProtocolFromString(
            wProtocol.getText(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realuser,
          realpass, wUseSSL.getSelection(), wUseProxy.getSelection(), realProxyUsername );
      mailConn.connect();

      retval = true;
    } catch ( Exception e ) {
      errordescription = e.getMessage();
    }
  }

  if ( !retval ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "MailInput.Connected.NOK.ConnectionBad", wServerName.getText() )
      + Const.CR + Const.NVL( errordescription, "" ) );
    mb.setText( BaseMessages.getString( PKG, "MailInput.Connected.Title.Bad" ) );
    mb.open();
  }

  return ( mailConn.isConnected() );

}
 
Example 8
Source File: MonetDBBulkLoader.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected MapiSocket getMonetDBConnection() throws Exception {
  if ( this.meta == null ) {
    throw new KettleException( "No metadata available to determine connection information from." );
  }
  DatabaseMeta dm = meta.getDatabaseMeta();
  String hostname = environmentSubstitute( Const.NVL( dm.getHostname(), "" ) );
  String portnum = environmentSubstitute( Const.NVL( dm.getDatabasePortNumberString(), "" ) );
  String user = environmentSubstitute( Const.NVL( dm.getUsername(), "" ) );
  String password = Utils.resolvePassword( variables, Const.NVL( dm.getPassword(), "" ) );
  String db = environmentSubstitute( Const.NVL( dm.getDatabaseName(), "" ) );

  MapiSocket mserver = getMonetDBConnection( hostname, Integer.valueOf( portnum ), user, password, db, log );
  return mserver;

}
 
Example 9
Source File: SSH.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (SSHMeta) smi;
  data = (SSHData) sdi;

  if ( super.init( smi, sdi ) ) {
    String servername = environmentSubstitute( meta.getServerName() );
    int nrPort = Const.toInt( environmentSubstitute( meta.getPort() ), 22 );
    String username = environmentSubstitute( meta.getuserName() );
    String password = Utils.resolvePassword( variables, meta.getpassword() );
    String keyFilename = environmentSubstitute( meta.getKeyFileName() );
    String passphrase = environmentSubstitute( meta.getPassphrase() );
    int timeOut = Const.toInt( environmentSubstitute( meta.getTimeOut() ), 0 );
    String proxyhost = environmentSubstitute( meta.getProxyHost() );
    int proxyport = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 0 );
    String proxyusername = environmentSubstitute( meta.getProxyUsername() );
    String proxypassword = environmentSubstitute( meta.getProxyPassword() );

    // Check target server
    if ( Utils.isEmpty( servername ) ) {
      logError( BaseMessages.getString( PKG, "SSH.MissingServerName" ) );
    }

    // Check if username field is provided
    if ( Utils.isEmpty( meta.getuserName() ) ) {
      logError( BaseMessages.getString( PKG, "SSH.Error.UserNamedMissing" ) );
      return false;
    }

    // Get output fields
    data.stdOutField = environmentSubstitute( meta.getStdOutFieldName() );
    if ( Utils.isEmpty( data.stdOutField ) ) {
      logError( BaseMessages.getString( PKG, "SSH.Error.StdOutFieldNameMissing" ) );
      return false;
    }
    data.stdTypeField = environmentSubstitute( meta.getStdErrFieldName() );

    try {
      // Open connection
      data.conn =
        SSHData.OpenConnection(
          servername, nrPort, username, password, meta.isusePrivateKey(), keyFilename, passphrase, timeOut,
          this, proxyhost, proxyport, proxyusername, proxypassword );

      if ( log.isDebug() ) {
        logDebug( BaseMessages.getString( PKG, "SSH.Log.ConnectionOpened" ) );
      }

    } catch ( Exception e ) {
      logError( BaseMessages.getString( PKG, "SSH.Error.OpeningConnection", e.getMessage() ) );
      return false;
    }

    return true;
  }
  return false;
}
 
Example 10
Source File: JobEntryFTPPUTDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTP( boolean checkfolder, String remoteFoldername ) {
  boolean retval = false;
  String realServername = null;
  try {
    if ( ftpclient == null || !ftpclient.connected() ) {
      // Create ftp client to host:port ...
      ftpclient = new FTPClient();
      realServername = jobMeta.environmentSubstitute( wServerName.getText() );
      int realPort = Const.toInt( jobMeta.environmentSubstitute( wServerPort.getText() ), 21 );
      ftpclient.setRemoteAddr( InetAddress.getByName( realServername ) );
      ftpclient.setRemotePort( realPort );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        ftpclient.setRemoteAddr( InetAddress.getByName( realProxy_host ) );

        int port = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 21 );
        if ( port != 0 ) {
          ftpclient.setRemotePort( port );
        }
      }

      // login to ftp host ...
      ftpclient.connect();
      String realUsername =
        jobMeta.environmentSubstitute( wUserName.getText() )
          + ( !Utils.isEmpty( wProxyHost.getText() ) ? "@" + realServername : "" )
          + ( !Utils.isEmpty( wProxyUsername.getText() ) ? " "
            + jobMeta.environmentSubstitute( wProxyUsername.getText() ) : "" );

      String realPassword =
        Utils.resolvePassword( jobMeta, wPassword.getText() )
          + ( !Utils.isEmpty( wProxyPassword.getText() ) ? " "
            + Utils.resolvePassword( jobMeta, wProxyPassword.getText() ) : "" );
      // login now ...
      ftpclient.login( realUsername, realPassword );

      pwdFolder = ftpclient.pwd();
    }

    if ( checkfolder ) {
      if ( pwdFolder != null ) {
        ftpclient.chdir( pwdFolder );
      }
      // move to spool dir ...
      if ( !Utils.isEmpty( remoteFoldername ) ) {
        String realFtpDirectory = jobMeta.environmentSubstitute( remoteFoldername );
        ftpclient.chdir( realFtpDirectory );
      }
    }

    retval = true;
  } catch ( Exception e ) {
    if ( ftpclient != null ) {
      try {
        ftpclient.quit();
      } catch ( Exception ignored ) {
        // We've tried quitting the FTP Client exception
        // nothing else can be done if the FTP Client was already disconnected
      }
      ftpclient = null;
    }
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTPPUT.ErrorConnect.NOK", realServername,
        e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTPPUT.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return retval;
}
 
Example 11
Source File: JobEntryFTPDeleteDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTPS() {
  boolean retval = false;
  try {
    if ( ftpsclient == null ) {
      String realServername = jobMeta.environmentSubstitute( wServerName.getText() );
      String realUsername = jobMeta.environmentSubstitute( wUserName.getText() );
      String realPassword = Utils.resolvePassword( jobMeta, wPassword.getText() );
      int port = Const.toInt( jobMeta.environmentSubstitute( wPort.getText() ), 0 );

      // Create ftp client to host:port ...
      ftpsclient =
        new FTPSConnection(
          FTPSConnection.getConnectionTypeByDesc( wConnectionType.getText() ), realServername, port,
          realUsername, realPassword );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        // Set proxy
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        String realProxy_user = jobMeta.environmentSubstitute( wProxyUsername.getText() );
        String realProxy_pass = Utils.resolvePassword( jobMeta, wProxyPassword.getText() );
        ftpsclient.setProxyHost( realProxy_host );
        int proxyport = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 990 );
        if ( proxyport != 0 ) {
          ftpsclient.setProxyPort( proxyport );
        }
        if ( !Utils.isEmpty( realProxy_user ) ) {
          ftpsclient.setProxyUser( realProxy_user );
        }
        if ( !Utils.isEmpty( realProxy_pass ) ) {
          ftpsclient.setProxyPassword( realProxy_pass );
        }
      }

      // login to FTPS host ...
      ftpsclient.connect();
      pwdFolder = ftpsclient.getWorkingDirectory();
    }
    retval = true;
  } catch ( Exception e ) {
    if ( ftpsclient != null ) {
      try {
        ftpsclient.disconnect();
      } catch ( Exception ignored ) {
        // We've tried quitting the FTPS Client exception
        // nothing else to be done if the FTPS Client was already disconnected
      }
      ftpsclient = null;
    }
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTPDelete.ErrorConnect.NOK", e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTPDelete.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return retval;
}
 
Example 12
Source File: JobEntryFTPDeleteDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTP() {
  boolean retval = false;
  String realServername = null;
  try {
    if ( ftpclient == null || !ftpclient.connected() ) {
      // Create ftp client to host:port ...
      ftpclient = new FTPClient();
      realServername = jobMeta.environmentSubstitute( wServerName.getText() );
      int realPort = Const.toInt( jobMeta.environmentSubstitute( wPort.getText() ), 21 );
      ftpclient.setRemoteAddr( InetAddress.getByName( realServername ) );
      ftpclient.setRemotePort( realPort );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        ftpclient.setRemoteAddr( InetAddress.getByName( realProxy_host ) );

        int port = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 21 );
        if ( port != 0 ) {
          ftpclient.setRemotePort( port );
        }
      }

      // login to ftp host ...
      ftpclient.connect();
      String realUsername =
        jobMeta.environmentSubstitute( wUserName.getText() )
          + ( !Utils.isEmpty( wProxyHost.getText() ) ? "@" + realServername : "" )
          + ( !Utils.isEmpty( wProxyUsername.getText() ) ? " "
            + jobMeta.environmentSubstitute( wProxyUsername.getText() ) : "" );

      String realPassword =
        Utils.resolvePassword( jobMeta, wPassword.getText() )
          + ( !Utils.isEmpty( wProxyPassword.getText() ) ? " "
            + Utils.resolvePassword( jobMeta, wProxyPassword.getText() ) : "" );
      // login now ...
      ftpclient.login( realUsername, realPassword );
      pwdFolder = ftpclient.pwd();
    }
    retval = true;
  } catch ( Exception e ) {
    if ( ftpclient != null ) {
      try {
        ftpclient.quit();
      } catch ( Exception ignored ) {
        // We've tried quitting the FTP Client exception
        // nothing else to be done if the FTP Client was already disconnected
      }
      ftpclient = null;
    }
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTPDelete.ErrorConnect.NOK", realServername,
        e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTPDelete.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return retval;
}
 
Example 13
Source File: JobEntryFTPSPUTDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTP( boolean checkfolder, String remoteFoldername ) {
  String realServername = null;
  try {
    realServername = jobMeta.environmentSubstitute( wServerName.getText() );
    int realPort = Const.toInt( jobMeta.environmentSubstitute( wServerPort.getText() ), 0 );
    String realUsername = jobMeta.environmentSubstitute( wUserName.getText() );
    String realPassword = Utils.resolvePassword( jobMeta, wPassword.getText() );

    if ( connection == null ) { // Create ftp client to host:port ...
      connection =
        new FTPSConnection(
          FTPSConnection.getConnectionTypeByDesc( wConnectionType.getText() ), realServername, realPort,
          realUsername, realPassword );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        // Set proxy
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        String realProxy_user = jobMeta.environmentSubstitute( wProxyUsername.getText() );
        String realProxy_pass = Utils.resolvePassword( jobMeta, wProxyPassword.getText() );

        connection.setProxyHost( realProxy_host );
        int proxyport = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 990 );
        if ( proxyport != 0 ) {
          connection.setProxyPort( proxyport );
        }
        if ( !Utils.isEmpty( realProxy_user ) ) {
          connection.setProxyUser( realProxy_user );
        }
        if ( !Utils.isEmpty( realProxy_pass ) ) {
          connection.setProxyPassword( realProxy_pass );
        }
      }

      // login to FTPS host ...
      connection.connect();
    }

    if ( checkfolder ) {
      // move to spool dir ...
      if ( !Utils.isEmpty( remoteFoldername ) ) {
        String realFtpDirectory = jobMeta.environmentSubstitute( remoteFoldername );
        return connection.isDirectoryExists( realFtpDirectory );
      }
    }
    return true;
  } catch ( Exception e ) {
    if ( connection != null ) {
      try {
        connection.disconnect();
      } catch ( Exception ignored ) {
        // We've tried quitting the FTPS Client exception
        // nothing else to be done if the FTPS Client was already disconnected
      }
      connection = null;
    }
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTPSPUT.ErrorConnect.NOK", realServername,
        e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTPSPUT.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return false;
}
 
Example 14
Source File: JobEntryFTPSGetDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTPS( boolean checkfolder, boolean checkmoveToFolder ) {
  boolean retval = true;
  String realServername = null;
  try {
    if ( connection == null ) {
      // Create FTPS client to host:port ...
      realServername = jobMeta.environmentSubstitute( wServerName.getText() );
      int port = Const.toInt( jobMeta.environmentSubstitute( wPort.getText() ), 0 );
      String realUsername = jobMeta.environmentSubstitute( wUserName.getText() );
      String realPassword = Utils.resolvePassword( jobMeta, wPassword.getText() );

      connection =
        new FTPSConnection(
          FTPSConnection.getConnectionTypeByDesc( wConnectionType.getText() ), realServername, port,
          realUsername, realPassword );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        // Set proxy
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        String realProxy_user = jobMeta.environmentSubstitute( wProxyUsername.getText() );
        String realProxy_pass = Utils.resolvePassword( jobMeta, wProxyPassword.getText() );
        connection.setProxyHost( realProxy_host );
        int proxyport = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 990 );
        if ( proxyport != 0 ) {
          connection.setProxyPort( proxyport );
        }
        if ( !Utils.isEmpty( realProxy_user ) ) {
          connection.setProxyUser( realProxy_user );
        }
        if ( !Utils.isEmpty( realProxy_pass ) ) {
          connection.setProxyPassword( realProxy_pass );
        }
      }

      // login to FTPS host ...
      connection.connect();
      // pwdFolder=connection.getWorkingDirectory();
    }

    String realFTPSDirectory = null;
    if ( !Utils.isEmpty( wFTPSDirectory.getText() ) ) {
      realFTPSDirectory = jobMeta.environmentSubstitute( wFTPSDirectory.getText() );
    }

    if ( checkfolder ) {
      // if(pwdFolder!=null) connection.changeDirectory(pwdFolder);
      // move to spool dir ...
      if ( !Utils.isEmpty( realFTPSDirectory ) ) {
        // connection.changeDirectory(realFTPSDirectory);
        retval = connection.isDirectoryExists( realFTPSDirectory );
      }
    }
    if ( checkmoveToFolder ) {
      // if(pwdFolder!=null) connection.changeDirectory(pwdFolder);

      // move to folder ...

      if ( !Utils.isEmpty( wMoveToDirectory.getText() ) ) {
        String realMoveDirectory = jobMeta.environmentSubstitute( wMoveToDirectory.getText() );
        // realMoveDirectory=realFTPSDirectory+"/"+realMoveDirectory;
        // connection.changeDirectory(realMoveDirectory);
        retval = connection.isDirectoryExists( realMoveDirectory );
      }
    }

  } catch ( Exception e ) {
    retval = false;
    if ( connection != null ) {
      try {
        connection.disconnect();
      } catch ( Exception ignored ) {
        // We've tried quitting the FTPS Client exception
        // nothing else to be done if the FTPS Client was already disconnected
      }
      connection = null;
    }
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTPS.ErrorConnect.NOK", realServername,
        e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTPS.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return retval;
}
 
Example 15
Source File: JobEntryFTPDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean connectToFTP( boolean checkfolder, boolean checkmoveToFolder ) {
  boolean retval = false;
  String realServername = null;
  try {
    if ( ftpclient == null || !ftpclient.connected() ) {
      // Create ftp client to host:port ...
      ftpclient = new FTPClient();
      realServername = jobMeta.environmentSubstitute( wServerName.getText() );
      int realPort = Const.toInt( jobMeta.environmentSubstitute( wPort.getText() ), 21 );
      ftpclient.setRemoteAddr( InetAddress.getByName( realServername ) );
      ftpclient.setRemotePort( realPort );

      if ( !Utils.isEmpty( wProxyHost.getText() ) ) {
        String realProxy_host = jobMeta.environmentSubstitute( wProxyHost.getText() );
        ftpclient.setRemoteAddr( InetAddress.getByName( realProxy_host ) );

        int port = Const.toInt( jobMeta.environmentSubstitute( wProxyPort.getText() ), 21 );
        if ( port != 0 ) {
          ftpclient.setRemotePort( port );
        }
      }

      // login to ftp host ...
      ftpclient.connect();
      String realUsername =
        jobMeta.environmentSubstitute( wUserName.getText() )
          + ( !Utils.isEmpty( wProxyHost.getText() ) ? "@" + realServername : "" )
          + ( !Utils.isEmpty( wProxyUsername.getText() ) ? " "
            + jobMeta.environmentSubstitute( wProxyUsername.getText() ) : "" );

      String realPassword =
        Utils.resolvePassword( jobMeta, wPassword.getText() )
          + ( !Utils.isEmpty( wProxyPassword.getText() ) ? " "
            + Utils.resolvePassword( jobMeta, wProxyPassword.getText() ) : "" );
      // login now ...
      ftpclient.login( realUsername, realPassword );
      pwdFolder = ftpclient.pwd();
    }

    String realFtpDirectory = "";
    if ( !Utils.isEmpty( wFtpDirectory.getText() ) ) {
      realFtpDirectory = jobMeta.environmentSubstitute( wFtpDirectory.getText() );
    }

    if ( checkfolder ) {
      if ( pwdFolder != null ) {
        ftpclient.chdir( pwdFolder );
      }
      // move to spool dir ...
      if ( !Utils.isEmpty( realFtpDirectory ) ) {
        ftpclient.chdir( realFtpDirectory );
      }
    }
    if ( checkmoveToFolder ) {
      if ( pwdFolder != null ) {
        ftpclient.chdir( pwdFolder );
      }

      // move to folder ...

      if ( !Utils.isEmpty( wMoveToDirectory.getText() ) ) {
        String realMoveDirectory = jobMeta.environmentSubstitute( wMoveToDirectory.getText() );
        realMoveDirectory = realFtpDirectory + "/" + realMoveDirectory;
        ftpclient.chdir( realMoveDirectory );
      }
    }

    retval = true;
  } catch ( Exception e ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "JobFTP.ErrorConnect.NOK", realServername,
        e.getMessage() ) + Const.CR );
    mb.setText( BaseMessages.getString( PKG, "JobFTP.ErrorConnect.Title.Bad" ) );
    mb.open();
  }
  return retval;
}
 
Example 16
Source File: MondrianHelper.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "deprecation" )
public void openQuery() throws KettleDatabaseException {

  connection = null;
  String realRole = space.environmentSubstitute( role );

  if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
    DataSource dataSource = ( new DatabaseUtil() ).getNamedDataSource( databaseMeta.getDatabaseName() );
    mondrian.olap.Util.PropertyList propList = new mondrian.olap.Util.PropertyList();
    propList.put( "Provider", "mondrian" );
    propList.put( "Catalog", space.environmentSubstitute( catalog ) );

    if ( !Utils.isEmpty( realRole ) ) {
      propList.put( "Role", realRole );
    }

    connection = DriverManager.getConnection( propList, null, dataSource );
  } else {

    String connectString =
      "Provider=mondrian;"
        + "Jdbc='" + space.environmentSubstitute( databaseMeta.getURL() ) + "';" + "Catalog='"
        + space.environmentSubstitute( catalog ) + "';" + "JdbcDrivers="
        + space.environmentSubstitute( databaseMeta.getDriverClass() ) + ";";

    if ( !Utils.isEmpty( databaseMeta.getUsername() ) ) {
      connectString += "JdbcUser=" + space.environmentSubstitute( databaseMeta.getUsername() ) + ";";
    }
    String password = databaseMeta.getPassword();
    if ( !Utils.isEmpty( password ) ) {
      String realPassword = Utils.resolvePassword( space, password );
      connectString += "JdbcPassword=" + space.environmentSubstitute( realPassword ) + ";";
    }

    if ( !Utils.isEmpty( realRole ) ) {
      connectString += "Role=" + realRole + ";";
    }

    connection = DriverManager.getConnection( connectString, null );

  }

  query = connection.parseQuery( queryString );
  result = connection.execute( query );
}
 
Example 17
Source File: JobEntryFTPDelete.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void FTPSConnect( String realservername, String realusername, int realport, String realpassword,
  String realFTPDirectory, int realtimeout ) throws Exception {
  // Create ftps client to host ...
  ftpsclient =
    new FTPSConnection( getFTPSConnectionType(), realservername, realport, realusername, realpassword );

  if ( !Utils.isEmpty( proxyHost ) ) {
    String realProxy_host = environmentSubstitute( proxyHost );
    String realProxy_username = environmentSubstitute( proxyUsername );
    String realProxy_password = Utils.resolvePassword( this, proxyPassword );

    ftpsclient.setProxyHost( realProxy_host );
    if ( !Utils.isEmpty( realProxy_username ) ) {
      ftpsclient.setProxyUser( realProxy_username );
    }
    if ( !Utils.isEmpty( realProxy_password ) ) {
      ftpsclient.setProxyPassword( realProxy_password );
    }
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPDelete.OpenedProxyConnectionOn", realProxy_host ) );
    }

    int proxyport = Const.toInt( environmentSubstitute( proxyPort ), 21 );
    if ( proxyport != 0 ) {
      ftpsclient.setProxyPort( proxyport );
    }
  } else {
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPDelete.OpenedConnectionTo", realservername ) );
    }
  }

  // set activeConnection connectmode ...
  if ( activeConnection ) {
    ftpsclient.setPassiveMode( false );
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPDelete.SetActive" ) );
    }
  } else {
    ftpsclient.setPassiveMode( true );
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPDelete.SetPassive" ) );
    }
  }

  // Set the timeout
  ftpsclient.setTimeOut( realtimeout );
  if ( isDetailed() ) {
    logDetailed( BaseMessages.getString( PKG, "JobEntryFTPDelete.SetTimeout", String.valueOf( realtimeout ) ) );
  }

  // now connect
  ftpsclient.connect();

  // move to spool dir ...
  if ( !Utils.isEmpty( realFTPDirectory ) ) {
    ftpsclient.changeDirectory( realFTPDirectory );
    if ( isDetailed() ) {
      logDetailed( "Changed to directory [" + realFTPDirectory + "]" );
    }
  }
}
 
Example 18
Source File: JobEntrySFTP.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public String getRealPassword( String password ) {
  return Utils.resolvePassword( variables, password );
}
 
Example 19
Source File: JobEntrySendNagiosPassiveCheck.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) {
  log.logBasic( BaseMessages.getString( PKG, "JobEntrySendNagiosPassiveCheck.Started", serverName ) );

  Result result = previousResult;
  result.setNrErrors( 1 );
  result.setResult( false );

  // Target
  String realServername = environmentSubstitute( serverName );
  String realPassword = Utils.resolvePassword( variables, password );
  int realPort = Const.toInt( environmentSubstitute( port ), DEFAULT_PORT );
  int realResponseTimeOut = Const.toInt( environmentSubstitute( responseTimeOut ), DEFAULT_RESPONSE_TIME_OUT );
  int realConnectionTimeOut =
    Const.toInt( environmentSubstitute( connectionTimeOut ), DEFAULT_CONNECTION_TIME_OUT );

  // Sender
  String realSenderServerName = environmentSubstitute( senderServerName );
  String realSenderServiceName = environmentSubstitute( senderServiceName );

  try {
    if ( Utils.isEmpty( realServername ) ) {
      throw new KettleException( BaseMessages.getString(
        PKG, "JobSendNagiosPassiveCheck.Error.TargetServerMissing" ) );
    }

    String realMessageString = environmentSubstitute( message );

    if ( Utils.isEmpty( realMessageString ) ) {
      throw new KettleException( BaseMessages.getString( PKG, "JobSendNagiosPassiveCheck.Error.MessageMissing" ) );
    }

    Level level = Level.UNKNOWN;
    switch ( getLevel() ) {
      case LEVEL_TYPE_OK:
        level = Level.OK;
        break;
      case LEVEL_TYPE_CRITICAL:
        level = Level.CRITICAL;
        break;
      case LEVEL_TYPE_WARNING:
        level = Level.WARNING;
        break;
      default:
        break;
    }
    Encryption encr = Encryption.NONE;
    switch ( getEncryptionMode() ) {
      case ENCRYPTION_MODE_TRIPLEDES:
        encr = Encryption.TRIPLE_DES;
        break;
      case ENCRYPTION_MODE_XOR:
        encr = Encryption.XOR;
        break;
      default:
        break;
    }

    // settings
    NagiosSettingsBuilder ns = new NagiosSettingsBuilder();
    ns.withNagiosHost( realServername );
    ns.withPort( realPort );
    ns.withConnectionTimeout( realConnectionTimeOut );
    ns.withResponseTimeout( realResponseTimeOut );
    ns.withEncryption( encr );
    if ( !Utils.isEmpty( realPassword ) ) {
      ns.withPassword( realPassword );
    } else {
      ns.withNoPassword();
    }

    // target nagios host
    NagiosSettings settings = ns.create();

    // sender
    MessagePayloadBuilder pb = new MessagePayloadBuilder();
    if ( !Utils.isEmpty( realSenderServerName ) ) {
      pb.withHostname( realSenderServerName );
    }
    pb.withLevel( level );
    if ( !Utils.isEmpty( realSenderServiceName ) ) {
      pb.withServiceName( realSenderServiceName );
    }
    pb.withMessage( realMessageString );
    MessagePayload payload = pb.create();

    NagiosPassiveCheckSender sender = new NagiosPassiveCheckSender( settings );

    sender.send( payload );

    result.setNrErrors( 0 );
    result.setResult( true );

  } catch ( Exception e ) {
    log.logError( BaseMessages.getString( PKG, "JobEntrySendNagiosPassiveCheck.ErrorGetting", e.toString() ) );
  }

  return result;
}
 
Example 20
Source File: JobEntryGetPOP.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * @param password string for resolving
 * @return Returns resolved decrypted password or null
 * in case of param returns null.
 */
public String getRealPassword( String password ) {
  return Utils.resolvePassword( variables, password );
}