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 441940cf7..20861bae9 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 @@ -259,12 +259,6 @@ public class ModeledConnection extends ModeledChildDirectoryObject getHistory() throws GuacamoleException { - return connectionService.retrieveHistory(getCurrentUser(), this); - } @Override public ActivityRecordSet getConnectionHistory() diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/connection/SharedConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/connection/SharedConnection.java index 81a0d5d03..48a0cbdc6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/connection/SharedConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/connection/SharedConnection.java @@ -22,18 +22,14 @@ package org.apache.guacamole.auth.jdbc.sharing.connection; import com.google.inject.Inject; import java.util.Collections; import java.util.Date; -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; import org.apache.guacamole.protocol.GuacamoleConfiguration; @@ -154,19 +150,6 @@ public class SharedConnection implements Connection { return null; } - @Deprecated - @Override - public List getHistory() - throws GuacamoleException { - throw new GuacamoleUnsupportedException("SharedConnection objects do not provide history."); - } - - @Override - public ActivityRecordSet getConnectionHistory() - throws GuacamoleException { - throw new GuacamoleUnsupportedException("SharedConnection objects do not provide history."); - } - @Override public Set getSharingProfileIdentifiers() throws GuacamoleException { diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java index 735642d92..80d22198c 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/sharing/user/SharedUser.java @@ -21,13 +21,9 @@ package org.apache.guacamole.auth.jdbc.sharing.user; 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.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; @@ -101,18 +97,6 @@ public class SharedUser implements User { } - @Deprecated - @Override - public List getHistory() throws GuacamoleException { - throw new GuacamoleUnsupportedException("SharedUser objects do not provide login history."); - } - - @Override - public ActivityRecordSet getUserHistory() - throws GuacamoleException { - throw new GuacamoleUnsupportedException("SharedUser objects do not provide login history."); - } - @Override public String getPassword() { return null; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java index edbe12a52..fe04cec19 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/ModeledUser.java @@ -754,12 +754,6 @@ public class ModeledUser extends ModeledPermissions implements User { return getModel().getLastActive(); } - @Deprecated - @Override - public List getHistory() throws GuacamoleException { - return userService.retrieveHistory(getCurrentUser(), this); - } - @Override public ActivityRecordSet getUserHistory() throws GuacamoleException { diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AbstractUser.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AbstractUser.java index aad3bc57d..f4e85ae6f 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AbstractUser.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/AbstractUser.java @@ -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} - * - *

This implementation simply an immutable, empty list. Implementations - * that wish to expose user login history should override this function. - */ - @Deprecated - @Override - public List getHistory() throws GuacamoleException { - return Collections.emptyList(); - } - @Override - public ActivityRecordSet getUserHistory() - throws GuacamoleException { - return new SimpleActivityRecordSet<>(); - } - /** * {@inheritDoc} * diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/Connection.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/Connection.java index 2824f248f..3d8e64d64 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/Connection.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/Connection.java @@ -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 getHistory() throws GuacamoleException; + default List 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 getConnectionHistory() - throws GuacamoleException; + default ActivityRecordSet 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 diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/User.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/User.java index 175985f96..788e8d674 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/User.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/User.java @@ -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 getHistory() throws GuacamoleException; + default List 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 getUserHistory() - throws GuacamoleException; + default ActivityRecordSet 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. diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java index a9a3c3eed..21aca5737 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleActivityRecordSet.java @@ -35,10 +35,34 @@ import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty; public class SimpleActivityRecordSet implements ActivityRecordSet { + /** + * The records associated with this record set, if any. + */ + private final Collection 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 records) { + this.records = Collections.unmodifiableCollection(records); + } + @Override public Collection asCollection() throws GuacamoleException { - return Collections.emptyList(); + return records; } @Override diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java index 7c388e102..ba61f7a7c 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/auth/simple/SimpleConnection.java @@ -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 getHistory() throws GuacamoleException { - return Collections.emptyList(); - } @Override public ActivityRecordSet getConnectionHistory() diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/connection/APIConnectionWrapper.java b/guacamole/src/main/java/org/apache/guacamole/rest/connection/APIConnectionWrapper.java index 9ddcd6e52..6b407b450 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/connection/APIConnectionWrapper.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/connection/APIConnectionWrapper.java @@ -19,17 +19,13 @@ package org.apache.guacamole.rest.connection; -import java.util.Collections; import java.util.Date; -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.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; import org.apache.guacamole.protocol.GuacamoleConfiguration; @@ -139,19 +135,5 @@ public class APIConnectionWrapper implements Connection { public Date getLastActive() { return null; } - - @Deprecated - @Override - public List getHistory() throws GuacamoleException { - throw new GuacamoleUnsupportedException("APIConnectionWrapper does not " - + "support retrieving connection history."); - } - - @Override - public ActivityRecordSet getConnectionHistory() - throws GuacamoleException { - throw new GuacamoleUnsupportedException("APIConnectionWrapper does not " - + "support retrieving connection history."); - } } 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 a5a21727a..7d4f0d552 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 @@ -30,6 +30,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleSecurityException; +import org.apache.guacamole.GuacamoleUnsupportedException; import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.Permissions; @@ -40,6 +41,7 @@ import org.apache.guacamole.net.auth.permission.ObjectPermission; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.SystemPermission; import org.apache.guacamole.net.auth.permission.SystemPermissionSet; +import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet; import org.apache.guacamole.protocol.GuacamoleConfiguration; import org.apache.guacamole.rest.directory.DirectoryObjectResource; import org.apache.guacamole.rest.directory.DirectoryObjectTranslator; @@ -47,6 +49,8 @@ import org.apache.guacamole.rest.directory.DirectoryResource; import org.apache.guacamole.rest.directory.DirectoryResourceFactory; import org.apache.guacamole.rest.history.ConnectionHistoryResource; import org.apache.guacamole.rest.sharingprofile.APISharingProfile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A REST resource which abstracts the operations available on an existing @@ -56,6 +60,11 @@ import org.apache.guacamole.rest.sharingprofile.APISharingProfile; @Consumes(MediaType.APPLICATION_JSON) public class ConnectionResource extends DirectoryObjectResource { + /** + * Logger for this class. + */ + private static final Logger logger = LoggerFactory.getLogger(ConnectionResource.class); + /** * The UserContext associated with the Directory which contains the * Connection exposed by this resource. @@ -147,11 +156,29 @@ public class ConnectionResource extends DirectoryObjectResource(connection.getHistory())); + } + catch (GuacamoleUnsupportedException e) { + logger.debug("Call to getHistory() is unsupported, no connection history records will be returned.", e); + } + + // If all fails, return an empty connection history set. + return new ConnectionHistoryResource(new SimpleActivityRecordSet<>()); } diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java index 8da835580..704988cbf 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/history/HistoryResource.java @@ -24,7 +24,9 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.GuacamoleUnsupportedException; import org.apache.guacamole.net.auth.UserContext; +import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet; /** * A REST resource for retrieving and managing the history records of Guacamole @@ -64,7 +66,12 @@ public class HistoryResource { */ @Path("connections") public ConnectionHistoryResource getConnectionHistory() throws GuacamoleException { - return new ConnectionHistoryResource(userContext.getConnectionHistory()); + try { + return new ConnectionHistoryResource(userContext.getConnectionHistory()); + } + catch (GuacamoleUnsupportedException e) { + return new ConnectionHistoryResource(new SimpleActivityRecordSet<>()); + } } /** @@ -81,7 +88,12 @@ public class HistoryResource { */ @Path("users") public UserHistoryResource getUserHistory() throws GuacamoleException { - return new UserHistoryResource(userContext.getUserHistory()); + try { + return new UserHistoryResource(userContext.getUserHistory()); + } + catch (GuacamoleUnsupportedException e) { + return new UserHistoryResource(new SimpleActivityRecordSet<>()); + } } } diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java index e9f6b473b..b086314f6 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/APIUserWrapper.java @@ -19,14 +19,10 @@ package org.apache.guacamole.rest.user; -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.GuacamoleUnsupportedException; -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; @@ -140,16 +136,4 @@ public class APIUserWrapper implements User { return null; } - @Deprecated - @Override - public List getHistory() throws GuacamoleException { - throw new GuacamoleUnsupportedException("APIUserWrapper does not provide login history."); - } - - @Override - public ActivityRecordSet getUserHistory() - throws GuacamoleException { - throw new GuacamoleUnsupportedException("APIUserWrapper does not provide login history."); - } - } diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java index 1ed17fc38..f31ce5dc8 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java @@ -21,8 +21,6 @@ package org.apache.guacamole.rest.user; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; -import java.util.ArrayList; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -33,18 +31,22 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleSecurityException; +import org.apache.guacamole.GuacamoleUnsupportedException; import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.Credentials; import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.credentials.GuacamoleCredentialsException; +import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet; import org.apache.guacamole.rest.directory.DirectoryObjectResource; import org.apache.guacamole.rest.directory.DirectoryObjectTranslator; import org.apache.guacamole.rest.history.UserHistoryResource; import org.apache.guacamole.rest.identifier.RelatedObjectSetResource; import org.apache.guacamole.rest.permission.APIPermissionSet; import org.apache.guacamole.rest.permission.PermissionSetResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A REST resource which abstracts the operations available on an existing @@ -55,6 +57,11 @@ import org.apache.guacamole.rest.permission.PermissionSetResource; public class UserResource extends DirectoryObjectResource { + /** + * Logger for this class. + */ + private static final Logger logger = LoggerFactory.getLogger(UserResource.class); + /** * The UserContext associated with the Directory which contains the User * exposed by this resource. @@ -109,11 +116,29 @@ public class UserResource * @throws GuacamoleException * If an error occurs while retrieving the user history. */ + @SuppressWarnings("deprecation") @Path("history") public UserHistoryResource getUserHistory() throws GuacamoleException { - return new UserHistoryResource(user.getUserHistory()); + // First try to retrieve history using the current getUserHistory() method. + try { + return new UserHistoryResource(user.getUserHistory()); + } + catch (GuacamoleUnsupportedException e) { + logger.debug("Call to getUserHistory() is unsupported, falling back to deprecated method getHistory().", e); + } + + // Fall back to deprecated getHistory() method. + try { + return new UserHistoryResource(new SimpleActivityRecordSet<>(user.getHistory())); + } + catch (GuacamoleUnsupportedException e) { + logger.debug("Call to getHistory() is unsupported, no user history records will be returned.", e); + } + + // If both are unimplemented, return an empty history set. + return new UserHistoryResource(new SimpleActivityRecordSet<>()); }