@Override
    public GuacamoleTunnel connect(GuacamoleClientInformation info,
            Map<String, String> tokens) throws GuacamoleException {

        // Create a connection record model, starting at the current date/time
        ConnectionRecordModel connectionRecordModel = new ConnectionRecordModel();
        connectionRecordModel.setStartDate(new Date());

        // Set the user information
        connectionRecordModel.setUsername(this.currentUser.getIdentifier());
        connectionRecordModel.setRemoteHost(this.remoteHost);

        // Set the connection information
        connectionRecordModel.setConnectionName(this.getDelegateConnection().getName());

        // Insert the connection history record to mark the start of this connection
        connectionRecordMapper.insert(connectionRecordModel,
                environment.getCaseSensitivity());

        // Include history record UUID as token
        ModeledConnectionRecord modeledRecord = new ModeledConnectionRecord(connectionRecordModel);
        Map<String, String> updatedTokens = new HashMap<>(tokens);
        updatedTokens.put("HISTORY_UUID", modeledRecord.getUUID().toString());

        // Connect, and wrap the tunnel for return
        GuacamoleTunnel tunnel = super.connect(info, updatedTokens);
        return new HistoryTrackingTunnel(
            tunnel, this.connectionRecordMapper, connectionRecordModel);
    }
Creates a new HistoryConnection that wraps the given connection,
automatically creating a history record when the connection is
established, and returning a HistoryTrackingTunnel to set the end
date on the history entry when the connection is closed.

@param currentUser
    The current Guacamole user.

@param remoteHost
    The remote host that the user connected from.

@param connection
    The connection to wrap.

@param connectionRecordMapper
    The connection record mapper that will be used to write the connection history records.
extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/HistoryTrackingConnection.java