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

@@ -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<? extends ConnectionRecord> getHistory() throws GuacamoleException {
throw new GuacamoleUnsupportedException("APIConnectionWrapper does not "
+ "support retrieving connection history.");
}
@Override
public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("APIConnectionWrapper does not "
+ "support retrieving connection history.");
}
}

View File

@@ -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<Connection, APIConnection> {
/**
* 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, APIC
* @throws GuacamoleException
* If an error occurs while retrieving the connection history.
*/
@SuppressWarnings("deprecation")
@Path("history")
public ConnectionHistoryResource getConnectionHistory()
throws GuacamoleException {
return new ConnectionHistoryResource(connection.getConnectionHistory());
// Try the current getConnectionHistory() method, first, for connection history.
try {
return new ConnectionHistoryResource(connection.getConnectionHistory());
}
catch (GuacamoleUnsupportedException e) {
logger.debug("Call to getConnectionHistory() is unsupported, falling back to getHistory().", e);
}
// Fall back to the deprecated getHistory() method.
try {
return new ConnectionHistoryResource(new SimpleActivityRecordSet<>(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<>());
}

View File

@@ -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<>());
}
}
}

View File

@@ -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<? extends ActivityRecord> getHistory() throws GuacamoleException {
throw new GuacamoleUnsupportedException("APIUserWrapper does not provide login history.");
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
throw new GuacamoleUnsupportedException("APIUserWrapper does not provide login history.");
}
}

View File

@@ -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<User, APIUser> {
/**
* 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<>());
}