GUACAMOLE-394: Pull connection last active time from history records.

This commit is contained in:
Michael Jumper
2017-09-11 19:47:59 -07:00
parent b0553d5f16
commit 3d7b8ee89b
5 changed files with 100 additions and 37 deletions

View File

@@ -19,6 +19,7 @@
package org.apache.guacamole.auth.jdbc.connection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.apache.guacamole.auth.jdbc.base.ChildObjectModel;
@@ -92,6 +93,12 @@ public class ConnectionModel extends ChildObjectModel {
*/
private EncryptionMethod proxyEncryptionMethod;
/**
* The date and time that this connection was last used, or null if this
* connection has never been used.
*/
private Date lastActive;
/**
* Creates a new, empty connection.
*/
@@ -341,6 +348,32 @@ public class ConnectionModel extends ChildObjectModel {
this.sharingProfileIdentifiers = sharingProfileIdentifiers;
}
/**
* Returns the date and time that this connection was last used, or null if
* this connection has never been used.
*
* @return
* The date and time that this connection was last used, or null if this
* connection has never been used.
*/
public Date getLastActive() {
return lastActive;
}
/**
* Sets the date and time that this connection was last used. This value is
* expected to be set automatically via queries, derived from connection
* history records. It does NOT correspond to an actual column, and values
* set manually through invoking this function will not persist.
*
* @param lastActive
* The date and time that this connection was last used, or null if this
* connection has never been used.
*/
public void setLastActive(Date lastActive) {
this.lastActive = lastActive;
}
@Override
public String getIdentifier() {

View File

@@ -235,7 +235,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod
@Override
public Date getLastActive() {
return null;
return getModel().getLastActive();
}
@Override

View File

@@ -39,6 +39,7 @@
javaType="org.apache.guacamole.net.auth.GuacamoleProxyConfiguration$EncryptionMethod"/>
<result column="connection_weight" property="connectionWeight" jdbcType="INTEGER"/>
<result column="failover_only" property="failoverOnly" jdbcType="BOOLEAN"/>
<result column="last_active" property="lastActive" jdbcType="TIMESTAMP"/>
<!-- Associated sharing profiles -->
<collection property="sharingProfileIdentifiers" resultSet="sharingProfiles" ofType="java.lang.String"
@@ -89,8 +90,8 @@
resultSets="connections,sharingProfiles">
SELECT
connection_id,
connection_name,
guacamole_connection.connection_id,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -99,13 +100,16 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
WHERE connection_id IN
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE guacamole_connection.connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=VARCHAR}
</foreach>;
</foreach>
GROUP BY guacamole_connection.connection_id;
SELECT primary_connection_id, sharing_profile_id
FROM guacamole_sharing_profile
@@ -123,7 +127,7 @@
SELECT
guacamole_connection.connection_id,
connection_name,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -132,16 +136,19 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
JOIN guacamole_connection_permission ON guacamole_connection_permission.connection_id = guacamole_connection.connection_id
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE guacamole_connection.connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=VARCHAR}
</foreach>
AND user_id = #{user.objectID,jdbcType=INTEGER}
AND permission = 'READ';
AND permission = 'READ'
GROUP BY guacamole_connection.connection_id;
SELECT primary_connection_id, guacamole_sharing_profile.sharing_profile_id
FROM guacamole_sharing_profile
@@ -160,8 +167,8 @@
<select id="selectOneByName" resultMap="ConnectionResultMap">
SELECT
connection_id,
connection_name,
guacamole_connection.connection_id,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -170,12 +177,15 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE
<if test="parentIdentifier != null">parent_id = #{parentIdentifier,jdbcType=VARCHAR}</if>
<if test="parentIdentifier == null">parent_id IS NULL</if>
AND connection_name = #{name,jdbcType=VARCHAR}
AND guacamole_connection.connection_name = #{name,jdbcType=VARCHAR}
GROUP BY guacamole_connection.connection_id
</select>

View File

@@ -39,6 +39,7 @@
javaType="org.apache.guacamole.net.auth.GuacamoleProxyConfiguration$EncryptionMethod"/>
<result column="connection_weight" property="connectionWeight" jdbcType="INTEGER"/>
<result column="failover_only" property="failoverOnly" jdbcType="BOOLEAN"/>
<result column="last_active" property="lastActive" jdbcType="TIMESTAMP"/>
<!-- Associated sharing profiles -->
<collection property="sharingProfileIdentifiers" resultSet="sharingProfiles" ofType="java.lang.String"
@@ -89,8 +90,8 @@
resultSets="connections,sharingProfiles">
SELECT
connection_id,
connection_name,
guacamole_connection.connection_id,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -99,13 +100,16 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
WHERE connection_id IN
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE guacamole_connection.connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER}::integer
</foreach>;
</foreach>
GROUP BY guacamole_connection.connection_id;
SELECT primary_connection_id, sharing_profile_id
FROM guacamole_sharing_profile
@@ -123,7 +127,7 @@
SELECT
guacamole_connection.connection_id,
connection_name,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -132,16 +136,19 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
JOIN guacamole_connection_permission ON guacamole_connection_permission.connection_id = guacamole_connection.connection_id
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE guacamole_connection.connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER}::integer
</foreach>
AND user_id = #{user.objectID,jdbcType=INTEGER}
AND permission = 'READ';
AND permission = 'READ'
GROUP BY guacamole_connection.connection_id;
SELECT primary_connection_id, guacamole_sharing_profile.sharing_profile_id
FROM guacamole_sharing_profile
@@ -160,8 +167,8 @@
<select id="selectOneByName" resultMap="ConnectionResultMap">
SELECT
connection_id,
connection_name,
guacamole_connection.connection_id,
guacamole_connection.connection_name,
parent_id,
protocol,
max_connections,
@@ -170,12 +177,15 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM guacamole_connection
JOIN guacamole_connection_history ON guacamole_connection_history.connection_id = guacamole_connection.connection_id
WHERE
<if test="parentIdentifier != null">parent_id = #{parentIdentifier,jdbcType=INTEGER}::integer</if>
<if test="parentIdentifier == null">parent_id IS NULL</if>
AND connection_name = #{name,jdbcType=VARCHAR}
AND guacamole_connection.connection_name = #{name,jdbcType=VARCHAR}
GROUP BY guacamole_connection.connection_id
</select>

View File

@@ -39,6 +39,7 @@
javaType="org.apache.guacamole.net.auth.GuacamoleProxyConfiguration$EncryptionMethod"/>
<result column="connection_weight" property="connectionWeight" jdbcType="INTEGER"/>
<result column="failover_only" property="failoverOnly" jdbcType="BOOLEAN"/>
<result column="last_active" property="lastActive" jdbcType="TIMESTAMP"/>
<!-- Associated sharing profiles -->
<collection property="sharingProfileIdentifiers" resultSet="sharingProfiles" ofType="java.lang.String"
@@ -89,8 +90,8 @@
resultSets="connections,sharingProfiles">
SELECT
connection_id,
connection_name,
[guacamole_connection].connection_id,
[guacamole_connection].connection_name,
parent_id,
protocol,
max_connections,
@@ -99,13 +100,16 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM [guacamole_connection]
WHERE connection_id IN
JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE [guacamole_connection].connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER}
</foreach>;
</foreach>
GROUP BY [guacamole_connection].connection_id;
SELECT primary_connection_id, sharing_profile_id
FROM [guacamole_sharing_profile]
@@ -123,7 +127,7 @@
SELECT
[guacamole_connection].connection_id,
connection_name,
[guacamole_connection].connection_name,
parent_id,
protocol,
max_connections,
@@ -132,16 +136,19 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM [guacamole_connection]
JOIN [guacamole_connection_permission] ON [guacamole_connection_permission].connection_id = [guacamole_connection].connection_id
JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE [guacamole_connection].connection_id IN
<foreach collection="identifiers" item="identifier"
open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER}
</foreach>
AND user_id = #{user.objectID,jdbcType=INTEGER}
AND permission = 'READ';
AND permission = 'READ'
GROUP BY [guacamole_connection].connection_id;
SELECT primary_connection_id, [guacamole_sharing_profile].sharing_profile_id
FROM [guacamole_sharing_profile]
@@ -160,8 +167,8 @@
<select id="selectOneByName" resultMap="ConnectionResultMap">
SELECT
connection_id,
connection_name,
[guacamole_connection].connection_id,
[guacamole_connection].connection_name,
parent_id,
protocol,
max_connections,
@@ -170,12 +177,15 @@
proxy_port,
proxy_encryption_method,
connection_weight,
failover_only
failover_only,
MAX(start_date) AS last_active
FROM [guacamole_connection]
JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE
<if test="parentIdentifier != null">parent_id = #{parentIdentifier,jdbcType=INTEGER}</if>
<if test="parentIdentifier == null">parent_id IS NULL</if>
AND connection_name = #{name,jdbcType=VARCHAR}
AND [guacamole_connection].connection_name = #{name,jdbcType=VARCHAR}
GROUP BY [guacamole_connection].connection_id
</select>