GUACAMOLE-221: Expose underlying protocol of a GuacamoleSocket via getProtocol().

This commit is contained in:
Michael Jumper committed 2020-11-25 15:24:31 -08:00
1 parent a71de2f155
commit 7fc94e236b
6 files changed
+141 -74

No files matched your search

@@ -24,6 +24,7 @@ import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.io.GuacamoleReader;
import org.apache.guacamole.io.GuacamoleWriter;
import org.apache.guacamole.net.DelegatingGuacamoleSocket;
import org.apache.guacamole.net.GuacamoleSocket;
/**
@@ -36,12 +37,7 @@ import org.apache.guacamole.net.GuacamoleSocket;
* this GuacamoleSocket from manually controlling the initial protocol
* handshake.
*/
public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
/**
* The wrapped socket.
*/
private GuacamoleSocket socket;
public class ConfiguredGuacamoleSocket extends DelegatingGuacamoleSocket {
/**
* The configuration to use when performing the Guacamole protocol
@@ -125,7 +121,7 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
GuacamoleConfiguration config,
GuacamoleClientInformation info) throws GuacamoleException {
this.socket = socket;
super(socket);
this.config = config;
// Get reader and writer
@@ -268,23 +264,8 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
}
@Override
public GuacamoleWriter getWriter() {
return socket.getWriter();
}
@Override
public GuacamoleReader getReader() {
return socket.getReader();
}
@Override
public void close() throws GuacamoleException {
socket.close();
}
@Override
public boolean isOpen() {
return socket.isOpen();
public String getProtocol() {
return getConfiguration().getProtocol();
}
}
@@ -28,7 +28,7 @@ import org.apache.guacamole.GuacamoleUpstreamNotFoundException;
import org.apache.guacamole.GuacamoleUpstreamTimeoutException;
import org.apache.guacamole.GuacamoleUpstreamUnavailableException;
import org.apache.guacamole.io.GuacamoleReader;
import org.apache.guacamole.io.GuacamoleWriter;
import org.apache.guacamole.net.DelegatingGuacamoleSocket;
import org.apache.guacamole.net.GuacamoleSocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
* constructor, allowing a different socket to be substituted prior to
* fulfilling the connection.
*/
public class FailoverGuacamoleSocket implements GuacamoleSocket {
public class FailoverGuacamoleSocket extends DelegatingGuacamoleSocket {
/**
* Logger for this class.
@@ -54,11 +54,6 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
*/
private static final int DEFAULT_INSTRUCTION_QUEUE_LIMIT = 131072;
/**
* The wrapped socket being used.
*/
private final GuacamoleSocket socket;
/**
* Queue of all instructions read while this FailoverGuacamoleSocket was
* being constructed.
@@ -158,6 +153,8 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
final int instructionQueueLimit)
throws GuacamoleException, GuacamoleUpstreamException {
super(socket);
int totalQueueSize = 0;
GuacamoleInstruction instruction;
@@ -189,8 +186,6 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
}
this.socket = socket;
}
/**
@@ -230,7 +225,7 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
@Override
public boolean available() throws GuacamoleException {
return !instructionQueue.isEmpty() || socket.getReader().available();
return !instructionQueue.isEmpty() || getDelegateSocket().getReader().available();
}
@Override
@@ -244,7 +239,7 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
return instruction.toString().toCharArray();
}
return socket.getReader().read();
return getDelegateSocket().getReader().read();
}
@@ -258,7 +253,7 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
if (!instructionQueue.isEmpty())
return instructionQueue.remove();
return socket.getReader().readInstruction();
return getDelegateSocket().getReader().readInstruction();
}
@@ -269,19 +264,4 @@ public class FailoverGuacamoleSocket implements GuacamoleSocket {
return queuedReader;
}
@Override
public GuacamoleWriter getWriter() {
return socket.getWriter();
}
@Override
public void close() throws GuacamoleException {
socket.close();
}
@Override
public boolean isOpen() {
return socket.isOpen();
}
}
@@ -19,21 +19,16 @@
package org.apache.guacamole.protocol;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.io.GuacamoleReader;
import org.apache.guacamole.io.GuacamoleWriter;
import org.apache.guacamole.net.DelegatingGuacamoleSocket;
import org.apache.guacamole.net.GuacamoleSocket;
/**
* Implementation of GuacamoleSocket which allows individual instructions to be
* intercepted, overridden, etc.
*/
public class FilteredGuacamoleSocket implements GuacamoleSocket {
/**
* Wrapped GuacamoleSocket.
*/
private final GuacamoleSocket socket;
public class FilteredGuacamoleSocket extends DelegatingGuacamoleSocket {
/**
* A reader for the wrapped GuacamoleSocket which may be filtered.
@@ -58,7 +53,8 @@ public class FilteredGuacamoleSocket implements GuacamoleSocket {
* instructions, if any.
*/
public FilteredGuacamoleSocket(GuacamoleSocket socket, GuacamoleFilter readFilter, GuacamoleFilter writeFilter) {
this.socket = socket;
super(socket);
// Apply filter to reader
if (readFilter != null)
@@ -84,14 +80,4 @@ public class FilteredGuacamoleSocket implements GuacamoleSocket {
return writer;
}
@Override
public void close() throws GuacamoleException {
socket.close();
}
@Override
public boolean isOpen() {
return socket.isOpen();
}
}
@@ -92,8 +92,7 @@ public class GuacamoleConfiguration implements Serializable {
/**
* Sets the ID of the connection being joined, if any. If no connection
* is being joined, this value must be omitted, and the protocol must be
* set instead.
* is being joined, this value must be omitted.
*
* @param connectionID The ID of the connection being joined.
*/
@@ -103,15 +102,34 @@ public class GuacamoleConfiguration implements Serializable {
/**
* Returns the name of the protocol to be used.
* @return The name of the protocol to be used.
*
* @return
* The name of the protocol to be used.
*/
public String getProtocol() {
return protocol;
}
/**
* Sets the name of the protocol to be used.
* @param protocol The name of the protocol to be used.
* Sets the name of the protocol to be used. If no connection is being
* joined (a new connection is being established), this value must be set.
*
* <p>If a connection is being joined, <strong>this value should still be
* set</strong> to ensure that protocol-specific responses like the
* "required" and "argv" instructions can be understood in their proper
* context by other code that may consume this GuacamoleConfiguration like
* {@link ConfiguredGuacamoleSocket}.
*
* <p>If this value is unavailable or remains unset, it is still possible
* to join an established connection using
* {@link #setConnectionID(java.lang.String)}, however protocol-specific
* responses like the "required" and "argv" instructions might not be
* possible to handle correctly if the underlying protocol is not made
* available through some other means to the client receiving those
* responses.
*
* @param protocol
* The name of the protocol to be used.
*/
public void setProtocol(String protocol) {
this.protocol = protocol;