mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-553: Send Guacamole status code as sole content of WebSocket close frame.
This commit is contained in:
@@ -32,8 +32,7 @@ import org.eclipse.jetty.websocket.WebSocket;
|
|||||||
import org.eclipse.jetty.websocket.WebSocket.Connection;
|
import org.eclipse.jetty.websocket.WebSocket.Connection;
|
||||||
import org.eclipse.jetty.websocket.WebSocketServlet;
|
import org.eclipse.jetty.websocket.WebSocketServlet;
|
||||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
import org.glyptodon.guacamole.protocol.GuacamoleStatus;
|
||||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -54,6 +53,22 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
*/
|
*/
|
||||||
private static final int BUFFER_SIZE = 8192;
|
private static final int BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an error on the given WebSocket connection and closes the
|
||||||
|
* connection. The error sent is determined from using the information
|
||||||
|
* within the given GuacamoleStatus.
|
||||||
|
*
|
||||||
|
* @param connection The WebSocket connection to close.
|
||||||
|
* @param guac_status The status to send.
|
||||||
|
*/
|
||||||
|
public static void sendError(Connection connection,
|
||||||
|
GuacamoleStatus guac_status) {
|
||||||
|
|
||||||
|
connection.close(guac_status.getWebSocketCode(),
|
||||||
|
Integer.toString(guac_status.getGuacamoleStatusCode()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
|
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
|
||||||
|
|
||||||
@@ -124,21 +139,13 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
// Catch any thrown guacamole exception and attempt
|
// Catch any thrown guacamole exception and attempt
|
||||||
// to pass within the WebSocket connection, logging
|
// to pass within the WebSocket connection, logging
|
||||||
// each error appropriately.
|
// each error appropriately.
|
||||||
catch (GuacamoleSecurityException e) {
|
|
||||||
logger.warn("Authorization failed.", e);
|
|
||||||
connection.close(1008, null); // Policy violation
|
|
||||||
}
|
|
||||||
catch (GuacamoleResourceNotFoundException e) {
|
|
||||||
logger.debug("Resource not found.", e);
|
|
||||||
connection.close(1002, null); // Protocol error
|
|
||||||
}
|
|
||||||
catch (GuacamoleClientException e) {
|
catch (GuacamoleClientException e) {
|
||||||
logger.warn("Error in client request.", e);
|
logger.warn("Client request rejected: {}", e.getMessage());
|
||||||
connection.close(1002, null); // Protocol error
|
sendError(connection, e.getStatus());
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Server error in tunnel", e);
|
logger.error("Internal server error.", e);
|
||||||
connection.close(1011, null); // Server error
|
sendError(connection, e.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ package org.glyptodon.guacamole.net.basic.websocket.tomcat;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import org.apache.catalina.websocket.Constants;
|
import org.apache.catalina.websocket.Constants;
|
||||||
@@ -36,8 +37,7 @@ import org.apache.catalina.websocket.StreamInbound;
|
|||||||
import org.apache.catalina.websocket.WebSocketServlet;
|
import org.apache.catalina.websocket.WebSocketServlet;
|
||||||
import org.apache.catalina.websocket.WsOutbound;
|
import org.apache.catalina.websocket.WsOutbound;
|
||||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||||
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
|
import org.glyptodon.guacamole.protocol.GuacamoleStatus;
|
||||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -58,6 +58,24 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
*/
|
*/
|
||||||
private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class);
|
private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an error on the given WebSocket connection and closes the
|
||||||
|
* connection. The error sent is determined from using the information
|
||||||
|
* within the given GuacamoleStatus.
|
||||||
|
*
|
||||||
|
* @param outbound The outbound WebSocket connection to close.
|
||||||
|
* @param guac_status The status to send.
|
||||||
|
* @throws IOException If an error prevents proper closure of the WebSocket
|
||||||
|
* connection.
|
||||||
|
*/
|
||||||
|
public static void sendError(WsOutbound outbound,
|
||||||
|
GuacamoleStatus guac_status) throws IOException {
|
||||||
|
|
||||||
|
byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8");
|
||||||
|
outbound.close(guac_status.getWebSocketCode(), ByteBuffer.wrap(message));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInbound createWebSocketInbound(String protocol, HttpServletRequest request) {
|
public StreamInbound createWebSocketInbound(String protocol, HttpServletRequest request) {
|
||||||
|
|
||||||
@@ -129,27 +147,19 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
outbound.close(Constants.STATUS_SHUTDOWN, null);
|
outbound.close(Constants.STATUS_SHUTDOWN, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch any thrown guacamole exception and attempt
|
// Catch any thrown guacamole exception and attempt
|
||||||
// to pass within the WebSocket connection, logging
|
// to pass within the WebSocket connection, logging
|
||||||
// each error appropriately.
|
// each error appropriately.
|
||||||
catch (GuacamoleSecurityException e) {
|
|
||||||
logger.warn("Authorization failed.", e);
|
|
||||||
outbound.close(Constants.STATUS_POLICY_VIOLATION, null);
|
|
||||||
}
|
|
||||||
catch (GuacamoleResourceNotFoundException e) {
|
|
||||||
logger.debug("Resource not found.", e);
|
|
||||||
outbound.close(Constants.STATUS_PROTOCOL_ERROR, null);
|
|
||||||
}
|
|
||||||
catch (GuacamoleClientException e) {
|
catch (GuacamoleClientException e) {
|
||||||
logger.warn("Error in client request.", e);
|
logger.warn("Client request rejected: {}", e.getMessage());
|
||||||
outbound.close(Constants.STATUS_PROTOCOL_ERROR, null);
|
sendError(outbound, e.getStatus());
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Server error in tunnel", e);
|
logger.error("Internal server error.", e);
|
||||||
outbound.close(Constants.STATUS_UNEXPECTED_CONDITION, null);
|
sendError(outbound, e.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user