mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUAC-821: Properly handle null tunnels.
This commit is contained in:
@@ -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,7 +169,8 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
||||
@Override
|
||||
public void onClose(int i, String string) {
|
||||
try {
|
||||
tunnel.close();
|
||||
if (tunnel != null)
|
||||
tunnel.close();
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
logger.debug("Unable to close WebSocket tunnel.", 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;
|
||||
|
||||
|
@@ -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,7 +201,8 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
||||
@Override
|
||||
public void onClose(int i) {
|
||||
try {
|
||||
tunnel.close();
|
||||
if (tunnel != null)
|
||||
tunnel.close();
|
||||
}
|
||||
catch (GuacamoleException e) {
|
||||
logger.debug("Unable to close WebSocket tunnel.", 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;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user