GUAC-821: Properly handle null tunnels.

This commit is contained in:
Michael Jumper
2014-10-12 21:52:36 -07:00
parent 39ac1a191c
commit 59356af44e
2 changed files with 53 additions and 2 deletions

View File

@@ -103,6 +103,12 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
@Override
public void onOpen(final Connection connection) {
// Do not start connection if tunnel does not exist
if (tunnel == null) {
closeConnection(connection, GuacamoleStatus.RESOURCE_NOT_FOUND);
return;
}
Thread readThread = new Thread() {
@Override
@@ -163,6 +169,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
@Override
public void onClose(int i, String string) {
try {
if (tunnel != null)
tunnel.close();
}
catch (GuacamoleException e) {
@@ -174,6 +181,22 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
}
/**
* Called whenever the JavaScript Guacamole client makes a connection
* request. It it up to the implementor of this function to define what
* conditions must be met for a tunnel to be configured and returned as a
* result of this connection request (whether some sort of credentials must
* be specified, for example).
*
* @param request The HttpServletRequest associated with the connection
* request received. Any parameters specified along with
* the connection request can be read from this object.
* @return A newly constructed GuacamoleTunnel if successful,
* null otherwise.
* @throws GuacamoleException If an error occurs while constructing the
* GuacamoleTunnel, or if the conditions
* required for connection are not met.
*/
protected abstract GuacamoleTunnel doConnect(HttpServletRequest request)
throws GuacamoleException;

View File

@@ -130,6 +130,17 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
@Override
public void onOpen(final WsOutbound outbound) {
// Do not start connection if tunnel does not exist
if (tunnel == null) {
try {
closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND);
}
catch (IOException e) {
logger.debug("Tunnel not found, but unable to signal closure of WebSocket.", e);
}
return;
}
Thread readThread = new Thread() {
@Override
@@ -190,6 +201,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
@Override
public void onClose(int i) {
try {
if (tunnel != null)
tunnel.close();
}
catch (GuacamoleException e) {
@@ -206,6 +218,22 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
}
/**
* Called whenever the JavaScript Guacamole client makes a connection
* request. It it up to the implementor of this function to define what
* conditions must be met for a tunnel to be configured and returned as a
* result of this connection request (whether some sort of credentials must
* be specified, for example).
*
* @param request The HttpServletRequest associated with the connection
* request received. Any parameters specified along with
* the connection request can be read from this object.
* @return A newly constructed GuacamoleTunnel if successful,
* null otherwise.
* @throws GuacamoleException If an error occurs while constructing the
* GuacamoleTunnel, or if the conditions
* required for connection are not met.
*/
protected abstract GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException;
}