From 75250148b0170f71bcd4090a3dd388d13d1845db Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sun, 12 Mar 2023 20:49:50 -0400 Subject: [PATCH] GUACAMOLE-1479: Implement the disabled methods for User and UserGroup in REST API. --- .../apache/guacamole/rest/user/APIUser.java | 47 +++++++++++++++++-- .../guacamole/rest/user/APIUserWrapper.java | 10 ++++ .../rest/user/UserObjectTranslator.java | 3 ++ .../rest/usergroup/APIUserGroup.java | 27 +++++++++++ .../rest/usergroup/APIUserGroupWrapper.java | 10 ++++ .../usergroup/UserGroupObjectTranslator.java | 3 ++ 6 files changed, 95 insertions(+), 5 deletions(-) diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUser.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUser.java index f018074b6..06f1de159 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUser.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUser.java @@ -43,6 +43,11 @@ public class APIUser { */ private String password; + /** + * Boolean value indicating whether or not this user account is disabled. + */ + private boolean disabled; + /** * Map of all associated attributes by attribute identifier. */ @@ -61,7 +66,9 @@ public class APIUser { /** * Construct a new APIUser from the provided User. - * @param user The User to construct the APIUser from. + * + * @param user + * The User to construct the APIUser from. */ public APIUser(User user) { @@ -69,6 +76,7 @@ public class APIUser { this.username = user.getIdentifier(); this.password = user.getPassword(); this.lastActive = user.getLastActive(); + this.disabled = user.isDisabled(); // Associate any attributes this.attributes = user.getAttributes(); @@ -77,7 +85,9 @@ public class APIUser { /** * Returns the username for this user. - * @return The username for this user. + * + * @return + * The username for this user. */ public String getUsername() { return username; @@ -85,7 +95,9 @@ public class APIUser { /** * Set the username for this user. - * @param username The username for this user. + * + * @param username + * The username for this user. */ public void setUsername(String username) { this.username = username; @@ -93,7 +105,9 @@ public class APIUser { /** * Returns the password for this user. - * @return The password for this user. + * + * @return + * The password for this user. */ public String getPassword() { return password; @@ -101,11 +115,34 @@ public class APIUser { /** * Set the password for this user. - * @param password The password for this user. + * + * @param password + * The password for this user. */ public void setPassword(String password) { this.password = password; } + + /** + * Returns true if this user account is disabled, otherwise false. + * + * @return + * True if this user account is disabled, otherwise false. + */ + public boolean isDisabled() { + return disabled; + } + + /** + * Sets the disabled status of this user account, disabling the account + * if set to true. + * + * @param disabled + * True if this user account should be disabled. + */ + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } /** * Returns a map of all attributes associated with this user. Each entry diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java index b086314f6..f48a9cf46 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java @@ -69,6 +69,16 @@ public class APIUserWrapper implements User { public void setPassword(String password) { apiUser.setPassword(password); } + + @Override + public boolean isDisabled() { + return apiUser.isDisabled(); + } + + @Override + public void setDisabled(boolean disabled) { + apiUser.setDisabled(disabled); + } @Override public Map getAttributes() { diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserObjectTranslator.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserObjectTranslator.java index 8c63d7218..f1a595bf7 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserObjectTranslator.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserObjectTranslator.java @@ -49,6 +49,9 @@ public class UserObjectTranslator // Do not update the user password if no password was provided if (object.getPassword() != null) existingObject.setPassword(object.getPassword()); + + // Update disabled status + existingObject.setDisabled(object.isDisabled()); // Update user attributes existingObject.setAttributes(object.getAttributes()); diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroup.java b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroup.java index df4847bc9..547fb1fca 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroup.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroup.java @@ -36,6 +36,11 @@ public class APIUserGroup { * The identifier of this user group. */ private String identifier; + + /** + * Boolean value indicating if this UserGroup is disabled. + */ + private boolean disabled; /** * Map of all associated attributes by attribute identifier. @@ -55,6 +60,7 @@ public class APIUserGroup { */ public APIUserGroup(UserGroup group) { this.identifier = group.getIdentifier(); + this.disabled = group.isDisabled(); this.attributes = group.getAttributes(); } @@ -79,6 +85,27 @@ public class APIUserGroup { public void setIdentifier(String identifier) { this.identifier = identifier; } + + /** + * Return true if this user group is disabled, otherwise false. + * + * @return + * True if this user group is disabled, otherwise false. + */ + public boolean isDisabled() { + return disabled; + } + + /** + * Sets whether or not this user group is disabled to the parameter + * provided. + * + * @param disabled + * True if the user group should be disabled, otherwise false. + */ + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } /** * Returns a map of all attributes associated with this user group. Each diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroupWrapper.java b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroupWrapper.java index 5dc6d7b0a..c195e87d0 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroupWrapper.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/APIUserGroupWrapper.java @@ -61,6 +61,16 @@ public class APIUserGroupWrapper implements UserGroup { public void setIdentifier(String identifier) { apiUserGroup.setIdentifier(identifier); } + + @Override + public boolean isDisabled() { + return apiUserGroup.isDisabled(); + } + + @Override + public void setDisabled(boolean disabled) { + apiUserGroup.setDisabled(disabled); + } @Override public Map getAttributes() { diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/UserGroupObjectTranslator.java b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/UserGroupObjectTranslator.java index 88000b010..a947b8fd4 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/UserGroupObjectTranslator.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/usergroup/UserGroupObjectTranslator.java @@ -47,6 +47,9 @@ public class UserGroupObjectTranslator public void applyExternalChanges(UserGroup existingObject, APIUserGroup object) throws GuacamoleException { + // Update disabled status + existingObject.setDisabled(object.isDisabled()); + // Update user attributes existingObject.setAttributes(object.getAttributes());