diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java index 8c16363a64..a2289342ad 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java @@ -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; @@ -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. */ @@ -121,7 +167,7 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS * All active connections through the tunnel having a given UUID. */ private final Map activeTunnels = - new ConcurrentHashMap(); + new ConcurrentHashMap<>(); /** * All active connections to a connection having a given identifier. @@ -416,6 +462,21 @@ private GuacamoleTunnel assignGuacamoleTunnel(ActiveConnectionRecord activeConne GuacamoleClientInformation info, Map 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 {