GUACAMOLE-1123: Provide default interface implementations for history methods.

This commit is contained in:
Virtually Nick
2020-10-27 15:14:32 -04:00
parent 0430d5510a
commit ba060f5534
14 changed files with 139 additions and 134 deletions

View File

@@ -21,12 +21,10 @@ 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;
import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
/**
* Base implementation of User which provides default implementations of
@@ -86,25 +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.
*/
@Deprecated
@Override
public List<ActivityRecord> getHistory() throws GuacamoleException {
return Collections.emptyList();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<>();
}
/**
* {@inheritDoc}
*

View File

@@ -20,10 +20,12 @@
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;
/**
@@ -99,7 +101,8 @@ 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.
*
* @deprecated
* This function has been deprecated in favor of
@@ -109,33 +112,44 @@ public interface Connection extends Identifiable, Connectable, Attributes {
* 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.
* @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.
*/
@Deprecated
List<? extends ConnectionRecord> getHistory() throws GuacamoleException;
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).
* 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 an error occurs retrieving history for this Connection, or if
* permission to retrieve the history is denied.
* If history tracking is not implemented, if an error occurs while
* reading the history of this connection, or if permission is
* denied.
*/
ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException;
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

View File

@@ -20,9 +20,11 @@
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.
@@ -94,7 +96,8 @@ 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
@@ -108,29 +111,35 @@ public interface User extends Identifiable, Attributes, Permissions {
* 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.
*/
@Deprecated
List<? extends ActivityRecord> getHistory() throws GuacamoleException;
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).
* 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 an error occurs retrieving this user's login history, or if
* permission to retrieve login history is denied.
* If history tracking is not implemented, if an error occurs while
* reading the history of this user, or if permission is denied.
*/
ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException;
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;
@@ -284,12 +283,6 @@ public class SimpleConnection extends AbstractConnection {
public Date getLastActive() {
return null;
}
@Deprecated
@Override
public List<ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.<ConnectionRecord>emptyList();
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()