GUACAMOLE-1123: Implement new methods for retrieving user and connection history.

This commit is contained in:
Virtually Nick
2020-08-23 14:51:32 -04:00
parent 54b80f94bf
commit 71625340f5
20 changed files with 169 additions and 34 deletions

View File

@@ -48,7 +48,7 @@ public abstract class ModeledActivityRecordSet<RecordType extends ActivityRecord
* strings within the collection will be excluded from the results.
*/
private final Set<ActivityRecordSearchTerm> requiredContents =
new HashSet<ActivityRecordSearchTerm>();
new HashSet<>();
/**
* The maximum number of history records that should be returned by a call
@@ -62,7 +62,7 @@ public abstract class ModeledActivityRecordSet<RecordType extends ActivityRecord
* properties.
*/
private final List<ActivityRecordSortPredicate> sortPredicates =
new ArrayList<ActivityRecordSortPredicate>();
new ArrayList<>();
/**
* Retrieves the history records matching the given criteria. Retrieves up

View File

@@ -27,6 +27,7 @@ import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.base.ActivityRecordSearchTerm;
import org.apache.guacamole.auth.jdbc.base.ActivityRecordSortPredicate;
import org.apache.guacamole.auth.jdbc.base.ModeledActivityRecordSet;
import org.apache.guacamole.auth.jdbc.user.ModeledAuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.ConnectionRecord;
@@ -43,6 +44,27 @@ public class ConnectionRecordSet extends ModeledActivityRecordSet<ConnectionReco
@Inject
private ConnectionService connectionService;
/**
* The identifier of the connection to which this record set should be
* limited, if any.
*/
private String identifier = null;
/**
* Initializes this object, associating it with the current authenticated
* user and connection identifier.
*
* @param currentUser
* The user that created or retrieved this object.
*
* @param identifier
* The connection identifier to which this record set should be limited.
*/
protected void init(ModeledAuthenticatedUser currentUser, String identifier) {
super.init(currentUser);
this.identifier = identifier;
}
@Override
protected Collection<ConnectionRecord> retrieveHistory(
AuthenticatedUser user, Set<ActivityRecordSearchTerm> requiredContents,
@@ -50,7 +72,7 @@ public class ConnectionRecordSet extends ModeledActivityRecordSet<ConnectionReco
throws GuacamoleException {
// Retrieve history from database
return connectionService.retrieveHistory(getCurrentUser(),
return connectionService.retrieveHistory(identifier, getCurrentUser(),
requiredContents, sortPredicates, limit);
}

View File

@@ -40,6 +40,7 @@ import org.apache.guacamole.form.Form;
import org.apache.guacamole.form.NumericField;
import org.apache.guacamole.form.TextField;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
@@ -196,6 +197,12 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod
@Inject
private Provider<ModeledGuacamoleConfiguration> configProvider;
/**
* Provider for creating connection record sets.
*/
@Inject
private Provider<ConnectionRecordSet> connectionRecordSetProvider;
/**
* The manually-set GuacamoleConfiguration, if any.
*/
@@ -257,6 +264,14 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
return connectionService.retrieveHistory(getCurrentUser(), this);
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
ConnectionRecordSet connectionRecordSet = connectionRecordSetProvider.get();
connectionRecordSet.init(getCurrentUser(), this.getIdentifier());
return connectionRecordSet;
}
@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info,

View File

@@ -26,10 +26,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
import org.apache.guacamole.auth.jdbc.sharing.connectiongroup.SharedRootConnectionGroup;
import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.apache.guacamole.auth.jdbc.user.RemoteAuthenticatedUser;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.protocol.GuacamoleClientInformation;
@@ -157,6 +159,12 @@ public class SharedConnection implements Connection {
throws GuacamoleException {
return Collections.<ConnectionRecord>emptyList();
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("SharedConnection objects do not provide history.");
}
@Override
public Set<String> getSharingProfileIdentifiers()

View File

@@ -24,8 +24,10 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
import org.apache.guacamole.auth.jdbc.sharing.permission.SharedObjectPermissionSet;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup;
@@ -106,6 +108,12 @@ public class SharedUser implements User {
return Collections.<ActivityRecord>emptyList();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("SharedUser objects do not provide login history.");
}
@Override
public String getPassword() {

View File

@@ -47,6 +47,7 @@ import org.apache.guacamole.form.TextField;
import org.apache.guacamole.form.TimeField;
import org.apache.guacamole.form.TimeZoneField;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.Permissions;
import org.apache.guacamole.net.auth.RelatedObjectSet;
import org.apache.guacamole.net.auth.User;
@@ -182,6 +183,12 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
*/
@Inject
private Provider<UserParentUserGroupSet> parentUserGroupSetProvider;
/**
* Provider for creating user record sets.
*/
@Inject
private Provider<UserRecordSet> userRecordSetProvider;
/**
* Whether attributes which control access restrictions should be exposed
@@ -751,6 +758,14 @@ public class ModeledUser extends ModeledPermissions<UserModel> implements User {
public List<ActivityRecord> getHistory() throws GuacamoleException {
return userService.retrieveHistory(getCurrentUser(), this);
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
UserRecordSet userRecordSet = userRecordSetProvider.get();
userRecordSet.init(getCurrentUser(), this.getIdentifier());
return userRecordSet;
}
@Override
public RelatedObjectSet getUserGroups() throws GuacamoleException {

View File

@@ -44,6 +44,13 @@ public class UserRecordSet extends ModeledActivityRecordSet<ActivityRecord> {
@Inject
private UserService userService;
private String identifier = null;
protected void init(ModeledAuthenticatedUser currentUser, String identifier) {
super.init(currentUser);
this.identifier = identifier;
}
@Override
protected Collection<ActivityRecord> retrieveHistory(
AuthenticatedUser user, Set<ActivityRecordSearchTerm> requiredContents,
@@ -51,7 +58,7 @@ public class UserRecordSet extends ModeledActivityRecordSet<ActivityRecord> {
throws GuacamoleException {
// Retrieve history from database
return userService.retrieveHistory(getCurrentUser(),
return userService.retrieveHistory(identifier, getCurrentUser(),
requiredContents, sortPredicates, limit);
}