From 3abecff0d11e4489cd703cf93a3118dea3a77611 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sat, 25 Dec 2021 21:18:32 -0500 Subject: [PATCH] GUACAMOLE-1293: Add common support for the name handshake instruction. --- .../protocol/ConfiguredGuacamoleSocket.java | 9 +++++- .../protocol/GuacamoleClientInformation.java | 32 +++++++++++++++++-- .../protocol/GuacamoleProtocolCapability.java | 8 +++++ .../protocol/GuacamoleProtocolVersion.java | 4 ++- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java index 1b34ef84a..ee1e26aef 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/ConfiguredGuacamoleSocket.java @@ -293,7 +293,14 @@ public class ConfiguredGuacamoleSocket extends DelegatingGuacamoleSocket { if (GuacamoleProtocolCapability.TIMEZONE_HANDSHAKE.isSupported(protocolVersion)) { String timezone = info.getTimezone(); if (timezone != null) - writer.writeInstruction(new GuacamoleInstruction("timezone", info.getTimezone())); + writer.writeInstruction(new GuacamoleInstruction("timezone", timezone)); + } + + // Send client name, if supported and available + if (GuacamoleProtocolCapability.NAME_HANDSHAKE.isSupported(protocolVersion)) { + String name = info.getName(); + if (name != null) + writer.writeInstruction(new GuacamoleInstruction("name", name)); } // Send args diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleClientInformation.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleClientInformation.java index 6d54a2f6c..b295db887 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleClientInformation.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleClientInformation.java @@ -47,17 +47,22 @@ public class GuacamoleClientInformation { /** * The list of audio mimetypes reported by the client to be supported. */ - private final List audioMimetypes = new ArrayList(); + private final List audioMimetypes = new ArrayList<>(); /** * The list of video mimetypes reported by the client to be supported. */ - private final List videoMimetypes = new ArrayList(); + private final List videoMimetypes = new ArrayList<>(); /** * The list of image mimetypes reported by the client to be supported. */ - private final List imageMimetypes = new ArrayList(); + private final List imageMimetypes = new ArrayList<>(); + + /** + * The name of the user reported by the client. + */ + private String name; /** * The timezone reported by the client. @@ -150,6 +155,17 @@ public class GuacamoleClientInformation { return imageMimetypes; } + /** + * Returns the name of the Guacamole user as reported by the client, or null + * if the user name is not set. + * + * @return + * A string value of the human-readable name reported by the client. + */ + public String getName() { + return name; + } + /** * Return the timezone as reported by the client, or null if the timezone * is not set. Valid timezones are specified in IANA zone key format, @@ -162,6 +178,16 @@ public class GuacamoleClientInformation { return timezone; } + /** + * Set the human-readable name of the user associated with this client. + * + * @param name + * The human-readable name of the user associated with this client. + */ + public void setName(String name) { + this.name = name; + } + /** * Set the string value of the timezone, or null if the timezone will not * be provided by the client. Valid timezones are specified in IANA zone diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolCapability.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolCapability.java index 354bfc85d..edfc26356 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolCapability.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolCapability.java @@ -40,6 +40,14 @@ public enum GuacamoleProtocolCapability { */ MSG_INSTRUCTION(GuacamoleProtocolVersion.VERSION_1_5_0), + /** + * Support for the "name" handshake instruction, allowing clients to send + * the name of the Guacamole user to be passed to guacd and associated with + * connections. Support for this insruction was introduced in + * {@link GuacamoleProtocolVersion#VERSION_1_5_0}. + */ + NAME_HANDSHAKE(GuacamoleProtocolVersion.VERSION_1_5_0), + /** * Negotiation of Guacamole protocol version between client and server * during the protocol handshake. The ability to negotiate protocol diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolVersion.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolVersion.java index 054334f65..a8e443102 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolVersion.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleProtocolVersion.java @@ -56,7 +56,9 @@ public class GuacamoleProtocolVersion { /** * Protocol version 1.5.0, which introduces the "msg" instruction, allowing * the server to send message notifications that will be displayed on the - * client. + * client. The version also adds support for the "name" handshake + * instruction, allowing guacd to store the name of the user who is + * accessing the connection. */ public static final GuacamoleProtocolVersion VERSION_1_5_0 = new GuacamoleProtocolVersion(1, 5, 0);