GUACAMOLE-1123: Merge standardization on ActivityRecordSet for history retrieval.

This commit is contained in:
Mike Jumper
2020-10-30 11:27:04 -07:00
committed by GitHub
29 changed files with 765 additions and 407 deletions

View File

@@ -21,7 +21,6 @@ package org.apache.guacamole.net.auth;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
@@ -85,18 +84,7 @@ public abstract class AbstractUser extends AbstractIdentifiable
public Date getLastActive() {
return null;
}
/**
* {@inheritDoc}
*
* <p>This implementation simply an immutable, empty list. Implementations
* that wish to expose user login history should override this function.
*/
@Override
public List<ActivityRecord> getHistory() throws GuacamoleException {
return Collections.emptyList();
}
/**
* {@inheritDoc}
*

View File

@@ -19,10 +19,13 @@
package org.apache.guacamole.net.auth;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
/**
@@ -98,17 +101,56 @@ public interface Connection extends Identifiable, Connectable, Attributes {
* of this Connection, including any active users. ConnectionRecords
* in this list will be sorted in descending order of end time (active
* connections are first), and then in descending order of start time
* (newer connections are first).
* (newer connections are first). If connection history tracking is
* not implemented this method should throw GuacamoleUnsupportedException.
*
* @return A list of ConnectionRecrods representing the usage history
* of this Connection.
* @deprecated
* This function has been deprecated in favor of
* {@link getConnectionHistory}, which returns the connection history
* as an ActivityRecordSet that can be easily sorted and filtered.
* While the getHistory() method is provided for API compatibility,
* new implementations should avoid use of this method and, instead,
* implement the getConnectionHistory() method.
*
* @return
* A list of ConnectionRecrods representing the usage history of this
* Connection.
*
* @throws GuacamoleException If an error occurs while reading the history
* of this connection, or if permission is
* denied.
* @throws GuacamoleException
* If history tracking is not implemented, if an error occurs while
* reading the history of this connection, or if permission is
* denied.
*/
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException;
@Deprecated
default List<? extends ConnectionRecord> getHistory()
throws GuacamoleException {
return Collections.unmodifiableList(new ArrayList<>(getConnectionHistory().asCollection()));
}
/**
* Returns an ActivityRecordSet containing ConnectionRecords that
* represent the usage history of this Connection, including any active
* users. ConnectionRecords in this list will be sorted in descending order
* of end time (active connections are first), and then in descending order
* of start time (newer connections are first). If connection history
* tracking has not been implemented, or has been implemented using the
* deprecated {@link getHistory} method, this function should throw
* GuacamoleUnsupportedExpcetion.
*
* @return
* An ActivityRecordSet containing ConnectionRecords representing the
* usage history of this Connection.
*
* @throws GuacamoleException
* If history tracking is not implemented, if an error occurs while
* reading the history of this connection, or if permission is
* denied.
*/
default ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("This implementation of Connection does not provide connection history.");
}
/**
* Returns identifiers of all readable sharing profiles that can be used to
* join this connection when it is active. The level of access granted to a

View File

@@ -134,11 +134,18 @@ public class DelegatingConnection implements Connection {
return connection.getLastActive();
}
@Deprecated
@Override
public List<? extends ConnectionRecord> getHistory()
throws GuacamoleException {
return connection.getHistory();
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
return connection.getConnectionHistory();
}
@Override
public Set<String> getSharingProfileIdentifiers()

View File

@@ -93,11 +93,18 @@ public class DelegatingUser implements User {
return user.getLastActive();
}
@Deprecated
@Override
public List<? extends ActivityRecord> getHistory()
throws GuacamoleException {
return user.getHistory();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return user.getUserHistory();
}
@Override
public SystemPermissionSet getSystemPermissions()

View File

@@ -19,9 +19,12 @@
package org.apache.guacamole.net.auth;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException;
/**
* A user of the Guacamole web application.
@@ -93,17 +96,50 @@ public interface User extends Identifiable, Attributes, Permissions {
* of this user, including any active sessions. ActivityRecords
* in this list will be sorted in descending order of end time (active
* sessions are first), and then in descending order of start time
* (newer sessions are first).
* (newer sessions are first). If user login history is not implemented
* this method should throw GuacamoleUnsupportedException.
*
* @deprecated
* This function is deprecated in favor of {@link getUserHistory}, which
* returns the login history as an ActivityRecordSet which supports
* various sort and filter functions. While this continues to be defined
* for API compatibility, new implementation should avoid this function
* and use getUserHistory(), instead.
*
* @return
* A list of ActivityRecords representing the login history of this
* User.
*
* @throws GuacamoleException
* If an error occurs while reading the history of this user, or if
* permission is denied.
* If history tracking is not implemented, if an error occurs while
* reading the history of this user, or if permission is denied.
*/
List<? extends ActivityRecord> getHistory() throws GuacamoleException;
@Deprecated
default List<? extends ActivityRecord> getHistory() throws GuacamoleException {
return Collections.unmodifiableList(new ArrayList<>(getUserHistory().asCollection()));
}
/**
* Returns an ActivityRecordSet containing ActivityRecords representing
* the login history for this user, including any active sessions.
* ActivityRecords in this list will be sorted in descending order of end
* time (active sessions are first), and then in descending order of start
* time (newer sessions are first). If login history tracking is not
* implemented, or is only implemented using the deprecated {@link getHistory}
* method, this method should throw GuacamoleUnsupportedException.
*
* @return
* An ActivityRecordSet containing ActivityRecords representing the
* login history for this user.
*
* @throws GuacamoleException
* If history tracking is not implemented, if an error occurs while
* reading the history of this user, or if permission is denied.
*/
default ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("The default implementation of User does not provide login history.");
}
/**
* Returns a set of all readable user groups of which this user is a member.

View File

@@ -35,10 +35,34 @@ import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty;
public class SimpleActivityRecordSet<RecordType extends ActivityRecord>
implements ActivityRecordSet<RecordType> {
/**
* The records associated with this record set, if any.
*/
private final Collection<RecordType> records;
/**
* Create a new SimpleActivityRecordSet that contains an empty set of
* records.
*/
public SimpleActivityRecordSet() {
records = Collections.emptyList();
}
/**
* Create a new SimpleActivityRecordSet that contains the provided records
* which will back this record set.
*
* @param records
* The records that this SimpleActivityRecordSet should contain.
*/
public SimpleActivityRecordSet(Collection<? extends RecordType> records) {
this.records = Collections.unmodifiableCollection(records);
}
@Override
public Collection<RecordType> asCollection()
throws GuacamoleException {
return Collections.<RecordType>emptyList();
return records;
}
@Override

View File

@@ -21,7 +21,6 @@ package org.apache.guacamole.net.auth.simple;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
@@ -33,6 +32,7 @@ import org.apache.guacamole.net.InetGuacamoleSocket;
import org.apache.guacamole.net.SSLGuacamoleSocket;
import org.apache.guacamole.net.SimpleGuacamoleTunnel;
import org.apache.guacamole.net.auth.AbstractConnection;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.GuacamoleProxyConfiguration;
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
@@ -283,10 +283,11 @@ public class SimpleConnection extends AbstractConnection {
public Date getLastActive() {
return null;
}
@Override
public List<ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.<ConnectionRecord>emptyList();
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<>();
}
}