diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java index c2b16eff4..052849520 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java @@ -176,6 +176,34 @@ public class ModeledUser extends ModeledDirectoryObject implements Us @Inject private UserPermissionService userPermissionService; + /** + * Whether attributes which control access restrictions should be exposed + * via getAttributes() or allowed to be set via setAttributes(). + */ + private boolean exposeRestrictedAttributes = false; + + /** + * Initializes this ModeledUser, associating it with the current + * authenticated user and populating it with data from the given user + * model. + * + * @param currentUser + * The user that created or retrieved this object. + * + * @param model + * The backing model object. + * + * @param exposeRestrictedAttributes + * Whether attributes which control access restrictions should be + * exposed via getAttributes() or allowed to be set via + * setAttributes(). + */ + public void init(ModeledAuthenticatedUser currentUser, UserModel model, + boolean exposeRestrictedAttributes) { + super.init(currentUser, model); + this.exposeRestrictedAttributes = exposeRestrictedAttributes; + } + /** * The plaintext password previously set by a call to setPassword(), if * any. The password of a user cannot be retrieved once saved into the @@ -309,10 +337,16 @@ public class ModeledUser extends ModeledDirectoryObject implements Us return userPermissionService.getPermissionSet(getCurrentUser(), this); } - @Override - public Map getAttributes() { - - Map attributes = new HashMap(); + /** + * Stores all restricted (privileged) attributes within the given Map, + * pulling the values of those attributes from the underlying user model. + * If no value is yet defined for an attribute, that attribute will be set + * to null. + * + * @param attributes + * The Map to store all restricted attributes within. + */ + private void putRestrictedAttributes(Map attributes) { // Set disabled attribute attributes.put(DISABLED_ATTRIBUTE_NAME, getModel().isDisabled() ? "true" : null); @@ -335,7 +369,6 @@ public class ModeledUser extends ModeledDirectoryObject implements Us // Set timezone attribute attributes.put(TIMEZONE_ATTRIBUTE_NAME, getModel().getTimeZone()); - return attributes; } /** @@ -396,8 +429,14 @@ public class ModeledUser extends ModeledDirectoryObject implements Us } - @Override - public void setAttributes(Map attributes) { + /** + * Stores all restricted (privileged) attributes within the underlying user + * model, pulling the values of those attributes from the given Map. + * + * @param attributes + * The Map to pull all restricted attributes from. + */ + private void setRestrictedAttributes(Map attributes) { // Translate disabled attribute getModel().setDisabled("true".equals(attributes.get(DISABLED_ATTRIBUTE_NAME))); @@ -438,6 +477,27 @@ public class ModeledUser extends ModeledDirectoryObject implements Us } + @Override + public Map getAttributes() { + + Map attributes = new HashMap(); + + // Include restricted attributes only if they should be exposed + if (exposeRestrictedAttributes) + putRestrictedAttributes(attributes); + + return attributes; + } + + @Override + public void setAttributes(Map attributes) { + + // Assign restricted attributes only if they are exposed + if (exposeRestrictedAttributes) + setRestrictedAttributes(attributes); + + } + /** * Returns the time zone associated with this user. This time zone must be * used when interpreting all date/time restrictions related to this user. diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java index 76a05f857..7935f864d 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java @@ -147,15 +147,35 @@ public class UserService extends ModeledDirectoryObjectService