mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Ticket #263: More querying.
This commit is contained in:
@@ -60,6 +60,11 @@ public class MySQLConnection extends AbstractConnection {
|
|||||||
*/
|
*/
|
||||||
private Integer connectionID;
|
private Integer connectionID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the parent connection for this connection group.
|
||||||
|
*/
|
||||||
|
private Integer parentID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the user who queried or created this connection.
|
* The ID of the user who queried or created this connection.
|
||||||
*/
|
*/
|
||||||
@@ -98,20 +103,38 @@ public class MySQLConnection extends AbstractConnection {
|
|||||||
this.connectionID = connectionID;
|
this.connectionID = connectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the parent connection group for this connection, if any.
|
||||||
|
* @return The ID of the parent connection group for this connection, if any.
|
||||||
|
*/
|
||||||
|
public Integer getParentID() {
|
||||||
|
return parentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ID of the parent connection group for this connection.
|
||||||
|
* @param connectionID The ID of the parent connection group for this connection.
|
||||||
|
*/
|
||||||
|
public void setParentID(Integer parentID) {
|
||||||
|
this.parentID = parentID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize from explicit values.
|
* Initialize from explicit values.
|
||||||
*
|
*
|
||||||
* @param connectionID The ID of the associated database record, if any.
|
* @param connectionID The ID of the associated database record, if any.
|
||||||
|
* @param parentID The D of the parent connection group for this connection, if any.
|
||||||
* @param identifier The unique identifier associated with this connection.
|
* @param identifier The unique identifier associated with this connection.
|
||||||
* @param config The GuacamoleConfiguration associated with this connection.
|
* @param config The GuacamoleConfiguration associated with this connection.
|
||||||
* @param history All ConnectionRecords associated with this connection.
|
* @param history All ConnectionRecords associated with this connection.
|
||||||
* @param userID The IID of the user who queried this connection.
|
* @param userID The IID of the user who queried this connection.
|
||||||
*/
|
*/
|
||||||
public void init(Integer connectionID, String identifier,
|
public void init(Integer connectionID, Integer parentID, String identifier,
|
||||||
GuacamoleConfiguration config,
|
GuacamoleConfiguration config,
|
||||||
List<? extends ConnectionRecord> history, int userID) {
|
List<? extends ConnectionRecord> history, int userID) {
|
||||||
|
|
||||||
this.connectionID = connectionID;
|
this.connectionID = connectionID;
|
||||||
|
this.parentID = parentID;
|
||||||
setIdentifier(identifier);
|
setIdentifier(identifier);
|
||||||
setConfiguration(config);
|
setConfiguration(config);
|
||||||
this.history.addAll(history);
|
this.history.addAll(history);
|
||||||
|
@@ -45,6 +45,8 @@ import net.sourceforge.guacamole.net.auth.Connection;
|
|||||||
import net.sourceforge.guacamole.net.auth.ConnectionGroup;
|
import net.sourceforge.guacamole.net.auth.ConnectionGroup;
|
||||||
import net.sourceforge.guacamole.net.auth.Directory;
|
import net.sourceforge.guacamole.net.auth.Directory;
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
|
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionGroupService;
|
||||||
|
import net.sourceforge.guacamole.net.auth.mysql.service.ConnectionService;
|
||||||
|
import net.sourceforge.guacamole.net.auth.mysql.service.PermissionCheckService;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +60,11 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
|
|||||||
*/
|
*/
|
||||||
private Integer connectionGroupID;
|
private Integer connectionGroupID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the parent connection group for this connection group.
|
||||||
|
*/
|
||||||
|
private Integer parentID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the user who queried or created this connection group.
|
* The ID of the user who queried or created this connection group.
|
||||||
*/
|
*/
|
||||||
@@ -73,12 +80,24 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
|
|||||||
*/
|
*/
|
||||||
private Directory<String, ConnectionGroup> connectionGroupDirectory = null;
|
private Directory<String, ConnectionGroup> connectionGroupDirectory = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service managing connections.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private ConnectionService connectionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service managing connection groups.
|
* Service managing connection groups.
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
private ConnectionGroupService connectionGroupService;
|
private ConnectionGroupService connectionGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service for checking permissions.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
private PermissionCheckService permissionCheckService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default, empty connection group.
|
* Create a default, empty connection group.
|
||||||
*/
|
*/
|
||||||
@@ -101,15 +120,33 @@ public class MySQLConnectionGroup extends AbstractConnectionGroup {
|
|||||||
this.connectionGroupID = connectionGroupID;
|
this.connectionGroupID = connectionGroupID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the parent connection group for this connection group, if any.
|
||||||
|
* @return The ID of the parent connection group for this connection group, if any.
|
||||||
|
*/
|
||||||
|
public Integer getParentID() {
|
||||||
|
return parentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ID of the parent connection group for this connection group.
|
||||||
|
* @param connectionID The ID of the parent connection group for this connection group.
|
||||||
|
*/
|
||||||
|
public void setParentID(Integer parentID) {
|
||||||
|
this.parentID = parentID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize from explicit values.
|
* Initialize from explicit values.
|
||||||
*
|
*
|
||||||
* @param connectionGroupID The ID of the associated database record, if any.
|
* @param connectionGroupID The ID of the associated database record, if any.
|
||||||
|
* @param parentID The D of the parent connection group for this connection group, if any.
|
||||||
* @param identifier The unique identifier associated with this connection group.
|
* @param identifier The unique identifier associated with this connection group.
|
||||||
* @param userID The IID of the user who queried this connection.
|
* @param userID The IID of the user who queried this connection.
|
||||||
*/
|
*/
|
||||||
public void init(Integer connectionGroupID, String identifier, int userID) {
|
public void init(Integer connectionGroupID, Integer parentID, String identifier, int userID) {
|
||||||
this.connectionGroupID = connectionGroupID;
|
this.connectionGroupID = connectionGroupID;
|
||||||
|
this.parentID = parentID;
|
||||||
setIdentifier(identifier);
|
setIdentifier(identifier);
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
}
|
}
|
||||||
|
@@ -51,8 +51,6 @@ import java.util.Set;
|
|||||||
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
import net.sourceforge.guacamole.net.GuacamoleSocket;
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionGroup;
|
import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionGroup;
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper;
|
import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper;
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.model.Connection;
|
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionExample;
|
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup;
|
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroup;
|
||||||
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample;
|
import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionGroupExample;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
||||||
@@ -65,18 +63,6 @@ import net.sourceforge.guacamole.protocol.GuacamoleClientInformation;
|
|||||||
*/
|
*/
|
||||||
public class ConnectionGroupService {
|
public class ConnectionGroupService {
|
||||||
|
|
||||||
/**
|
|
||||||
* Service managing users.
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service managing connections.
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
private ConnectionService connectionService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DAO for accessing connection groups.
|
* DAO for accessing connection groups.
|
||||||
*/
|
*/
|
||||||
@@ -88,15 +74,40 @@ public class ConnectionGroupService {
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
private Provider<MySQLConnectionGroup> mysqlConnectionGroupProvider;
|
private Provider<MySQLConnectionGroup> mysqlConnectionGroupProvider;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all connection groups with a given parent connection group ID.
|
||||||
|
*
|
||||||
|
* @param parentID The parent ID of the connection groups.
|
||||||
|
* @param userID The ID of the user who queried these connection groups.
|
||||||
|
* @return All connection groups with a given parent connection group ID.
|
||||||
|
*/
|
||||||
|
public Collection<MySQLConnectionGroup> getConnectionGroupsByParentConnectionGroup(Integer parentID, int userID) {
|
||||||
|
|
||||||
|
// A null parentID indicates the root-level group
|
||||||
|
ConnectionGroupExample example = new ConnectionGroupExample();
|
||||||
|
if(parentID != null)
|
||||||
|
example.createCriteria().andParent_group_idEqualTo(parentID);
|
||||||
|
else
|
||||||
|
example.createCriteria().andParent_group_idIsNull();
|
||||||
|
|
||||||
|
// Get all connections with the given parent ID
|
||||||
|
List<ConnectionGroup> connectionGroups = connectionGroupDAO.selectByExample(example);
|
||||||
|
|
||||||
|
List<MySQLConnectionGroup> mySQLConnectionGroups = new ArrayList<MySQLConnectionGroup>();
|
||||||
|
|
||||||
|
for(ConnectionGroup connectionGroup : connectionGroups) {
|
||||||
|
mySQLConnectionGroups.add(toMySQLConnectionGroup(connectionGroup, userID));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mySQLConnectionGroups;
|
||||||
|
}
|
||||||
|
|
||||||
public GuacamoleSocket connect(MySQLConnectionGroup group,
|
public GuacamoleSocket connect(MySQLConnectionGroup group,
|
||||||
GuacamoleClientInformation info, int userID) {
|
GuacamoleClientInformation info, int userID) {
|
||||||
throw new UnsupportedOperationException("Not yet implemented");
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
//public Collection<MySQLConnection> getConnectionGroupConnections()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a map of all connection group names for the given IDs.
|
* Retrieves a map of all connection group names for the given IDs.
|
||||||
@@ -148,6 +159,31 @@ public class ConnectionGroupService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the given database-retrieved Connection into a MySQLConnection.
|
||||||
|
* The parameters of the given connection will be read and added to the
|
||||||
|
* MySQLConnection in the process.
|
||||||
|
*
|
||||||
|
* @param connection The connection to convert.
|
||||||
|
* @param userID The user who queried this connection.
|
||||||
|
* @return A new MySQLConnection containing all data associated with the
|
||||||
|
* specified connection.
|
||||||
|
*/
|
||||||
|
private MySQLConnectionGroup toMySQLConnectionGroup(ConnectionGroup connectionGroup, int userID) {
|
||||||
|
|
||||||
|
// Create new MySQLConnection from retrieved data
|
||||||
|
MySQLConnectionGroup mySQLConnectionGroup = mysqlConnectionGroupProvider.get();
|
||||||
|
mySQLConnectionGroup.init(
|
||||||
|
connectionGroup.getConnection_group_id(),
|
||||||
|
connectionGroup.getParent_group_id(),
|
||||||
|
connectionGroup.getConnection_group_name(),
|
||||||
|
userID
|
||||||
|
);
|
||||||
|
|
||||||
|
return mySQLConnectionGroup;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the connection group IDs of all the connection groups defined in the system.
|
* Get the connection group IDs of all the connection groups defined in the system.
|
||||||
*
|
*
|
||||||
|
@@ -172,6 +172,34 @@ public class ConnectionService {
|
|||||||
// Otherwise, return found connection
|
// Otherwise, return found connection
|
||||||
return toMySQLConnection(connection, userID);
|
return toMySQLConnection(connection, userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all connections with a given parent connection group ID.
|
||||||
|
*
|
||||||
|
* @param parentID The parent ID of the connections.
|
||||||
|
* @param userID The ID of the user who queried these connections.
|
||||||
|
* @return All connections with a given parent connection group ID.
|
||||||
|
*/
|
||||||
|
public Collection<MySQLConnection> getConnectionsByParentConnectionGroup(Integer parentID, int userID) {
|
||||||
|
|
||||||
|
// A null parentID indicates the root-level group
|
||||||
|
ConnectionExample example = new ConnectionExample();
|
||||||
|
if(parentID != null)
|
||||||
|
example.createCriteria().andConnection_group_idEqualTo(parentID);
|
||||||
|
else
|
||||||
|
example.createCriteria().andConnection_group_idIsNull();
|
||||||
|
|
||||||
|
// Get all connections with the given parent ID
|
||||||
|
List<Connection> connections = connectionDAO.selectByExample(example);
|
||||||
|
|
||||||
|
List<MySQLConnection> mySQLConnections = new ArrayList<MySQLConnection>();
|
||||||
|
|
||||||
|
for(Connection connection : connections) {
|
||||||
|
mySQLConnections.add(toMySQLConnection(connection, userID));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mySQLConnections;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a translation map of connection names to their corresponding
|
* Retrieves a translation map of connection names to their corresponding
|
||||||
@@ -267,6 +295,7 @@ public class ConnectionService {
|
|||||||
MySQLConnection mySQLConnection = mySQLConnectionProvider.get();
|
MySQLConnection mySQLConnection = mySQLConnectionProvider.get();
|
||||||
mySQLConnection.init(
|
mySQLConnection.init(
|
||||||
connection.getConnection_id(),
|
connection.getConnection_id(),
|
||||||
|
connection.getConnection_group_id(),
|
||||||
connection.getConnection_name(),
|
connection.getConnection_name(),
|
||||||
config,
|
config,
|
||||||
retrieveHistory(connection.getConnection_id()),
|
retrieveHistory(connection.getConnection_id()),
|
||||||
|
Reference in New Issue
Block a user