public class TunnelConnectionManager extends Object implements Closeable
| Constructor and Description |
|---|
TunnelConnectionManager(ISessionFactory baseSessionFactory)
Creates a TunnelConnectionManager that will use the
baseSessionFactory to obtain its session connections. |
TunnelConnectionManager(ISessionFactory baseSessionFactory,
Iterable<String> pathAndSpecList)
Creates a TunnelConnectionManager that will use the
baseSessionFactory to obtain its session connections and
provide the tunnels specified. |
TunnelConnectionManager(ISessionFactory baseSessionFactory,
String... pathAndSpecList)
Creates a TunnelConnectionManager that will use the
baseSessionFactory to obtain its session connections and
provide the tunnels specified. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all sessions and their associated tunnels.
|
void |
ensureOpen()
Will re-open any connections that are not still open.
|
Tunnel |
getTunnel(String destinationHostname,
int destinationPort)
Returns the tunnel matching the supplied values, or
null if
there isn't one that matches. |
void |
open()
Opens all the necessary sessions and connects all of the tunnels.
|
void |
setTunnelConnections(Iterable<String> pathAndSpecList)
Creates a set of tunnel connections based upon the pathAndTunnels.
|
void |
setTunnelConnectionsFromFile(File tunnelsConfig,
Charset aCharset)
Creates a set of tunnel connections based upon the contents of
tunnelsConfig. |
public TunnelConnectionManager(ISessionFactory baseSessionFactory) throws com.jcraft.jsch.JSchException
baseSessionFactory to obtain its session connections. Because
this constructor does not set the tunnel connections for you, you will need
to call setTunnelConnections(Iterable).baseSessionFactory - The session factorycom.jcraft.jsch.JSchException - For connection failuressetTunnelConnections(Iterable)public TunnelConnectionManager(ISessionFactory baseSessionFactory, String... pathAndSpecList) throws com.jcraft.jsch.JSchException
baseSessionFactory to obtain its session connections and
provide the tunnels specified.baseSessionFactory - The session factorypathAndSpecList - A list of path and spec
stringscom.jcraft.jsch.JSchException - For connection failuressetTunnelConnections(Iterable)public TunnelConnectionManager(ISessionFactory baseSessionFactory, Iterable<String> pathAndSpecList) throws com.jcraft.jsch.JSchException
baseSessionFactory to obtain its session connections and
provide the tunnels specified.baseSessionFactory - The session factorypathAndSpecList - A list of path and spec
stringscom.jcraft.jsch.JSchException - For connection failuressetTunnelConnections(Iterable)public void close()
close in interface Closeableclose in interface AutoCloseableTunnelConnection.close()public void ensureOpen()
throws com.jcraft.jsch.JSchException
com.jcraft.jsch.JSchException - For connection failurespublic Tunnel getTunnel(String destinationHostname, int destinationPort)
null if
there isn't one that matches.destinationHostname - The tunnels destination hostnamedestinationPort - The tunnels destination portTunnelConnection.getTunnel(String, int)public void open()
throws com.jcraft.jsch.JSchException
com.jcraft.jsch.JSchException - For connection failuresTunnelConnection.open()public void setTunnelConnectionsFromFile(File tunnelsConfig, @Nonnull Charset aCharset) throws IOException, com.jcraft.jsch.JSchException
tunnelsConfig. The format of this file is one path and tunnel
per line. Comments and empty lines are allowed and are excluded using the
pattern ^\s*(?:#.*)?$.tunnelsConfig - A file containing tunnel configurationaCharset - Charset to use. May not be null.IOException - If unable to read from tunnelsConfigcom.jcraft.jsch.JSchException - For connection failurespublic void setTunnelConnections(Iterable<String> pathAndSpecList) throws com.jcraft.jsch.JSchException
path and tunnels = path and tunnel, {new line, path and tunnel}
path and tunnel = path, "|", tunnel
new line = "\n"
path = path part, {"->", path part}
path part = {user, "@"}, hostname
tunnel = {local part}, ":", destination hostname, ":", destination port
local part = {local alias, ":"}, local port
local alias = hostname
local port = port
destination hostname = hostname
destination port = port
user = ? user name ?
hostname = ? hostname ?
port = ? port ?
For example:
jimhenson@admin.muppets.com->animal@drteethandtheelectricmahem.muppets.com|drteeth:8080:drteeth.muppets.com:80
Says open an ssh connection as user jimhenson to host
admin.muppets.com. Then, through that connection, open a
connection as user animal to host
drteethandtheelectricmahem.muppets.com. Then map local port
8080 on the interface with alias drteeth through
the two-hop tunnel to port 80 on
drteeth.muppets.com.
pathAndSpecList - A list of path and spec entriescom.jcraft.jsch.JSchException - For connection failuresCopyright © 2020 Philip Helger. All rights reserved.