mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-641: Allow tokens to be easily injected on-demand.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.apache.guacamole.net.auth;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
@@ -37,6 +38,22 @@ public class TokenInjectingConnection extends DelegatingConnection {
|
||||
*/
|
||||
private final Map<String, String> tokens;
|
||||
|
||||
/**
|
||||
* Returns the tokens which should be added to an in-progress call to
|
||||
* connect(). If not overridden, this function will return the tokens
|
||||
* provided when this instance of TokenInjectingConnection was created.
|
||||
*
|
||||
* @return
|
||||
* The tokens which should be added to the in-progress call to
|
||||
* connect().
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the applicable tokens cannot be generated.
|
||||
*/
|
||||
protected Map<String, String> getTokens() throws GuacamoleException {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given Connection, automatically adding the given tokens to
|
||||
* each invocation of connect(). Any additional tokens which have the same
|
||||
@@ -54,13 +71,26 @@ public class TokenInjectingConnection extends DelegatingConnection {
|
||||
this.tokens = tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given Connection such that the additional parameter tokens
|
||||
* returned by getTokens() are included with each invocation of connect().
|
||||
* Any additional tokens which have the same name as existing tokens will
|
||||
* override the existing values.
|
||||
*
|
||||
* @param connection
|
||||
* The Connection to wrap.
|
||||
*/
|
||||
public TokenInjectingConnection(Connection connection) {
|
||||
this(connection, Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleTunnel connect(GuacamoleClientInformation info,
|
||||
Map<String, String> tokens) throws GuacamoleException {
|
||||
|
||||
// Apply provided tokens over those given to connect()
|
||||
tokens = new HashMap<>(tokens);
|
||||
tokens.putAll(this.tokens);
|
||||
tokens.putAll(getTokens());
|
||||
|
||||
return super.connect(info, tokens);
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.apache.guacamole.net.auth;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
@@ -37,6 +38,23 @@ public class TokenInjectingConnectionGroup extends DelegatingConnectionGroup {
|
||||
*/
|
||||
private final Map<String, String> tokens;
|
||||
|
||||
/**
|
||||
* Returns the tokens which should be added to an in-progress call to
|
||||
* connect(). If not overridden, this function will return the tokens
|
||||
* provided when this instance of TokenInjectingConnectionGroup was
|
||||
* created.
|
||||
*
|
||||
* @return
|
||||
* The tokens which should be added to the in-progress call to
|
||||
* connect().
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If the applicable tokens cannot be generated.
|
||||
*/
|
||||
protected Map<String, String> getTokens() throws GuacamoleException {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given ConnectionGroup, automatically adding the given tokens
|
||||
* to each invocation of connect(). Any additional tokens which have the
|
||||
@@ -54,13 +72,26 @@ public class TokenInjectingConnectionGroup extends DelegatingConnectionGroup {
|
||||
this.tokens = tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given ConnectionGroup such that the additional parameter
|
||||
* tokens returned by getTokens() are included with each invocation of
|
||||
* connect(). Any additional tokens which have the same name as existing
|
||||
* tokens will override the existing values.
|
||||
*
|
||||
* @param connectionGroup
|
||||
* The ConnectionGroup to wrap.
|
||||
*/
|
||||
public TokenInjectingConnectionGroup(ConnectionGroup connectionGroup) {
|
||||
this(connectionGroup, Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuacamoleTunnel connect(GuacamoleClientInformation info,
|
||||
Map<String, String> tokens) throws GuacamoleException {
|
||||
|
||||
// Apply provided tokens over those given to connect()
|
||||
tokens = new HashMap<>(tokens);
|
||||
tokens.putAll(this.tokens);
|
||||
tokens.putAll(getTokens());
|
||||
|
||||
return super.connect(info, tokens);
|
||||
|
||||
|
@@ -122,7 +122,14 @@ public class TokenInjectingUserContext extends DelegatingUserContext {
|
||||
|
||||
@Override
|
||||
protected ConnectionGroup decorate(ConnectionGroup object) throws GuacamoleException {
|
||||
return new TokenInjectingConnectionGroup(object, getTokens(object));
|
||||
return new TokenInjectingConnectionGroup(object) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getTokens() throws GuacamoleException {
|
||||
return TokenInjectingUserContext.this.getTokens(object);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +147,14 @@ public class TokenInjectingUserContext extends DelegatingUserContext {
|
||||
|
||||
@Override
|
||||
protected Connection decorate(Connection object) throws GuacamoleException {
|
||||
return new TokenInjectingConnection(object, getTokens(object));
|
||||
return new TokenInjectingConnection(object) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getTokens() throws GuacamoleException {
|
||||
return TokenInjectingUserContext.this.getTokens(object);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user