Search in sources :

Example 1 with PublicKeyAuthenticationClient

use of com.sshtools.j2ssh.authentication.PublicKeyAuthenticationClient in project iaf by ibissource.

the class FtpSession method getSshAuthentication.

private SshAuthenticationClient getSshAuthentication() throws Exception {
    if (StringUtils.isNotEmpty(privateKeyFilePath)) {
        PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
        CredentialFactory pkcf = new CredentialFactory(getPrivateKeyAuthAlias(), getUsername(), getPrivateKeyPassword());
        pk.setUsername(pkcf.getUsername());
        SshPrivateKeyFile pkFile = SshPrivateKeyFile.parse(new File(privateKeyFilePath));
        pk.setKey(pkFile.toPrivateKey(pkcf.getPassword()));
        return pk;
    }
    CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
    if (StringUtils.isNotEmpty(usercf.getPassword())) {
        PasswordAuthenticationClient pac = new PasswordAuthenticationClient();
        pac.setUsername(usercf.getUsername());
        pac.setPassword(usercf.getPassword());
        return pac;
    }
    throw new Exception("Unknown authentication type, either the password or the privateKeyFile must be filled");
}
Also used : SshPrivateKeyFile(com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) SshPrivateKeyFile(com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile) SftpFile(com.sshtools.j2ssh.sftp.SftpFile) File(java.io.File) PasswordAuthenticationClient(com.sshtools.j2ssh.authentication.PasswordAuthenticationClient) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PublicKeyAuthenticationClient(com.sshtools.j2ssh.authentication.PublicKeyAuthenticationClient)

Aggregations

PasswordAuthenticationClient (com.sshtools.j2ssh.authentication.PasswordAuthenticationClient)1 PublicKeyAuthenticationClient (com.sshtools.j2ssh.authentication.PublicKeyAuthenticationClient)1 SftpFile (com.sshtools.j2ssh.sftp.SftpFile)1 SshPrivateKeyFile (com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile)1 File (java.io.File)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)1