From 333a8c411f90f847f50111939089f3d10610ed89 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 16 Oct 2018 13:21:57 -0700 Subject: [PATCH 1/2] GUACAMOLE-524: Provide convenience constructor for TokenFilter which initializes the filter with provided tokens. --- .../apache/guacamole/token/TokenFilter.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/token/TokenFilter.java b/guacamole-ext/src/main/java/org/apache/guacamole/token/TokenFilter.java index ab4362227..c412d184a 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/token/TokenFilter.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/token/TokenFilter.java @@ -19,6 +19,7 @@ package org.apache.guacamole.token; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -68,7 +69,27 @@ public class TokenFilter { /** * The values of all known tokens. */ - private final Map tokenValues = new HashMap(); + private final Map tokenValues; + + /** + * Creates a new TokenFilter which has no associated tokens. Tokens must + * later be given using {@link #setToken(java.lang.String, java.lang.String)} + * or {@link #setTokens(java.util.Map)}. + */ + public TokenFilter() { + this(Collections.emptyMap()); + } + + /** + * Creates a new TokenFilter which is initialized with the given token + * name/value pairs. + * + * @param tokenValues + * A map containing token names and their corresponding values. + */ + public TokenFilter(Map tokenValues) { + this.tokenValues = new HashMap<>(tokenValues); + } /** * Sets the token having the given name to the given value. Any existing From 143c10b6efb42a6bccd95714795d0c6ab0a06be1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 16 Oct 2018 13:23:55 -0700 Subject: [PATCH 2/2] GUACAMOLE-524: Correct handling of tokens within SimpleConnection. The copy of the configuration should be filtered, not the original, and token values need to actually be set. --- .../org/apache/guacamole/net/auth/simple/SimpleConnection.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java index f9da240c4..2dec26a94 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java @@ -113,8 +113,7 @@ public class SimpleConnection extends AbstractConnection { // Apply tokens to config parameters GuacamoleConfiguration filteredConfig = new GuacamoleConfiguration(config); - TokenFilter tokenFilter = new TokenFilter(); - tokenFilter.filterValues(config.getParameters()); + new TokenFilter(tokens).filterValues(filteredConfig.getParameters()); GuacamoleSocket socket;