mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1101: Separate configuration and record saving into own functions.
This commit is contained in:
@@ -139,6 +139,80 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
protected abstract void release(AuthenticatedUser user,
|
protected abstract void release(AuthenticatedUser user,
|
||||||
ModeledConnection connection);
|
ModeledConnection connection);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a guacamole configuration containing the protocol and parameters
|
||||||
|
* from the given connection. If tokens are used in the connection
|
||||||
|
* parameter values, credentials from the given user will be substituted
|
||||||
|
* appropriately.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* The user whose credentials should be used if necessary.
|
||||||
|
*
|
||||||
|
* @param connection
|
||||||
|
* The connection whose protocol and parameters should be added to the
|
||||||
|
* returned configuration.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A GuacamoleConfiguration containing the protocol and parameters from
|
||||||
|
* the given connection.
|
||||||
|
*/
|
||||||
|
private GuacamoleConfiguration getGuacamoleConfiguration(AuthenticatedUser user,
|
||||||
|
ModeledConnection connection) {
|
||||||
|
|
||||||
|
// Generate configuration from available data
|
||||||
|
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
||||||
|
|
||||||
|
// Set protocol from connection
|
||||||
|
ConnectionModel model = connection.getModel();
|
||||||
|
config.setProtocol(model.getProtocol());
|
||||||
|
|
||||||
|
// Set parameters from associated data
|
||||||
|
Collection<ParameterModel> parameters = parameterMapper.select(connection.getIdentifier());
|
||||||
|
for (ParameterModel parameter : parameters)
|
||||||
|
config.setParameter(parameter.getName(), parameter.getValue());
|
||||||
|
|
||||||
|
// Build token filter containing credential tokens
|
||||||
|
TokenFilter tokenFilter = new TokenFilter();
|
||||||
|
StandardTokens.addStandardTokens(tokenFilter, user.getCredentials());
|
||||||
|
|
||||||
|
// Filter the configuration
|
||||||
|
tokenFilter.filterValues(config.getParameters());
|
||||||
|
|
||||||
|
return config;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the given ActiveConnectionRecord to the database, associating it
|
||||||
|
* with the connection having the given identifier. The end date of the
|
||||||
|
* saved record will be populated with the current time.
|
||||||
|
*
|
||||||
|
* @param identifier
|
||||||
|
* The connection to associate the new record with.
|
||||||
|
*
|
||||||
|
* @param record
|
||||||
|
* The record to save.
|
||||||
|
*/
|
||||||
|
private void saveConnectionRecord(String identifier,
|
||||||
|
ActiveConnectionRecord record) {
|
||||||
|
|
||||||
|
// Get associated models
|
||||||
|
AuthenticatedUser user = record.getUser();
|
||||||
|
UserModel userModel = user.getUser().getModel();
|
||||||
|
ConnectionRecordModel recordModel = new ConnectionRecordModel();
|
||||||
|
|
||||||
|
// Copy user information and timestamps into new record
|
||||||
|
recordModel.setUserID(userModel.getObjectID());
|
||||||
|
recordModel.setUsername(userModel.getIdentifier());
|
||||||
|
recordModel.setConnectionIdentifier(identifier);
|
||||||
|
recordModel.setStartDate(record.getStartDate());
|
||||||
|
recordModel.setEndDate(new Date());
|
||||||
|
|
||||||
|
// Insert connection record
|
||||||
|
connectionRecordMapper.insert(recordModel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a socket for the given user which connects to the given
|
* Creates a socket for the given user which connects to the given
|
||||||
* connection, which MUST already be acquired via acquire(). The given
|
* connection, which MUST already be acquired via acquire(). The given
|
||||||
@@ -178,25 +252,6 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
final String identifier = connection.getIdentifier();
|
final String identifier = connection.getIdentifier();
|
||||||
final String parentIdentifier = connection.getParentIdentifier();
|
final String parentIdentifier = connection.getParentIdentifier();
|
||||||
|
|
||||||
// Generate configuration from available data
|
|
||||||
GuacamoleConfiguration config = new GuacamoleConfiguration();
|
|
||||||
|
|
||||||
// Set protocol from connection
|
|
||||||
ConnectionModel model = connection.getModel();
|
|
||||||
config.setProtocol(model.getProtocol());
|
|
||||||
|
|
||||||
// Set parameters from associated data
|
|
||||||
Collection<ParameterModel> parameters = parameterMapper.select(identifier);
|
|
||||||
for (ParameterModel parameter : parameters)
|
|
||||||
config.setParameter(parameter.getName(), parameter.getValue());
|
|
||||||
|
|
||||||
// Build token filter containing credential tokens
|
|
||||||
TokenFilter tokenFilter = new TokenFilter();
|
|
||||||
StandardTokens.addStandardTokens(tokenFilter, user.getCredentials());
|
|
||||||
|
|
||||||
// Filter the configuration
|
|
||||||
tokenFilter.filterValues(config.getParameters());
|
|
||||||
|
|
||||||
// Return new socket
|
// Return new socket
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -210,7 +265,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
environment.getRequiredProperty(Environment.GUACD_HOSTNAME),
|
environment.getRequiredProperty(Environment.GUACD_HOSTNAME),
|
||||||
environment.getRequiredProperty(Environment.GUACD_PORT)
|
environment.getRequiredProperty(Environment.GUACD_PORT)
|
||||||
),
|
),
|
||||||
config
|
getGuacamoleConfiguration(user, connection)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -227,18 +282,8 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
activeConnectionGroups.remove(parentIdentifier, activeConnection);
|
activeConnectionGroups.remove(parentIdentifier, activeConnection);
|
||||||
release(user, connection);
|
release(user, connection);
|
||||||
|
|
||||||
UserModel userModel = user.getUser().getModel();
|
// Save record to database
|
||||||
ConnectionRecordModel recordModel = new ConnectionRecordModel();
|
saveConnectionRecord(identifier, activeConnection);
|
||||||
|
|
||||||
// Copy user information and timestamps into new record
|
|
||||||
recordModel.setUserID(userModel.getObjectID());
|
|
||||||
recordModel.setUsername(userModel.getIdentifier());
|
|
||||||
recordModel.setConnectionIdentifier(identifier);
|
|
||||||
recordModel.setStartDate(activeConnection.getStartDate());
|
|
||||||
recordModel.setEndDate(new Date());
|
|
||||||
|
|
||||||
// Insert connection record
|
|
||||||
connectionRecordMapper.insert(recordModel);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,18 @@ public class ActiveConnectionRecord implements ConnectionRecord {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user that connected to the connection associated with this
|
||||||
|
* connection record.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The user that connected to the connection associated with this
|
||||||
|
* connection record.
|
||||||
|
*/
|
||||||
|
public AuthenticatedUser getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getStartDate() {
|
public Date getStartDate() {
|
||||||
return startDate;
|
return startDate;
|
||||||
|
Reference in New Issue
Block a user