Add arbitrary attributes on AuthenticatedUser
Add attribute map to AuthenticatedUser along with methods for
retrieving and setting map. Also, make AuthenticatedUser
implement Attributes.
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
@@ -42,6 +46,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.
*
@@ -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;
