Package adams.scripting.connection
Class AbstractSSHConnection
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.scripting.connection.AbstractConnection
-
- adams.scripting.connection.AbstractSSHConnection
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,SSHSessionProvider
,OptionHandler
,PasswordSupporter
,QuickInfoSupporter
,SizeOfHandler
,Connection
,Serializable
,Comparable<Connection>
- Direct Known Subclasses:
AbstractSSHConnectionWithPortForwarding
,ScpConnection
public abstract class AbstractSSHConnection extends AbstractConnection implements SSHSessionProvider, PasswordSupporter
Ancestor of connection schemes that use an SSH tunnel to connect to the remote scripting engine.
Inspired by: www.beanizer.org- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractSSHConnection.TrustAll
Dummy implementation that trusts all.
-
Field Summary
Fields Modifier and Type Field Description protected int
m_AssignedPort
the assigned port.protected SSHAuthenticationType
m_AuthenticationType
the type of authentication to use.protected String
m_Host
the SSH host.protected PlaceholderFile
m_KnownHosts
the file with known hosts.protected BasePassword
m_Password
the SSH password to use.protected int
m_Port
the SSH port.protected PlaceholderFile
m_PrivateKeyFile
the location of the private key.protected BasePassword
m_PrivateKeyPassphrase
the passphrase for the private key.protected com.jcraft.jsch.Session
m_Session
the SSH session.protected boolean
m_StrictHostKeyChecking
whether to perform strict host key checking (only disable for testing!! insecure!!).protected String
m_User
the SSH user to use.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractSSHConnection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
authenticationTypeTipText()
Returns the tip text for this property.void
cleanUp()
Cleans up data structures, frees up memory.protected com.jcraft.jsch.Session
createSession(String host, int port)
Creates a newSession
object, but does not connect or establish the tunnel.void
defineOptions()
Adds options to the internal list of options.protected abstract String
doSend(RemoteCommand cmd, RemoteCommandProcessor processor, boolean request)
Sends the command to the specified sscripting engine.protected String
doSendRequest(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the request command.protected String
doSendResponse(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the response command.SSHAuthenticationType
getAuthenticationType()
Returns the type of authentication to use.String
getHost()
Returns the host to connect to.PlaceholderFile
getKnownHosts()
Returns the file with the known hosts.BasePassword
getPassword()
Returns the SSH password to use.int
getPort()
Returns the remote SSH port to connect to.PlaceholderFile
getPrivateKeyFile()
Returns the location of the private key file.BasePassword
getPrivateKeyPassphrase()
Returns the passphrase for the private key file, ignored if empty.String
getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.com.jcraft.jsch.Session
getSession()
Returns the SSH session.boolean
getStrictHostKeyChecking()
Returns whether to perform strict host key checking.String
getUser()
Returns the SSH user name to use.String
hostTipText()
Returns the tip text for this property.String
knownHostsTipText()
Returns the tip text for this property.com.jcraft.jsch.Session
newSession()
Returns a new session, connects and configures the tunnel.com.jcraft.jsch.Session
newSession(String host, int port)
Returns a new session and connects.String
passwordTipText()
Returns the tip text for this property.String
portTipText()
Returns the tip text for this property.String
privateKeyFileTipText()
Returns the tip text for this property.String
privateKeyPassphraseTipText()
Returns the tip text for this property.protected void
reset()
Resets the scheme.protected String
send(RemoteCommand cmd, RemoteCommandProcessor processor, boolean request)
Sends the command to the specified sscripting engine.void
setAuthenticationType(SSHAuthenticationType value)
Sets the type of authentication to use.void
setHost(String value)
Sets the host to connect to.void
setKnownHosts(PlaceholderFile value)
Sets the file with the known hosts.void
setPassword(BasePassword value)
Sets the SSH password to use.void
setPort(int value)
Sets the remote SSH port to connect to.void
setPrivateKeyFile(PlaceholderFile value)
Sets the location of the private key file.void
setPrivateKeyPassphrase(BasePassword value)
Sets the passphrase for the private key file, ignored if empty.void
setStrictHostKeyChecking(boolean value)
Sets whether to perform strict host key checking.void
setUser(String value)
Sets the SSH user to use.String
strictHostKeyCheckingTipText()
Returns the tip text for this property.String
userTipText()
Returns the tip text for this property.-
Methods inherited from class adams.scripting.connection.AbstractConnection
checkRequest, checkResponse, compareTo, equals, sendRequest, sendResponse, toString
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
m_Host
protected String m_Host
the SSH host.
-
m_Port
protected int m_Port
the SSH port.
-
m_AuthenticationType
protected SSHAuthenticationType m_AuthenticationType
the type of authentication to use.
-
m_User
protected String m_User
the SSH user to use.
-
m_Password
protected BasePassword m_Password
the SSH password to use.
-
m_PrivateKeyFile
protected PlaceholderFile m_PrivateKeyFile
the location of the private key.
-
m_PrivateKeyPassphrase
protected BasePassword m_PrivateKeyPassphrase
the passphrase for the private key.
-
m_KnownHosts
protected PlaceholderFile m_KnownHosts
the file with known hosts.
-
m_StrictHostKeyChecking
protected boolean m_StrictHostKeyChecking
whether to perform strict host key checking (only disable for testing!! insecure!!).
-
m_Session
protected transient com.jcraft.jsch.Session m_Session
the SSH session.
-
m_AssignedPort
protected int m_AssignedPort
the assigned port.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in classAbstractOptionHandler
-
setHost
public void setHost(String value)
Sets the host to connect to.- Parameters:
value
- the host name/ip
-
getHost
public String getHost()
Returns the host to connect to.- Returns:
- the host name/ip
-
hostTipText
public String hostTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPort
public void setPort(int value)
Sets the remote SSH port to connect to.- Parameters:
value
- the port
-
getPort
public int getPort()
Returns the remote SSH port to connect to.- Returns:
- the port
-
portTipText
public String portTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAuthenticationType
public void setAuthenticationType(SSHAuthenticationType value)
Sets the type of authentication to use.- Parameters:
value
- the type
-
getAuthenticationType
public SSHAuthenticationType getAuthenticationType()
Returns the type of authentication to use.- Returns:
- the type
-
authenticationTypeTipText
public String authenticationTypeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setUser
public void setUser(String value)
Sets the SSH user to use.- Parameters:
value
- the user name
-
getUser
public String getUser()
Returns the SSH user name to use.- Returns:
- the user name
-
userTipText
public String userTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPassword
public void setPassword(BasePassword value)
Sets the SSH password to use.- Specified by:
setPassword
in interfacePasswordSupporter
- Parameters:
value
- the password
-
getPassword
public BasePassword getPassword()
Returns the SSH password to use.- Specified by:
getPassword
in interfacePasswordSupporter
- Returns:
- the password
-
passwordTipText
public String passwordTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPrivateKeyFile
public void setPrivateKeyFile(PlaceholderFile value)
Sets the location of the private key file.- Parameters:
value
- the key file
-
getPrivateKeyFile
public PlaceholderFile getPrivateKeyFile()
Returns the location of the private key file.- Returns:
- the key file
-
privateKeyFileTipText
public String privateKeyFileTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPrivateKeyPassphrase
public void setPrivateKeyPassphrase(BasePassword value)
Sets the passphrase for the private key file, ignored if empty.- Parameters:
value
- the passphrase
-
getPrivateKeyPassphrase
public BasePassword getPrivateKeyPassphrase()
Returns the passphrase for the private key file, ignored if empty.- Returns:
- the passphrase
-
privateKeyPassphraseTipText
public String privateKeyPassphraseTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setKnownHosts
public void setKnownHosts(PlaceholderFile value)
Sets the file with the known hosts.- Parameters:
value
- the file
-
getKnownHosts
public PlaceholderFile getKnownHosts()
Returns the file with the known hosts.- Returns:
- the file
-
knownHostsTipText
public String knownHostsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStrictHostKeyChecking
public void setStrictHostKeyChecking(boolean value)
Sets whether to perform strict host key checking. NB: only disabled for testing, as it is very insecure to disable it!- Parameters:
value
- if true then strict checking is on
-
getStrictHostKeyChecking
public boolean getStrictHostKeyChecking()
Returns whether to perform strict host key checking. NB: only disabled for testing, as it is very insecure to disable it!- Returns:
- true if strict checking is on
-
strictHostKeyCheckingTipText
public String strictHostKeyCheckingTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractConnection
- Returns:
- null if no info available, otherwise short string
-
createSession
protected com.jcraft.jsch.Session createSession(String host, int port) throws Exception
Creates a newSession
object, but does not connect or establish the tunnel.- Returns:
- the Session object
- Throws:
Exception
-
newSession
public com.jcraft.jsch.Session newSession()
Returns a new session, connects and configures the tunnel.- Specified by:
newSession
in interfaceSSHSessionProvider
- Returns:
- the session
-
newSession
public com.jcraft.jsch.Session newSession(String host, int port)
Returns a new session and connects.- Specified by:
newSession
in interfaceSSHSessionProvider
- Parameters:
host
- the host to useport
- the port to use- Returns:
- the session
-
getSession
public com.jcraft.jsch.Session getSession()
Returns the SSH session. Attempts to reconnect when necessary or create new session when none present.- Specified by:
getSession
in interfaceSSHSessionProvider
- Returns:
- the SSH session, null if not connected
-
doSend
protected abstract String doSend(RemoteCommand cmd, RemoteCommandProcessor processor, boolean request)
Sends the command to the specified sscripting engine.- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsingrequest
- whether Request or Response- Returns:
- null if successfully sent, otherwise error message
-
send
protected String send(RemoteCommand cmd, RemoteCommandProcessor processor, boolean request)
Sends the command to the specified sscripting engine.- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsingrequest
- whether Request or Response- Returns:
- null if successfully sent, otherwise error message
-
doSendRequest
protected String doSendRequest(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the request command.- Specified by:
doSendRequest
in classAbstractConnection
- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsing- Returns:
- null if successful, otherwise error message
-
doSendResponse
protected String doSendResponse(RemoteCommand cmd, RemoteCommandProcessor processor)
Sends the response command.- Specified by:
doSendResponse
in classAbstractConnection
- Parameters:
cmd
- the command to sendprocessor
- the processor for formatting/parsing- Returns:
- null if successful, otherwise error message
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractConnection
-
-