diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.java index 7380b213b..720ded317 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.java @@ -62,8 +62,12 @@ public interface ConnectionRecordMapper { * the data they are associated with is is readable by any particular user. * This should only be called on behalf of a system administrator. If * records are needed by a non-administrative user who must have explicit - * read rights, use searchReadable() instead. + * read rights, use {@link searchReadable()} instead. * + * @param identifier + * The optional connection identifier to which records should be limited, + * or null if all records should be retrieved. + * * @param terms * The search terms that must match the returned records. * @@ -77,7 +81,8 @@ public interface ConnectionRecordMapper { * @return * The results of the search performed with the given parameters. */ - List search(@Param("terms") Collection terms, + List search(@Param("identifier") String identifier, + @Param("terms") Collection terms, @Param("sortPredicates") List sortPredicates, @Param("limit") int limit); @@ -86,8 +91,13 @@ public interface ConnectionRecordMapper { * the given terms, sorted by the given predicates. Only records that are * associated with data explicitly readable by the given user will be * returned. If records are needed by a system administrator (who, by - * definition, does not need explicit read rights), use search() instead. + * definition, does not need explicit read rights), use {@link search()} + * instead. * + * @param identifier + * The optional connection identifier for which records should be + * retrieved, or null if all readable records should be retrieved. + * * @param user * The user whose permissions should determine whether a record is * returned. @@ -111,7 +121,8 @@ public interface ConnectionRecordMapper { * @return * The results of the search performed with the given parameters. */ - List searchReadable(@Param("user") UserModel user, + List searchReadable(@Param("identifier") String identifier, + @Param("user") UserModel user, @Param("terms") Collection terms, @Param("sortPredicates") List sortPredicates, @Param("limit") int limit, diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionService.java index 926df32fa..16d378432 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionService.java @@ -213,7 +213,7 @@ public class ConnectionService extends ModeledChildDirectoryObjectService parameters = connection.getConfiguration().getParameters(); // Convert parameters to model objects - Collection parameterModels = new ArrayList(parameters.size()); + Collection parameterModels = new ArrayList<>(parameters.size()); for (Map.Entry parameterEntry : parameters.entrySet()) { // Get parameter name and value @@ -329,7 +329,7 @@ public class ConnectionService extends ModeledChildDirectoryObjectService retrieveParameters(ModeledAuthenticatedUser user, String identifier) { - Map parameterMap = new HashMap(); + Map parameterMap = new HashMap<>(); // Determine whether we have permission to read parameters boolean canRetrieveParameters; @@ -382,7 +382,7 @@ public class ConnectionService extends ModeledChildDirectoryObjectService getObjectInstances(List models) { // Create new list of records by manually converting each model - List objects = new ArrayList(models.size()); + List objects = new ArrayList<>(models.size()); for (ConnectionRecordModel model : models) objects.add(getObjectInstance(model)); @@ -411,28 +411,16 @@ public class ConnectionService extends ModeledChildDirectoryObjectService models = connectionRecordMapper.select(identifier); - - // Get currently-active connections - List records = new ArrayList(tunnelService.getActiveConnections(connection)); - Collections.reverse(records); - - // Add past connections from model objects - for (ConnectionRecordModel model : models) - records.add(getObjectInstance(model)); - - // Return converted history list - return records; - - } - - // The user does not have permission to read the history - throw new GuacamoleSecurityException("Permission denied."); + + // Get current active connections. + List records = new ArrayList<>(tunnelService.getActiveConnections(connection)); + Collections.reverse(records); + + // Add in the history records. + records.addAll(retrieveHistory(identifier, user, Collections.emptyList(), + Collections.emptyList(), Integer.MAX_VALUE)); + + return records; } @@ -442,6 +430,60 @@ public class ConnectionService extends ModeledChildDirectoryObjectService retrieveHistory(String identifier, + ModeledAuthenticatedUser user, + Collection requiredContents, + List sortPredicates, int limit) + throws GuacamoleException { + + List searchResults; + + // Bypass permission checks if the user is privileged + if (user.isPrivileged()) + searchResults = connectionRecordMapper.search(identifier, requiredContents, + sortPredicates, limit); + + // Otherwise only return explicitly readable history records + else + searchResults = connectionRecordMapper.searchReadable(identifier, + user.getUser().getModel(), requiredContents, sortPredicates, + limit, user.getEffectiveUserGroups()); + + return getObjectInstances(searchResults); + + } + + /** + * Retrieves the connection history records matching the given criteria. + * Retrieves up to limit connection history records matching + * the given terms and sorted by the given predicates. Only history records + * associated with data that the given user can read are returned. + * * @param user * The user retrieving the connection history. * @@ -467,22 +509,9 @@ public class ConnectionService extends ModeledChildDirectoryObjectService requiredContents, List sortPredicates, int limit) throws GuacamoleException { - - List searchResults; - - // Bypass permission checks if the user is privileged - if (user.isPrivileged()) - searchResults = connectionRecordMapper.search(requiredContents, - sortPredicates, limit); - - // Otherwise only return explicitly readable history records - else - searchResults = connectionRecordMapper.searchReadable( - user.getUser().getModel(), requiredContents, sortPredicates, - limit, user.getEffectiveUserGroups()); - - return getObjectInstances(searchResults); - + + return retrieveHistory(null, user, requiredContents, sortPredicates, limit); + } /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.java index 92501ab0b..fe15f41e4 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.java @@ -73,8 +73,12 @@ public interface UserRecordMapper { * the data they are associated with is is readable by any particular user. * This should only be called on behalf of a system administrator. If * records are needed by a non-administrative user who must have explicit - * read rights, use searchReadable() instead. + * read rights, use {@link searchReadable()} instead. * + * @param username + * The optional username to which records should be limited, or null + * if all records should be retrieved. + * * @param terms * The search terms that must match the returned records. * @@ -88,7 +92,8 @@ public interface UserRecordMapper { * @return * The results of the search performed with the given parameters. */ - List search(@Param("terms") Collection terms, + List search(@Param("username") String username, + @Param("terms") Collection terms, @Param("sortPredicates") List sortPredicates, @Param("limit") int limit); @@ -97,11 +102,16 @@ public interface UserRecordMapper { * the given terms, sorted by the given predicates. Only records that are * associated with data explicitly readable by the given user will be * returned. If records are needed by a system administrator (who, by - * definition, does not need explicit read rights), use search() instead. + * definition, does not need explicit read rights), use {@link search()} + * instead. * + * @param username + * The optional username to which records should be limited, or null + * if all readable records should be retrieved. + * * @param user - * The user whose permissions should determine whether a record is - * returned. + * The user whose permissions should determine whether a record is + * returned. * * @param terms * The search terms that must match the returned records. @@ -122,7 +132,8 @@ public interface UserRecordMapper { * @return * The results of the search performed with the given parameters. */ - List searchReadable(@Param("user") UserModel user, + List searchReadable(@Param("username") String username, + @Param("user") UserModel user, @Param("terms") Collection terms, @Param("sortPredicates") List sortPredicates, @Param("limit") int limit, diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java index 50b9e4295..80d555cc5 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/UserService.java @@ -32,7 +32,6 @@ import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObjectMapper; import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObjectService; import org.apache.guacamole.GuacamoleClientException; import org.apache.guacamole.GuacamoleException; -import org.apache.guacamole.GuacamoleSecurityException; import org.apache.guacamole.GuacamoleUnsupportedException; import org.apache.guacamole.auth.jdbc.base.ActivityRecordModel; import org.apache.guacamole.auth.jdbc.base.ActivityRecordSearchTerm; @@ -581,13 +580,9 @@ public class UserService extends ModeledDirectoryObjectService retrieveHistory(String username, + ModeledAuthenticatedUser user, + Collection requiredContents, + List sortPredicates, int limit) + throws GuacamoleException { + + List searchResults; + + // Bypass permission checks if the user is privileged + if (user.isPrivileged()) + searchResults = userRecordMapper.search(username, requiredContents, + sortPredicates, limit); + + // Otherwise only return explicitly readable history records + else + searchResults = userRecordMapper.searchReadable(username, + user.getUser().getModel(), + requiredContents, sortPredicates, limit, user.getEffectiveUserGroups()); + + return getObjectInstances(searchResults); + + } + + /** + * Retrieves user login history records matching the given criteria. + * Retrieves up to limit user history records matching the + * given terms and sorted by the given predicates. Only history records + * associated with data that the given user can read are returned. + * * @param user * The user retrieving the login history. * @@ -621,21 +669,9 @@ public class UserService extends ModeledDirectoryObjectService requiredContents, List sortPredicates, int limit) throws GuacamoleException { - - List searchResults; - - // Bypass permission checks if the user is privileged - if (user.isPrivileged()) - searchResults = userRecordMapper.search(requiredContents, - sortPredicates, limit); - - // Otherwise only return explicitly readable history records - else - searchResults = userRecordMapper.searchReadable(user.getUser().getModel(), - requiredContents, sortPredicates, limit, user.getEffectiveUserGroups()); - - return getObjectInstances(searchResults); - + + return retrieveHistory(null, user, requiredContents, sortPredicates, limit); + } } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml index d74d4c4cb..daeec396f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml @@ -108,28 +108,35 @@ LEFT JOIN guacamole_user ON guacamole_connection_history.user_id = guacamole_user.user_id - - ( + + + + guacamole_connection_history.connection_id = #{identifier,jdbcType=VARCHAR} + + + + ( + + guacamole_connection_history.user_id IN ( + SELECT user_id + FROM guacamole_user + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN username) > 0 + ) + + OR guacamole_connection_history.connection_id IN ( + SELECT connection_id + FROM guacamole_connection + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_connection_history.user_id IN ( - SELECT user_id - FROM guacamole_user - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN username) > 0 ) - - OR guacamole_connection_history.connection_id IN ( - SELECT connection_id - FROM guacamole_connection - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + @@ -186,31 +193,38 @@ AND guacamole_user_permission.permission = 'READ' - - ( + + + + guacamole_connection_history.connection_id = #{identifier,jdbcType=VARCHAR} + + + + ( + + guacamole_connection_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER' + ) + + OR guacamole_connection_history.connection_id IN ( + SELECT connection_id + FROM guacamole_connection + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_connection_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER' ) - - OR guacamole_connection_history.connection_id IN ( - SELECT connection_id - FROM guacamole_connection - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml index d9c02ef54..46edb96cd 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml @@ -105,25 +105,32 @@ FROM guacamole_user_history - - ( + + + + guacamole_user_history.username = #{username,jdbcType=VARCHAR} + + + + ( + + guacamole_user_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER'), + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_user_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER'), ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + @@ -164,25 +171,32 @@ AND guacamole_user_permission.permission = 'READ' - - ( + + + + guacamole_entity.name = #{username,jdbcType=VARCHAR} + + + + ( + + guacamole_user_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER' + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_user_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER' ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml index e8e88764b..2d2ed5bc9 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml @@ -106,28 +106,35 @@ FROM guacamole_connection_history - - ( + + + + guacamole_connection_history.connection_id = #{identifier,jdbcType=INTEGER}::integer + + + + ( + + guacamole_connection_history.user_id IN ( + SELECT user_id + FROM guacamole_user + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN username) > 0 + ) + + OR guacamole_connection_history.connection_id IN ( + SELECT connection_id + FROM guacamole_connection + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_connection_history.user_id IN ( - SELECT user_id - FROM guacamole_user - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN username) > 0 ) - - OR guacamole_connection_history.connection_id IN ( - SELECT connection_id - FROM guacamole_connection - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + @@ -184,31 +191,38 @@ AND guacamole_user_permission.permission = 'READ' - - ( + + + + guacamole_connection_history.connection_id = #{identifier,jdbcType=INTEGER}::integer + + + + ( + + guacamole_connection_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER'::guacamole_entity_type + ) + + OR guacamole_connection_history.connection_id IN ( + SELECT connection_id + FROM guacamole_connection + WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_connection_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER'::guacamole_entity_type ) + - OR guacamole_connection_history.connection_id IN ( - SELECT connection_id - FROM guacamole_connection - WHERE POSITION(#{term.term,jdbcType=VARCHAR} IN connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml index 6311a2546..b943bb6ff 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml @@ -105,25 +105,32 @@ FROM guacamole_user_history - - ( + + + + guacamole_user_history.username = #{username,jdbcType=VARCHAR} + + + + ( + + guacamole_user_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER'::guacamole_entity_type), + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_user_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER'::guacamole_entity_type), ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + @@ -164,25 +171,31 @@ AND guacamole_user_permission.permission = 'READ' - - ( + + + guacamole_entity.name = #{username,jdbcType=VARCHAR} + + + + ( + + guacamole_user_history.user_id IN ( + SELECT user_id + FROM guacamole_user + JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id + WHERE + POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 + AND guacamole_entity.type = 'USER'::guacamole_entity_type + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - guacamole_user_history.user_id IN ( - SELECT user_id - FROM guacamole_user - JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - WHERE - POSITION(#{term.term,jdbcType=VARCHAR} IN guacamole_entity.name) > 0 - AND guacamole_entity.type = 'USER'::guacamole_entity_type ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml index 5d97b0b88..e24f2e863 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionRecordMapper.xml @@ -106,28 +106,35 @@ FROM [guacamole_connection_history] - - ( + + + + [guacamole_connection_history].connection_id = #{identifier,jdbcType=INTEGER} + + + + ( + + [guacamole_connection_history].user_id IN ( + SELECT user_id + FROM [guacamole_user] + WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, username) > 0 + ) + + OR [guacamole_connection_history].connection_id IN ( + SELECT connection_id + FROM [guacamole_connection] + WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - [guacamole_connection_history].user_id IN ( - SELECT user_id - FROM [guacamole_user] - WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, username) > 0 ) - - OR [guacamole_connection_history].connection_id IN ( - SELECT connection_id - FROM [guacamole_connection] - WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + @@ -182,31 +189,38 @@ AND [guacamole_user_permission].permission = 'READ' - - ( + + + + [guacamole_connection_history].connection_id = #{identifier,jdbcType=INTEGER} + + + + ( + + [guacamole_connection_history].user_id IN ( + SELECT user_id + FROM [guacamole_user] + JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id + WHERE + CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 + AND [guacamole_entity].type = 'USER' + ) + + OR [guacamole_connection_history].connection_id IN ( + SELECT connection_id + FROM [guacamole_connection] + WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, connection_name) > 0 + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - [guacamole_connection_history].user_id IN ( - SELECT user_id - FROM [guacamole_user] - JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id - WHERE - CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 - AND [guacamole_entity].type = 'USER' ) - - OR [guacamole_connection_history].connection_id IN ( - SELECT connection_id - FROM [guacamole_connection] - WHERE CHARINDEX(#{term.term,jdbcType=VARCHAR}, connection_name) > 0 - ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml index 7cc5efabb..179ef39ae 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserRecordMapper.xml @@ -105,25 +105,32 @@ FROM [guacamole_user_history] - - ( + + + + [guacamole_user_history].username = #{username,jdbcType=VARCHAR} + + + + ( + + [guacamole_user_history].user_id IN ( + SELECT user_id + FROM [guacamole_user] + JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id + WHERE + CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 + AND [guacamole_entity].type = 'USER'), + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - [guacamole_user_history].user_id IN ( - SELECT user_id - FROM [guacamole_user] - JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id - WHERE - CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 - AND [guacamole_entity].type = 'USER'), ) + - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + @@ -162,25 +169,32 @@ AND [guacamole_user_permission].permission = 'READ' - - ( + + + + [guacamole_entity].name = #{username,jdbcType=VARCHAR} + + + + ( + + [guacamole_user_history].user_id IN ( + SELECT user_id + FROM [guacamole_user] + JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id + WHERE + CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 + AND [guacamole_entity].type = 'USER' + ) + + + OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} + - [guacamole_user_history].user_id IN ( - SELECT user_id - FROM [guacamole_user] - JOIN [guacamole_entity] ON [guacamole_user].entity_id = [guacamole_entity].entity_id - WHERE - CHARINDEX(#{term.term,jdbcType=VARCHAR}, [guacamole_entity].name) > 0 - AND [guacamole_entity].type = 'USER' ) - - - OR start_date BETWEEN #{term.startDate,jdbcType=TIMESTAMP} AND #{term.endDate,jdbcType=TIMESTAMP} - - - ) - + + + diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/connection/ConnectionResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/connection/ConnectionResource.java index 3149987d1..02c2c0f6e 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/connection/ConnectionResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/connection/ConnectionResource.java @@ -156,7 +156,7 @@ public class ConnectionResource extends DirectoryObjectResource apiRecords = new ArrayList(); + List apiRecords = new ArrayList<>(); for (ConnectionRecord record : connection.getHistory()) apiRecords.add(new APIConnectionRecord(record)); @@ -184,7 +184,7 @@ public class ConnectionResource extends DirectoryObjectResource sharingProfiles = new DirectoryView( + Directory sharingProfiles = new DirectoryView<>( userContext.getSharingProfileDirectory(), connection.getSharingProfileIdentifiers() );