GUACAMOLE-462: Allow individual records to be identified and retrieved directly.

This commit is contained in:
Michael Jumper
2022-02-09 15:33:56 -08:00
parent 6874f9c6bd
commit 449fcb828e
9 changed files with 124 additions and 59 deletions

View File

@@ -96,6 +96,7 @@ public class APIActivityRecord {
this.remoteHost = record.getRemoteHost();
this.username = record.getUsername();
this.active = record.isActive();
this.identifier = record.getIdentifier();
this.uuid = record.getUUID();
this.attributes = record.getAttributes();
@@ -164,6 +165,18 @@ public class APIActivityRecord {
return active;
}
/**
* Returns the unique identifier assigned to this record, if any. If this
* record is not uniquely identifiable, this may be null.
*
* @return
* The unique identifier assigned to this record, or null if this
* record has no such identifier.
*/
public String getIdentifier() {
return identifier;
}
/**
* Returns a UUID that uniquely identifies this record. If not implemented
* by the extension exposing this history record, this may be null.

View File

@@ -19,7 +19,9 @@
package org.apache.guacamole.rest.history;
import java.util.function.Function;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@@ -42,14 +44,37 @@ public class ActivityRecordResource {
*/
private final ActivityRecord record;
/**
* The REST API object representing the ActivityRecord being exposed.
*/
private final APIActivityRecord externalRecord;
/**
* Creates a new ActivityRecordResource which exposes the given record.
*
* @param record
* The ActivityRecord that should be exposed.
*
* @param externalRecord
* The REST API object representing the ActivityRecord being exposed.
*/
public ActivityRecordResource(ActivityRecord record) {
public ActivityRecordResource(ActivityRecord record,
APIActivityRecord externalRecord) {
this.record = record;
this.externalRecord = externalRecord;
}
/**
* Returns the record represented by this ActivityRecordResource, in a
* format intended for interchange.
*
* @return
* The record that this ActivityRecordResource represents, in a format
* intended for interchange.
*/
@GET
public APIActivityRecord getRecord() {
return externalRecord;
}
/**

View File

@@ -21,7 +21,6 @@ package org.apache.guacamole.rest.history;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -29,7 +28,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleResourceNotFoundException;
import org.apache.guacamole.net.auth.ActivityRecord;
@@ -176,70 +174,28 @@ public abstract class ActivityRecordSetResource<InternalRecordType extends Activ
}
/**
* Retrieves record having the given UUID from among the list of activity
* records stored within the underlying ActivityRecordSet which match the
* given, arbitrary criteria. If specified, the returned records will also
* be sorted according to the given sort predicates. As the number of
* activity records retrieved at any given time may be limited by the
* extension providing those records, the sorting and search criteria may
* impact whether the record having a particular UUID can be located, even
* if it is known that the record exists.
* Retrieves record having the given identifier from among the set of
* activity records stored within the underlying ActivityRecordSet.
*
* @param uuid
* The UUID of the record to retrieve.
*
* @param requiredContents
* The set of strings that each must occur somewhere within the
* relevant records, whether within the associated username,
* the name of some associated object (such as a connection), or any
* associated date. If non-empty, any record not matching each of the
* strings within the collection will not be considered.
*
* @param sortPredicates
* A list of predicates to apply while sorting the relevant records,
* describing the properties involved and the sort order for those
* properties.
* @param identifier
* The unique identifier of the record to retrieve.
*
* @return
* The record having the given UUID which matches the provided
* criteria.
* A resource representing the record having the given identifier.
*
* @throws GuacamoleException
* If an error occurs while applying the given filter criteria or
* sort predicates, or if the requested record cannot be found.
* If an error occurs while locating the requested record, or if the
* requested record cannot be found.
*/
@Path("{uuid}")
public ActivityRecordResource getRecord(@PathParam("uuid") String uuid,
@QueryParam("contains") List<String> requiredContents,
@QueryParam("order") List<APISortPredicate> sortPredicates)
throws GuacamoleException {
@Path("{identifier}")
public ActivityRecordResource getRecord(@PathParam("identifier") String identifier)
throws GuacamoleException {
// Parse UUID from provided string
UUID parsedUUID;
try {
parsedUUID = UUID.fromString(uuid);
}
catch (IllegalArgumentException e) {
throw new GuacamoleClientException("Invalid UUID.", e);
}
InternalRecordType record = history.get(identifier);
if (record == null)
throw new GuacamoleResourceNotFoundException("Not found: \"" + identifier + "\"");
// Apply search/sort criteria
applyCriteria(requiredContents, sortPredicates);
// Locate record having given UUID among all visible records
for (InternalRecordType record : history.asCollection()) {
// Ignore records lacking any UUID
UUID recordUUID = record.getUUID();
if (recordUUID == null)
continue;
if (recordUUID.equals(parsedUUID))
return new ActivityRecordResource(record);
}
throw new GuacamoleResourceNotFoundException("No such history entry.");
return new ActivityRecordResource(record, toExternalRecord(record));
}