GUACAMOLE-524: Add Custom Attributes to Tokens Added method to add custom map of tokens to StandardTokens.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/165d3d0d Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/165d3d0d Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/165d3d0d Branch: refs/heads/master Commit: 165d3d0d0de0d6cfd2f089138974fd152feb8ca6 Parents: 4c1281d Author: Jared Frees <frees...@osu.edu> Authored: Mon Jun 11 14:59:12 2018 -0400 Committer: Jared Frees <frees...@osu.edu> Committed: Mon Jun 11 14:59:12 2018 -0400 ---------------------------------------------------------------------- .../apache/guacamole/token/StandardTokens.java | 43 +++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/165d3d0d/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java ---------------------------------------------------------------------- diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java b/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java index af8a231..b34b995 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java @@ -25,8 +25,6 @@ import org.apache.guacamole.net.auth.AuthenticatedUser; import org.apache.guacamole.net.auth.Credentials; import java.util.Map; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Utility class which provides access to standardized token names, as well as @@ -79,11 +77,10 @@ public class StandardTokens { private static final String TIME_FORMAT = "HHmmss"; /** - * Standard prefix to append to beginning of the name of each custom - * LDAP attribute before adding attributes as tokens. + * The prefix of the arbitrary attribute tokens. */ - private static final String LDAP_ATTR_PREFIX = "USER_ATTR:"; - + public static final String ATTR_TOKEN_PREFIX = "GUAC_ATTR:"; + /** * This utility class should not be instantiated. */ @@ -144,15 +141,6 @@ public class StandardTokens { if (address != null) filter.setToken(CLIENT_ADDRESS_TOKEN, address); - // Add each custom client LDAP attribute token - Map<String, String> ldapAttrs = credentials.getLDAPAttributes(); - if (ldapAttrs != null) { - for (Map.Entry<String, String> attr : ldapAttrs.entrySet()) { - String tokenName = LDAP_ATTR_PREFIX + attr.getKey().toUpperCase(); - filter.setToken(tokenName, attr.getValue()); - } - } - // Add any tokens which do not require credentials addStandardTokens(filter); @@ -185,4 +173,29 @@ public class StandardTokens { } + /** + * Add attribute tokens to StandardTokens. These are arbitrary + * key/value pairs that may be configured by the various authentication + * extensions. + * + * @param filter + * The TokenFilter to add attributes tokens to. + * + * @param attributes + * The map of key/value pairs to add tokens for. + */ + public static void addAttributeTokens(TokenFilter filter, + Map<String, String> attributes) { + + if (attributes != null) { + for (Map.Entry entry : attributes.entrySet()) { + String key = entry.getKey().toString(); + String tokenName = ATTR_TOKEN_PREFIX + key.toUpperCase(); + String tokenValue = entry.getValue().toString(); + filter.setToken(tokenName, tokenValue); + } + } + + } + }