GUACAMOLE-524: Ensure all guacamole-ext classes implementing connect() use the old connect() as their basis. Overriding the old connect() will not have the expected effect otherwise.

This commit is contained in:
Michael Jumper
2019-01-22 15:49:16 -08:00
parent feecb6301f
commit bcbac1fb57
3 changed files with 85 additions and 5 deletions

View File

@@ -19,6 +19,7 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -39,6 +40,24 @@ public class DelegatingConnection implements Connection {
*/ */
private final Connection connection; private final Connection connection;
/**
* 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 DelegatingConnection. <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();
}
};
/** /**
* Wraps the given Connection such that all function calls against this * Wraps the given Connection such that all function calls against this
* DelegatingConnection will be delegated to it. * DelegatingConnection will be delegated to it.
@@ -127,10 +146,27 @@ public class DelegatingConnection implements Connection {
return connection.getSharingProfileIdentifiers(); return connection.getSharingProfileIdentifiers();
} }
@Override
@Deprecated
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
return connection.connect(info, currentTokens.get());
}
@Override @Override
public GuacamoleTunnel connect(GuacamoleClientInformation info, public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException { Map<String, String> tokens) throws GuacamoleException {
return connection.connect(info, tokens);
// 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();
}
} }
@Override @Override

View File

@@ -19,6 +19,7 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
@@ -36,6 +37,25 @@ public class DelegatingConnectionGroup implements ConnectionGroup {
*/ */
private final ConnectionGroup connectionGroup; private final ConnectionGroup connectionGroup;
/**
* 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 DelegatingConnectionGroup. <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();
}
};
/** /**
* Wraps the given ConnectionGroup such that all function calls against this * Wraps the given ConnectionGroup such that all function calls against this
* DelegatingConnectionGroup will be delegated to it. * DelegatingConnectionGroup will be delegated to it.
@@ -118,10 +138,27 @@ public class DelegatingConnectionGroup implements ConnectionGroup {
connectionGroup.setAttributes(attributes); connectionGroup.setAttributes(attributes);
} }
@Override
@Deprecated
public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
return connectionGroup.connect(info, currentTokens.get());
}
@Override @Override
public GuacamoleTunnel connect(GuacamoleClientInformation info, public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException { Map<String, String> tokens) throws GuacamoleException {
return connectionGroup.connect(info, tokens);
// 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();
}
} }
@Override @Override

View File

@@ -47,7 +47,7 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup {
* The identifiers of all connection groups in this group. * The identifiers of all connection groups in this group.
*/ */
private final Set<String> connectionGroupIdentifiers; private final Set<String> connectionGroupIdentifiers;
/** /**
* Creates a new SimpleConnectionGroup having the given name and identifier * Creates a new SimpleConnectionGroup having the given name and identifier
* which will expose the given contents. * which will expose the given contents.
@@ -109,9 +109,16 @@ public class SimpleConnectionGroup extends AbstractConnectionGroup {
} }
@Override @Override
public GuacamoleTunnel connect(GuacamoleClientInformation info, @Deprecated
Map<String, String> tokens) throws GuacamoleException { public GuacamoleTunnel connect(GuacamoleClientInformation info)
throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }
@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,
Map<String, String> tokens) throws GuacamoleException {
return connect(info);
}
} }