Class ApacheSshdSftpSessionFactory

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.sftp.spring.integration.ApacheSshdSftpSessionFactory
All Implemented Interfaces:
SimpleClientConfigurator, BasicCredentialsProvider, MutableBasicCredentials, MutablePassword, MutableUserHolder, PasswordHolder, UsernameHolder, org.apache.sshd.common.config.keys.FilePasswordProviderHolder, org.apache.sshd.common.config.keys.FilePasswordProviderManager, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.integration.file.remote.session.SessionFactory<SftpClient.DirEntry>, org.springframework.integration.file.remote.session.SharedSessionCapable

public class ApacheSshdSftpSessionFactory extends org.apache.sshd.common.util.logging.AbstractLoggingBean implements org.springframework.integration.file.remote.session.SessionFactory<SftpClient.DirEntry>, org.springframework.integration.file.remote.session.SharedSessionCapable, MutableBasicCredentials, org.apache.sshd.common.config.keys.FilePasswordProviderManager, SimpleClientConfigurator, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
A proper replacement for the org.springframework.integration.sftp.session.DefaultSftpSessionFactory
Author:
Apache MINA SSHD Project
  • Constructor Details

    • ApacheSshdSftpSessionFactory

      public ApacheSshdSftpSessionFactory()
    • ApacheSshdSftpSessionFactory

      public ApacheSshdSftpSessionFactory(boolean sharedSession)
  • Method Details

    • getHost

      public String getHost()
    • setHost

      public void setHost(String host)
      Parameters:
      host - The host to connect to - this is a mandatory property.
    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
      The port over which the SFTP connection shall be established. If not specified, this value defaults to 22. If specified, this property must be a positive number.
      Parameters:
      port - The port value
    • getUsername

      public String getUsername()
      Specified by:
      getUsername in interface UsernameHolder
    • setUsername

      public void setUsername(String user)
      The remote user to use. This is a mandatory property.
      Specified by:
      setUsername in interface MutableUserHolder
      Parameters:
      user - The (never null/empty) username
    • getPassword

      public String getPassword()
      Specified by:
      getPassword in interface PasswordHolder
    • setPassword

      public void setPassword(String password)
      The password to authenticate against the remote host. If a password is not provided, then a setPrivateKeyLocation(Resource) call is mandatory.
      Specified by:
      setPassword in interface MutablePassword
      Parameters:
      password - The password to use - if null then no password is set - in which case the getPrivateKeyLocation() resource is used
    • getPrivateKeyLocation

      public org.springframework.core.io.Resource getPrivateKeyLocation()
    • setPrivateKeyLocation

      public void setPrivateKeyLocation(org.springframework.core.io.Resource privateKey)
      Allows you to set a Resource, which represents the location of the private key used for authenticating against the remote host. If the privateKey is not provided, then the setPassword(String) call is mandatory
      Parameters:
      privateKey - The private key Resource
    • getPrivateKeyPassphrase

      public String getPrivateKeyPassphrase()
    • setPrivateKeyPassphrase

      public void setPrivateKeyPassphrase(String privateKeyPassphrase)
      Parameters:
      privateKeyPassphrase - The password for the private key - required if the private key resource is encrypted
    • getFilePasswordProvider

      public org.apache.sshd.common.config.keys.FilePasswordProvider getFilePasswordProvider()
      Specified by:
      getFilePasswordProvider in interface org.apache.sshd.common.config.keys.FilePasswordProviderHolder
    • setFilePasswordProvider

      public void setFilePasswordProvider(org.apache.sshd.common.config.keys.FilePasswordProvider provider)
      Specified by:
      setFilePasswordProvider in interface org.apache.sshd.common.config.keys.FilePasswordProviderManager
    • getPrivateKeyPair

      public KeyPair getPrivateKeyPair()
    • setPrivateKeyPair

      public void setPrivateKeyPair(KeyPair privateKeyPair)
    • getConnectTimeout

      public long getConnectTimeout()
      Specified by:
      getConnectTimeout in interface SimpleClientConfigurator
    • setConnectTimeout

      public void setConnectTimeout(long timeout)
      Specified by:
      setConnectTimeout in interface SimpleClientConfigurator
    • getAuthenticationTimeout

      public long getAuthenticationTimeout()
      Specified by:
      getAuthenticationTimeout in interface SimpleClientConfigurator
    • setAuthenticationTimeout

      public void setAuthenticationTimeout(long timeout)
      Specified by:
      setAuthenticationTimeout in interface SimpleClientConfigurator
    • getSessionConfig

      public Properties getSessionConfig()
    • setSessionConfig

      public void setSessionConfig(Properties sessionConfig)
      Parameters:
      sessionConfig - Extra Properties that can be used to set specific SSHD session properties
    • getSshClient

      public SshClient getSshClient()
    • setSshClient

      public void setSshClient(SshClient sshClient)
    • isSharedSession

      public boolean isSharedSession()
      Specified by:
      isSharedSession in interface org.springframework.integration.file.remote.session.SharedSessionCapable
    • getSftpVersionSelector

      public SftpVersionSelector getSftpVersionSelector()
    • setSftpVersion

      public void setSftpVersion(String version)
    • setSftpVersionSelector

      public void setSftpVersionSelector(SftpVersionSelector selector)
    • getSharedClientSession

      protected ClientSession getSharedClientSession()
    • resetSharedSession

      public void resetSharedSession()
      Specified by:
      resetSharedSession in interface org.springframework.integration.file.remote.session.SharedSessionCapable
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • createSshClientInstance

      protected SshClient createSshClientInstance() throws Exception
      Throws:
      Exception
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • resolveKeyIdentity

      protected KeyPair resolveKeyIdentity(ClientSession session) throws IOException, GeneralSecurityException
      Throws:
      IOException
      GeneralSecurityException
    • resolveFilePasswordProvider

      protected org.apache.sshd.common.config.keys.FilePasswordProvider resolveFilePasswordProvider(ClientSession session, org.springframework.core.io.Resource keyResource, String keyPassword)
    • loadPrivateKey

      protected KeyPair loadPrivateKey(ClientSession session, org.springframework.core.io.Resource keyResource, String keyPassword) throws IOException, GeneralSecurityException
      Throws:
      IOException
      GeneralSecurityException
    • getSession

      public org.springframework.integration.file.remote.session.Session<SftpClient.DirEntry> getSession()
      Specified by:
      getSession in interface org.springframework.integration.file.remote.session.SessionFactory<SftpClient.DirEntry>
    • resolveClientSession

      protected ClientSession resolveClientSession(boolean sharedInstance) throws Exception
      Throws:
      Exception
    • createClientSession

      protected ClientSession createClientSession() throws Exception
      Throws:
      Exception
    • createClientSession

      protected ClientSession createClientSession(String hostname, String username, int port, long timeout) throws IOException
      Throws:
      IOException
    • configureClientSessionProperties

      protected ClientSession configureClientSessionProperties(ClientSession session, Properties props) throws IOException
      Throws:
      IOException
    • authenticateClientSession

      protected ClientSession authenticateClientSession(ClientSession session, long timeout) throws IOException, GeneralSecurityException
      Throws:
      IOException
      GeneralSecurityException
    • getEffectiveTimeoutValue

      protected long getEffectiveTimeoutValue(long timeoutSeconds)