GUACAMOLE-524: Add Custom Attributes to Tokens

Added method to add custom map of tokens to StandardTokens.
This commit is contained in:
Jared Frees
2018-06-11 14:59:12 -04:00
parent 4c1281d8c2
commit 165d3d0d0d

View File

@@ -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,10 +77,9 @@ 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);
}
}
}
}