From a34d3facc4c99354d4262101e9c516f36b25c675 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 7 Mar 2017 13:23:13 -0800 Subject: [PATCH] GUACAMOLE-292: Store user profile information within PostgreSQL/MySQL database. --- .../guacamole/auth/jdbc/user/ModeledUser.java | 16 +-- .../guacamole/auth/jdbc/user/UserModel.java | 111 ++++++++++++++++++ .../schema/001-create-schema.sql | 6 + .../schema/upgrade/upgrade-pre-0.9.13.sql | 10 ++ .../guacamole/auth/jdbc/user/UserMapper.xml | 62 +++++++--- .../schema/001-create-schema.sql | 6 + .../schema/upgrade/upgrade-pre-0.9.13.sql | 10 ++ .../guacamole/auth/jdbc/user/UserMapper.xml | 64 +++++++--- 8 files changed, 242 insertions(+), 43 deletions(-) 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 418fe8012..418ffad81 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 @@ -397,16 +397,16 @@ public class ModeledUser extends ModeledDirectoryObject implements Us private void putUnrestrictedAttributes(Map attributes) { // Set full name attribute - attributes.put(User.Attribute.FULL_NAME, "Testy McTesterson"); // TODO + attributes.put(User.Attribute.FULL_NAME, getModel().getFullName()); // Set email address attribute - attributes.put(User.Attribute.EMAIL_ADDRESS, "test@test.test"); // TODO + attributes.put(User.Attribute.EMAIL_ADDRESS, getModel().getEmailAddress()); // Set organization attribute - attributes.put(User.Attribute.ORGANIZATION, "Example, Inc."); // TODO + attributes.put(User.Attribute.ORGANIZATION, getModel().getOrganization()); // Set role attribute - attributes.put(User.Attribute.ORGANIZATIONAL_ROLE, "Senior Lead Architect"); // TODO + attributes.put(User.Attribute.ORGANIZATIONAL_ROLE, getModel().getOrganizationalRole()); } @@ -526,16 +526,16 @@ public class ModeledUser extends ModeledDirectoryObject implements Us private void setUnrestrictedAttributes(Map attributes) { // Translate full name attribute - logger.info("FULL NAME: \"{}\"", attributes.get(User.Attribute.FULL_NAME)); // TODO + getModel().setFullName(attributes.get(User.Attribute.FULL_NAME)); // Translate email address attribute - logger.info("EMAIL ADDRESS: \"{}\"", attributes.get(User.Attribute.EMAIL_ADDRESS)); // TODO + getModel().setEmailAddress(attributes.get(User.Attribute.EMAIL_ADDRESS)); // Translate organization attribute - logger.info("ORGANIZATION: \"{}\"", attributes.get(User.Attribute.ORGANIZATION)); // TODO + getModel().setOrganization(attributes.get(User.Attribute.ORGANIZATION)); // Translate role attribute - logger.info("ORGANIZATIONAL ROLE: \"{}\"", attributes.get(User.Attribute.ORGANIZATIONAL_ROLE)); // TODO + getModel().setOrganizationalRole(attributes.get(User.Attribute.ORGANIZATIONAL_ROLE)); } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserModel.java index 4dfb27596..2376caed9 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserModel.java @@ -92,6 +92,28 @@ public class UserModel extends ObjectModel { */ private String timeZone; + /** + * The user's full name, or null if this is not known. + */ + private String fullName; + + /** + * The email address of the user, or null if this is not known. + */ + private String emailAddress; + + /** + * The organization, company, group, etc. that the user belongs to, or null + * if this is not known. + */ + private String organization; + + /** + * The role that the user has at the organization, company, group, etc. + * they belong to, or null if this is not known. + */ + private String organizationalRole; + /** * Creates a new, empty user. */ @@ -351,4 +373,93 @@ public class UserModel extends ObjectModel { this.timeZone = timeZone; } + /** + * Returns the user's full name, if known. If not available, null is + * returned. + * + * @return + * The user's full name, or null if this is not known. + */ + public String getFullName() { + return fullName; + } + + /** + * Sets the user's full name. + * + * @param fullName + * The user's full name, or null if this is not known. + */ + public void setFullName(String fullName) { + this.fullName = fullName; + } + + /** + * Returns the email address of the user, if known. If not available, null + * is returned. + * + * @return + * The email address of the user, or null if this is not known. + */ + public String getEmailAddress() { + return emailAddress; + } + + /** + * Sets the email address of the user. + * + * @param emailAddress + * The email address of the user, or null if this is not known. + */ + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Returns the organization, company, group, etc. that the user belongs to, + * if known. If not available, null is returned. + * + * @return + * The organization, company, group, etc. that the user belongs to, or + * null if this is not known. + */ + public String getOrganization() { + return organization; + } + + /** + * Sets the organization, company, group, etc. that the user belongs to. + * + * @param organization + * The organization, company, group, etc. that the user belongs to, or + * null if this is not known. + */ + public void setOrganization(String organization) { + this.organization = organization; + } + + /** + * Returns the role that the user has at the organization, company, group, + * etc. they belong to. If not available, null is returned. + * + * @return + * The role that the user has at the organization, company, group, etc. + * they belong to, or null if this is not known. + */ + public String getOrganizationalRole() { + return organizationalRole; + } + + /** + * Sets the role that the user has at the organization, company, group, + * etc. they belong to. + * + * @param organizationalRole + * The role that the user has at the organization, company, group, etc. + * they belong to, or null if this is not known. + */ + public void setOrganizationalRole(String organizationalRole) { + this.organizationalRole = organizationalRole; + } + } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql index 37a825917..29bc47a7e 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql @@ -102,6 +102,12 @@ CREATE TABLE `guacamole_user` ( -- Timezone used for all date/time comparisons and interpretation `timezone` VARCHAR(64), + -- Profile information + `full_name` VARCHAR(256), + `email_address` VARCHAR(256), + `organization` VARCHAR(256), + `organizational_role` VARCHAR(256), + PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.13.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.13.sql index bb37c6c31..95bbc1c05 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.13.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.13.sql @@ -28,3 +28,13 @@ ALTER TABLE guacamole_connection ADD COLUMN proxy_encryption_method ENUM( 'NONE', 'SSL' ); + +-- +-- Add new user profile columns +-- + +ALTER TABLE guacamole_user ADD COLUMN full_name VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN email_address VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN organization VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN organizational_role VARCHAR(256); + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml index 3530b0b51..0ddb0517a 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml @@ -25,17 +25,21 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -69,7 +73,11 @@ access_window_end, valid_from, valid_until, - timezone + timezone, + full_name, + email_address, + organization, + organizational_role FROM guacamole_user WHERE username IN @@ -180,7 +204,11 @@ access_window_end = #{object.accessWindowEnd,jdbcType=TIME}, valid_from = #{object.validFrom,jdbcType=DATE}, valid_until = #{object.validUntil,jdbcType=DATE}, - timezone = #{object.timeZone,jdbcType=VARCHAR} + timezone = #{object.timeZone,jdbcType=VARCHAR}, + full_name = #{object.fullName,jdbcType=VARCHAR}, + email_address = #{object.emailAddress,jdbcType=VARCHAR}, + organization = #{object.organization,jdbcType=VARCHAR}, + organizational_role = #{object.organizationalRole,jdbcType=VARCHAR} WHERE user_id = #{object.objectID,jdbcType=VARCHAR} diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql index 199b4bdc2..f9b235108 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql @@ -143,6 +143,12 @@ CREATE TABLE guacamole_user ( -- Timezone used for all date/time comparisons and interpretation timezone varchar(64), + -- Profile information + full_name varchar(256), + email_address varchar(256), + organization varchar(256), + organizational_role varchar(256), + PRIMARY KEY (user_id), CONSTRAINT username diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.13.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.13.sql index 015ec9a6c..0fac52846 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.13.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.13.sql @@ -33,3 +33,13 @@ CREATE TYPE guacamole_proxy_encryption_method AS ENUM( ALTER TABLE guacamole_connection ADD COLUMN proxy_port integer; ALTER TABLE guacamole_connection ADD COLUMN proxy_hostname varchar(512); ALTER TABLE guacamole_connection ADD COLUMN proxy_encryption_method guacamole_proxy_encryption_method; + +-- +-- Add new user profile columns +-- + +ALTER TABLE guacamole_user ADD COLUMN full_name VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN email_address VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN organization VARCHAR(256); +ALTER TABLE guacamole_user ADD COLUMN organizational_role VARCHAR(256); + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml index 39ec05a01..569a8ac45 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml @@ -25,18 +25,22 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -70,7 +74,11 @@ access_window_end, valid_from, valid_until, - timezone + timezone, + full_name, + email_address, + organization, + organizational_role FROM guacamole_user WHERE username IN @@ -181,7 +205,11 @@ access_window_end = #{object.accessWindowEnd,jdbcType=TIME}, valid_from = #{object.validFrom,jdbcType=DATE}, valid_until = #{object.validUntil,jdbcType=DATE}, - timezone = #{object.timeZone,jdbcType=VARCHAR} + timezone = #{object.timeZone,jdbcType=VARCHAR}, + full_name = #{object.fullName,jdbcType=VARCHAR}, + email_address = #{object.emailAddress,jdbcType=VARCHAR}, + organization = #{object.organization,jdbcType=VARCHAR}, + organizational_role = #{object.organizationalRole,jdbcType=VARCHAR} WHERE user_id = #{object.objectID,jdbcType=VARCHAR}