From 86841ebfe3071ec96b6e6e64ae692f85d346885c Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Wed, 9 Dec 2015 22:22:34 -0800 Subject: [PATCH 1/2] GUAC-1429: Return whole objects instead of identifiers to fix text/plain conversion error. --- .../rest/connection/ConnectionRESTService.java | 13 ++++++------- .../ConnectionGroupRESTService.java | 16 +++++++--------- .../net/basic/rest/user/UserRESTService.java | 9 ++++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java index 258d81962..fad3c4ef4 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connection/ConnectionRESTService.java @@ -249,8 +249,8 @@ public class ConnectionRESTService { } /** - * Creates a new connection and returns the identifier of the new - * connection. + * Creates a new connection and returns the new connection, with identifier + * field populated. * * @param authToken * The authentication token that is used to authenticate the user @@ -264,14 +264,13 @@ public class ConnectionRESTService { * The connection to create. * * @return - * The identifier of the new connection. + * The new connection. * * @throws GuacamoleException * If an error occurs while creating the connection. */ @POST - @Produces(MediaType.TEXT_PLAIN) - public String createConnection(@QueryParam("token") String authToken, + public APIConnection createConnection(@QueryParam("token") String authToken, @PathParam("dataSource") String authProviderIdentifier, APIConnection connection) throws GuacamoleException { @@ -286,8 +285,8 @@ public class ConnectionRESTService { Directory connectionDirectory = userContext.getConnectionDirectory(); connectionDirectory.add(new APIConnectionWrapper(connection)); - // Return the new connection identifier - return connection.getIdentifier(); + // Return the new connection + return connection; } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java index 77bcbdfae..1a1bcadee 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/connectiongroup/ConnectionGroupRESTService.java @@ -190,10 +190,8 @@ public class ConnectionGroupRESTService { } /** - * Creates a new connection group and returns the identifier of the new connection group. - * If a parentID is provided, the connection group will be created in the - * connection group with the parentID. Otherwise, the root connection group - * will be used. + * Creates a new connection group and returns the new connection group, + * with identifier field populated. * * @param authToken * The authentication token that is used to authenticate the user @@ -207,14 +205,14 @@ public class ConnectionGroupRESTService { * The connection group to create. * * @return - * The identifier of the new connection group. + * The new connection group. * * @throws GuacamoleException * If an error occurs while creating the connection group. */ @POST - @Produces(MediaType.TEXT_PLAIN) - public String createConnectionGroup(@QueryParam("token") String authToken, + public APIConnectionGroup createConnectionGroup( + @QueryParam("token") String authToken, @PathParam("dataSource") String authProviderIdentifier, APIConnectionGroup connectionGroup) throws GuacamoleException { @@ -229,8 +227,8 @@ public class ConnectionGroupRESTService { Directory connectionGroupDirectory = userContext.getConnectionGroupDirectory(); connectionGroupDirectory.add(new APIConnectionGroupWrapper(connectionGroup)); - // Return the new connection group identifier - return connectionGroup.getIdentifier(); + // Return the new connection group + return connectionGroup; } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java index 404757b86..0aa92446e 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/user/UserRESTService.java @@ -217,7 +217,7 @@ public class UserRESTService { } /** - * Creates a new user and returns the username. + * Creates a new user and returns the user that was created. * * @param authToken * The authentication token that is used to authenticate the user @@ -234,11 +234,10 @@ public class UserRESTService { * If a problem is encountered while creating the user. * * @return - * The username of the newly created user. + * The newly created user. */ @POST - @Produces(MediaType.TEXT_PLAIN) - public String createUser(@QueryParam("token") String authToken, + public APIUser createUser(@QueryParam("token") String authToken, @PathParam("dataSource") String authProviderIdentifier, APIUser user) throws GuacamoleException { @@ -255,7 +254,7 @@ public class UserRESTService { // Create the user userDirectory.add(new APIUserWrapper(user)); - return user.getUsername(); + return user; } From b0ac9e8d52575aef743197b5bde3079c1490421b Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Wed, 9 Dec 2015 22:59:08 -0800 Subject: [PATCH 2/2] GUAC-1429: Modify Directory API to set identifier on added object, and update javascript to use new models. --- .../base/ModeledDirectoryObjectService.java | 6 +++++- .../ModeledGroupedDirectoryObjectService.java | 3 ++- .../guacamole/net/auth/Directory.java | 21 +++++++++++-------- .../net/auth/simple/SimpleDirectory.java | 4 +++- .../rest/services/connectionGroupService.js | 4 ++-- .../app/rest/services/connectionService.js | 4 ++-- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java index b5cb2822f..034784310 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/base/ModeledDirectoryObjectService.java @@ -32,6 +32,7 @@ import org.glyptodon.guacamole.GuacamoleSecurityException; import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper; import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionModel; import org.glyptodon.guacamole.auth.jdbc.user.UserModel; +import org.glyptodon.guacamole.net.auth.Identifiable; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; @@ -54,7 +55,7 @@ import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; * database. */ public abstract class ModeledDirectoryObjectService, - ExternalType, ModelType extends ObjectModel> + ExternalType extends Identifiable, ModelType extends ObjectModel> implements DirectoryObjectService { /** @@ -384,6 +385,9 @@ public abstract class ModeledDirectoryObjectService, - ExternalType, ModelType extends GroupedObjectModel> + ExternalType extends Identifiable, ModelType extends GroupedObjectModel> extends ModeledDirectoryObjectService { /** diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Directory.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Directory.java index 4dbb60ce9..958a9ad5e 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Directory.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/Directory.java @@ -28,16 +28,15 @@ import org.glyptodon.guacamole.GuacamoleException; /** * Provides access to a collection of all objects with associated identifiers, - * and allows user manipulation and removal. Objects stored within a - * Directory are not necessarily returned to the use as references to - * the stored objects, thus updating an object requires calling an update - * function. + * and allows user manipulation and removal. Objects returned by a Directory + * are not necessarily backed by the stored objects, thus updating an object + * always requires calling the update() function. * * @author Michael Jumper * @param * The type of objects stored within this Directory. */ -public interface Directory { +public interface Directory { /** * Returns the object having the given identifier. Note that changes to @@ -91,12 +90,16 @@ public interface Directory { Set getIdentifiers() throws GuacamoleException; /** - * Adds the given object to the overall set. + * Adds the given object to the overall set. If a new identifier is + * created for the added object, that identifier will be automatically + * assigned via setIdentifier(). * - * @param object The object to add. + * @param object + * The object to add. * - * @throws GuacamoleException If an error occurs while adding the object , or - * if adding the object is not allowed. + * @throws GuacamoleException + * If an error occurs while adding the object, or if adding the object + * is not allowed. */ void add(ObjectType object) throws GuacamoleException; diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java index cf207785e..f688350ba 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleDirectory.java @@ -30,6 +30,7 @@ import java.util.Set; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleSecurityException; import org.glyptodon.guacamole.net.auth.Directory; +import org.glyptodon.guacamole.net.auth.Identifiable; /** * An extremely simple read-only implementation of a Directory which provides @@ -40,7 +41,8 @@ import org.glyptodon.guacamole.net.auth.Directory; * @param * The type of objects stored within this SimpleDirectory. */ -public class SimpleDirectory implements Directory { +public class SimpleDirectory + implements Directory { /** * The Map of objects to provide access to. diff --git a/guacamole/src/main/webapp/app/rest/services/connectionGroupService.js b/guacamole/src/main/webapp/app/rest/services/connectionGroupService.js index 1d48c160d..f157e7590 100644 --- a/guacamole/src/main/webapp/app/rest/services/connectionGroupService.js +++ b/guacamole/src/main/webapp/app/rest/services/connectionGroupService.js @@ -145,8 +145,8 @@ angular.module('rest').factory('connectionGroupService', ['$injector', }) // Set the identifier on the new connection group and clear the cache - .success(function connectionGroupCreated(identifier){ - connectionGroup.identifier = identifier; + .success(function connectionGroupCreated(newConnectionGroup){ + connectionGroup.identifier = newConnectionGroup.identifier; cacheService.connections.removeAll(); }); } diff --git a/guacamole/src/main/webapp/app/rest/services/connectionService.js b/guacamole/src/main/webapp/app/rest/services/connectionService.js index cbf40eb81..aa12639e3 100644 --- a/guacamole/src/main/webapp/app/rest/services/connectionService.js +++ b/guacamole/src/main/webapp/app/rest/services/connectionService.js @@ -152,8 +152,8 @@ angular.module('rest').factory('connectionService', ['$injector', }) // Set the identifier on the new connection and clear the cache - .success(function connectionCreated(identifier){ - connection.identifier = identifier; + .success(function connectionCreated(newConnection){ + connection.identifier = newConnection.identifier; cacheService.connections.removeAll(); }); }