Skip to content

Commit

Permalink
GUACAMOLE-61: Add JDBC-specific tokens, including connection start da…
Browse files Browse the repository at this point in the history
…te and time.
  • Loading branch information
necouchman committed Apr 16, 2023
1 parent bb93e4c commit 196f4f7
Showing 1 changed file with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -81,6 +82,51 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
*/
private final Logger logger = LoggerFactory.getLogger(AbstractGuacamoleTunnelService.class);

/**
* The token that contains the date the connection was started.
*/
private final String JDBC_DATE_TOKEN = "GUAC_JDBC_STARTDATE";

/**
* The format of the date in the date token.
*/
private final String JDBC_DATE_TOKEN_FORMAT = "yyyyMMdd";

/**
* The token that contains the start time of the connection.
*/
private final String JDBC_TIME_TOKEN = "GUAC_JDBC_STARTTIME";

/**
* The format of the time in the time token.
*/
private final String JDBC_TIME_TOKEN_FORMAT = "HHmmss";

/**
* The token that contains the connection name.
*/
private final String JDBC_CONNECTION_NAME_TOKEN = "GUAC_JDBC_CONNECTION_NAME";

/**
* The token that contains the connection identifier.
*/
private final String JDBC_CONNECTION_ID_TOKEN = "GUAC_JDBC_CONNECTION_ID";

/**
* The token that contains the hostname configured in the connection parameters.
*/
private final String JDBC_CONNECTION_HOSTNAME_TOKEN = "GUAC_JDBC_HOSTNAME";

/**
* The name of the parameter containing the hostname in the configuration.
*/
private final String JDBC_CONNECTION_HOSTNAME_TOKEN_PARAMTER = "hostname";

/**
* The token containing the protocol configured in the connection.
*/
private final String JDBC_CONNECTION_PROTOCOL_TOKEN = "GUAC_JDBC_PROTOCOL";

/**
* Mapper for accessing connections.
*/
Expand Down Expand Up @@ -121,7 +167,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
* All active connections through the tunnel having a given UUID.
*/
private final Map<String, ActiveConnectionRecord> activeTunnels =
new ConcurrentHashMap<String, ActiveConnectionRecord>();
new ConcurrentHashMap<>();

/**
* All active connections to a connection having a given identifier.
Expand Down Expand Up @@ -416,6 +462,21 @@ private GuacamoleTunnel assignGuacamoleTunnel(ActiveConnectionRecord activeConne
GuacamoleClientInformation info, Map<String, String> tokens,
boolean interceptErrors) throws GuacamoleException {

// Set up JDBC-specific tokens
tokens.put(JDBC_DATE_TOKEN,
new SimpleDateFormat(JDBC_DATE_TOKEN_FORMAT)
.format(activeConnection.getStartDate()));
tokens.put(JDBC_TIME_TOKEN,
new SimpleDateFormat(JDBC_TIME_TOKEN_FORMAT)
.format(activeConnection.getStartDate()));
tokens.put(JDBC_CONNECTION_NAME_TOKEN, activeConnection.getConnectionName());
tokens.put(JDBC_CONNECTION_ID_TOKEN, activeConnection.getConnectionIdentifier());
tokens.put(JDBC_CONNECTION_HOSTNAME_TOKEN,
activeConnection.getConnection().getConfiguration().getParameter(JDBC_CONNECTION_HOSTNAME_TOKEN_PARAMTER));
tokens.put(JDBC_CONNECTION_PROTOCOL_TOKEN,
activeConnection.getConnection().getConfiguration().getProtocol());


// Record new active connection
Runnable cleanupTask = new ConnectionCleanupTask(activeConnection);
try {
Expand Down

0 comments on commit 196f4f7

Please sign in to comment.