GUAC-1101: Add parameters upon insertion of new connection.

This commit is contained in:
Michael Jumper
2015-02-26 23:32:27 -08:00
parent 9dffabfd23
commit 9159df5ee4
2 changed files with 53 additions and 14 deletions

View File

@@ -163,16 +163,22 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
} }
@Override /**
public void updateObject(AuthenticatedUser user, MySQLConnection object) * Given an arbitrary Guacamole connection, produces a collection of
throws GuacamoleException { * parameter model objects containing the name/value pairs of that
* connection's parameters.
*
* @param connection
* The connection whose configuration should be used to produce the
* collection of parameter models.
*
* @return
* A collection of parameter models containing the name/value pairs
* of the given connection's parameters.
*/
private Collection<ParameterModel> getParameterModels(MySQLConnection connection) {
// Update connection Map<String, String> parameters = connection.getConfiguration().getParameters();
super.updateObject(user, object);
// Get identifier and connection parameters
String identifier = object.getIdentifier();
Map<String, String> parameters = object.getConfiguration().getParameters();
// Convert parameters to model objects // Convert parameters to model objects
Collection<ParameterModel> parameterModels = new ArrayList(parameters.size()); Collection<ParameterModel> parameterModels = new ArrayList(parameters.size());
@@ -188,7 +194,7 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
// Produce model object from parameter // Produce model object from parameter
ParameterModel model = new ParameterModel(); ParameterModel model = new ParameterModel();
model.setConnectionIdentifier(identifier); model.setConnectionIdentifier(connection.getIdentifier());
model.setName(name); model.setName(name);
model.setValue(value); model.setValue(value);
@@ -197,8 +203,37 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
} }
return parameterModels;
}
@Override
public MySQLConnection createObject(AuthenticatedUser user, Connection object)
throws GuacamoleException {
// Create connection
MySQLConnection connection = super.createObject(user, object);
connection.setConfiguration(object.getConfiguration());
// Insert new parameters, if any
Collection<ParameterModel> parameterModels = getParameterModels(connection);
if (!parameterModels.isEmpty())
parameterMapper.insert(parameterModels);
return connection;
}
@Override
public void updateObject(AuthenticatedUser user, MySQLConnection object)
throws GuacamoleException {
// Update connection
super.updateObject(user, object);
// Replace existing parameters with new parameters // Replace existing parameters with new parameters
parameterMapper.delete(identifier); Collection<ParameterModel> parameterModels = getParameterModels(object);
parameterMapper.delete(object.getIdentifier());
parameterMapper.insert(parameterModels); parameterMapper.insert(parameterModels);
} }

View File

@@ -327,11 +327,14 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
* @param object * @param object
* The object to create. * The object to create.
* *
* @return
* The newly-created object.
*
* @throws GuacamoleException * @throws GuacamoleException
* If the user lacks permission to create the object, or an error * If the user lacks permission to create the object, or an error
* occurs while creating the object. * occurs while creating the object.
*/ */
public void createObject(AuthenticatedUser user, ExternalType object) public InternalType createObject(AuthenticatedUser user, ExternalType object)
throws GuacamoleException { throws GuacamoleException {
// Only create object if user has permission to do so // Only create object if user has permission to do so
@@ -341,10 +344,11 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
validateNewObject(user, object); validateNewObject(user, object);
// Create object // Create object
getObjectMapper().insert(getModelInstance(user, object)); ModelType model = getModelInstance(user, object);
getObjectMapper().insert(model);
// FIXME: Insert implicit object permissions, too. // FIXME: Insert implicit object permissions, too.
return; return getObjectInstance(user, model);
} }
// User lacks permission to create // User lacks permission to create