GUACAMOLE-394: Pull connection last active time from history records.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/3d7b8ee8 Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/3d7b8ee8 Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/3d7b8ee8 Branch: refs/heads/staging/0.9.14 Commit: 3d7b8ee89b278e7bfc0ccad1fa78092450761086 Parents: b0553d5 Author: Michael Jumper <mjum...@apache.org> Authored: Mon Sep 11 19:47:59 2017 -0700 Committer: Michael Jumper <mjum...@apache.org> Committed: Mon Dec 11 23:51:56 2017 -0800 ---------------------------------------------------------------------- .../auth/jdbc/connection/ConnectionModel.java | 33 +++++++++++++++++++ .../auth/jdbc/connection/ModeledConnection.java | 2 +- .../auth/jdbc/connection/ConnectionMapper.xml | 34 +++++++++++++------- .../auth/jdbc/connection/ConnectionMapper.xml | 34 +++++++++++++------- .../auth/jdbc/connection/ConnectionMapper.xml | 34 +++++++++++++------- 5 files changed, 100 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3d7b8ee8/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 788daa1..da45402 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -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; @@ -93,6 +94,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. */ public ConnectionModel() { @@ -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() { http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3d7b8ee8/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index c596b27..eb392bc 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -235,7 +235,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod @Override public Date getLastActive() { - return null; + return getModel().getLastActive(); } @Override http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3d7b8ee8/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index 97c2e54..14b739e 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -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> http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3d7b8ee8/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index dd9265d..09bd510 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -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> http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/3d7b8ee8/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml ---------------------------------------------------------------------- diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index 3e6819f..d27b528 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -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>