Skip to content

Commit

Permalink
GUACAMOLE-524: Leverage thread-local storage to allow overriding the …
Browse files Browse the repository at this point in the history
…deprecated connect() function to have the expected effect within subclasses of SimpleConnection.
  • Loading branch information
mike-jumper committed Jan 22, 2019
1 parent b638387 commit 7e67dde
Showing 1 changed file with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,27 @@ public class SimpleConnection extends AbstractConnection {
private GuacamoleConfiguration fullConfig;

/**
* Creates a completely uninitialized SimpleConnection.
* The tokens which should apply strictly to the next call to
* {@link #connect(org.apache.guacamole.protocol.GuacamoleClientInformation)}.
* This storage is intended as a temporary bridge allowing the old version
* of connect() to be overridden while still resulting in the same behavior
* as older versions of SimpleConnection. <strong>This storage should be
* removed once support for the old, deprecated connect() is removed.</strong>
*/
private final ThreadLocal<Map<String, String>> currentTokens =
new ThreadLocal<Map<String, String>>() {

@Override
protected Map<String, String> initialValue() {
return Collections.emptyMap();
}

};

/**
* Creates a completely uninitialized SimpleConnection. The name,
* identifier, and configuration of this SimpleConnection must eventually
* be set before the SimpleConnection may be used.
*/
public SimpleConnection() {
}
Expand Down Expand Up @@ -117,8 +137,9 @@ public void setAttributes(Map<String, String> attributes) {
}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
@SuppressWarnings("deprecation")
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {

// Retrieve proxy configuration from environment
Environment environment = new LocalEnvironment();
Expand All @@ -130,7 +151,7 @@ public GuacamoleTunnel connect(GuacamoleClientInformation info,

// Apply tokens to config parameters
GuacamoleConfiguration filteredConfig = new GuacamoleConfiguration(getFullConfiguration());
new TokenFilter(tokens).filterValues(filteredConfig.getParameters());
new TokenFilter(currentTokens.get()).filterValues(filteredConfig.getParameters());

GuacamoleSocket socket;

Expand Down Expand Up @@ -160,6 +181,22 @@ public GuacamoleTunnel connect(GuacamoleClientInformation info,
}

return new SimpleGuacamoleTunnel(socket);

}

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {

// Make received tokens available within the legacy connect() strictly
// in context of the current connect() call
try {
currentTokens.set(tokens);
return connect(info);
}
finally {
currentTokens.remove();
}

}

Expand Down

0 comments on commit 7e67dde

Please sign in to comment.