mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-1101: Implement connection parameter update.
This commit is contained in:
@@ -48,4 +48,29 @@ public interface ParameterMapper {
|
|||||||
*/
|
*/
|
||||||
Collection<ParameterModel> select(@Param("identifier") String identifier);
|
Collection<ParameterModel> select(@Param("identifier") String identifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts each of the parameter model objects in the given collection as
|
||||||
|
* new connection parameters.
|
||||||
|
*
|
||||||
|
* @param parameters
|
||||||
|
* The connection parameters to insert.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The number of rows inserted.
|
||||||
|
*/
|
||||||
|
int insert(@Param("parameters") Collection<ParameterModel> parameters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all parameters associated with the connection having the given
|
||||||
|
* identifier.
|
||||||
|
*
|
||||||
|
* @param identifier
|
||||||
|
* The identifier of the connection whose parameters should be
|
||||||
|
* deleted.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The number of rows deleted.
|
||||||
|
*/
|
||||||
|
int delete(@Param("identifier") String identifier);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,8 @@ package net.sourceforge.guacamole.net.auth.mysql.service;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -151,6 +153,46 @@ public class ConnectionService extends DirectoryObjectService<MySQLConnection, C
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateObject(AuthenticatedUser user, MySQLConnection object)
|
||||||
|
throws GuacamoleException {
|
||||||
|
|
||||||
|
// Update connection
|
||||||
|
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
|
||||||
|
Collection<ParameterModel> parameterModels = new ArrayList(parameters.size());
|
||||||
|
for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
|
||||||
|
|
||||||
|
// Get parameter name and value
|
||||||
|
String name = parameterEntry.getKey();
|
||||||
|
String value = parameterEntry.getValue();
|
||||||
|
|
||||||
|
// There is no need to insert empty parameters
|
||||||
|
if (value.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Produce model object from parameter
|
||||||
|
ParameterModel model = new ParameterModel();
|
||||||
|
model.setConnectionIdentifier(identifier);
|
||||||
|
model.setName(name);
|
||||||
|
model.setValue(value);
|
||||||
|
|
||||||
|
// Add model to list
|
||||||
|
parameterModels.add(model);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace existing parameters with new parameters
|
||||||
|
parameterMapper.delete(identifier);
|
||||||
|
parameterMapper.insert(parameterModels);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the set of all identifiers for all connections within the root
|
* Returns the set of all identifiers for all connections within the root
|
||||||
* connection group that the user has read access to.
|
* connection group that the user has read access to.
|
||||||
|
@@ -44,4 +44,28 @@
|
|||||||
connection_id = #{identifier,jdbcType=VARCHAR}
|
connection_id = #{identifier,jdbcType=VARCHAR}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Delete all parameters of a given connection -->
|
||||||
|
<delete id="delete">
|
||||||
|
DELETE FROM guacamole_connection_parameter
|
||||||
|
WHERE connection_id = #{identifier,jdbcType=VARCHAR}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- Insert all given parameters -->
|
||||||
|
<insert id="insert" parameterType="net.sourceforge.guacamole.net.auth.mysql.model.ParameterModel">
|
||||||
|
|
||||||
|
INSERT INTO guacamole_connection_parameter (
|
||||||
|
connection_id,
|
||||||
|
parameter_name,
|
||||||
|
parameter_value
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="parameters" item="parameter" separator=",">
|
||||||
|
(#{parameter.connectionIdentifier,jdbcType=VARCHAR},
|
||||||
|
#{parameter.name,jdbcType=VARCHAR},
|
||||||
|
#{parameter.value,jdbcType=VARCHAR})
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Reference in New Issue
Block a user