GUACAMOLE-524: Add arbitrary attributes on AuthenticatedUser Add attribute map to AuthenticatedUser along with methods for retrieving and setting map. Also, make AuthenticatedUser implement Attributes.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/64e29b95 Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/64e29b95 Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/64e29b95 Branch: refs/heads/master Commit: 64e29b952bba5231d43c73b51dc5bef0377188e9 Parents: 165d3d0 Author: Jared Frees <[email protected]> Authored: Mon Jun 11 15:05:20 2018 -0400 Committer: Jared Frees <[email protected]> Committed: Mon Jun 11 15:05:20 2018 -0400 ---------------------------------------------------------------------- .../auth/ldap/user/AuthenticatedUser.java | 75 +++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/64e29b95/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/AuthenticatedUser.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/AuthenticatedUser.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/AuthenticatedUser.java index 669efcd..86c4de1 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/AuthenticatedUser.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/AuthenticatedUser.java @@ -20,7 +20,10 @@ package org.apache.guacamole.auth.ldap.user; import com.google.inject.Inject; +import java.util.Map; +import java.util.HashMap; import org.apache.guacamole.net.auth.AbstractAuthenticatedUser; +import org.apache.guacamole.net.auth.Attributes; import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.Credentials; @@ -28,7 +31,8 @@ import org.apache.guacamole.net.auth.Credentials; * An LDAP-specific implementation of AuthenticatedUser, associating a * particular set of credentials with the LDAP authentication provider. */ -public class AuthenticatedUser extends AbstractAuthenticatedUser { +public class AuthenticatedUser extends AbstractAuthenticatedUser + implements Attributes { /** * Reference to the authentication provider associated with this @@ -43,6 +47,11 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser { private Credentials credentials; /** + * Arbitrary attributes associated with this AuthenticatedUser object. + */ + private Map<String, String> attributes = new HashMap<String, String>(); + + /** * Initializes this AuthenticatedUser using the given credentials. * * @param credentials @@ -53,6 +62,70 @@ public class AuthenticatedUser extends AbstractAuthenticatedUser { setIdentifier(credentials.getUsername()); } + /** + * Get a map of attributes associated with this AuthenticatedUser. + * + * @return + * The Map of arbitrary attributes associated with this + * AuthenticatedUser object. + */ + public Map<String, String> getAttributes() { + return attributes; + } + + /** + * Sets a map of attributes associated with this AuthenticatedUser. + * + * @param attributes + * A map of attribute key/value pairs to add to this AuthenticatedUser. + */ + public void setAttributes(Map<String, String> attributes) { + this.attributes = attributes; + } + + /** + * Add the Map of attributes to the current set, without completely + * replacing the existing set. However, if duplicate keys exist the new + * values will replace any existing ones. + * + * @param attributes + * A Map of attributes to add to the existing attributes, without + * completely overwriting them. + */ + public void addAttributes(Map<String, String> attributes) { + this.attributes.putAll(attributes); + } + + /** + * Retrieve a single attribute value from the map of arbitrary attributes + * stored in this AuthenticatedUser object. + * + * @param key + * The key of the attribute to retrieve. + * + * @return + * The value of the attribute with the specified key. + */ + public String getAttribute(String key) { + return attributes.get(key); + } + + /** + * Set the attribute of the given key to the given value, either adding + * a new value if the specified key does not exist, or replacing an existing + * value. + * + * @param key + * The key name of the attribute to set (or overwrite, if it + * already exists). + * + * @param value + * The value of the attribute to set or overwrite. + */ + public void setAttribute(String key, String value) { + attributes.put(key, value); + } + @Override public AuthenticationProvider getAuthenticationProvider() { return authProvider;
