GUACAMOLE-394: Merge refactor extension API to define user history

This commit is contained in:
Nick Couchman
2017-09-27 18:14:43 -04:00
27 changed files with 504 additions and 194 deletions

View File

@@ -27,15 +27,17 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.base.RestrictedObject; import org.apache.guacamole.auth.jdbc.base.RestrictedObject;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty;
import org.apache.guacamole.net.auth.ConnectionRecord; import org.apache.guacamole.net.auth.ConnectionRecord;
/** /**
* A JDBC implementation of ConnectionRecordSet. Calls to asCollection() will * A JDBC implementation of ActivityRecordSet for ConnectionRecords. Calls to
* query connection history records from the database. Which records are * asCollection() will query connection history records from the database. Which
* returned will be determined by the values passed in earlier. * records are returned will be determined by the values passed in earlier.
*/ */
public class ConnectionRecordSet extends RestrictedObject public class ConnectionRecordSet extends RestrictedObject
implements org.apache.guacamole.net.auth.ConnectionRecordSet { implements ActivityRecordSet<ConnectionRecord> {
/** /**
* Service for managing connection objects. * Service for managing connection objects.

View File

@@ -19,7 +19,7 @@
package org.apache.guacamole.auth.jdbc.connection; package org.apache.guacamole.auth.jdbc.connection;
import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.ActivityRecordSet;
/** /**
* A sort predicate which species the property to use when sorting connection * A sort predicate which species the property to use when sorting connection
@@ -30,7 +30,7 @@ public class ConnectionRecordSortPredicate {
/** /**
* The property to use when sorting ConnectionRecords. * The property to use when sorting ConnectionRecords.
*/ */
private final ConnectionRecordSet.SortableProperty property; private final ActivityRecordSet.SortableProperty property;
/** /**
* Whether the sort order is descending (true) or ascending (false). * Whether the sort order is descending (true) or ascending (false).
@@ -47,7 +47,7 @@ public class ConnectionRecordSortPredicate {
* @param descending * @param descending
* Whether the sort order is descending (true) or ascending (false). * Whether the sort order is descending (true) or ascending (false).
*/ */
public ConnectionRecordSortPredicate(ConnectionRecordSet.SortableProperty property, public ConnectionRecordSortPredicate(ActivityRecordSet.SortableProperty property,
boolean descending) { boolean descending) {
this.property = property; this.property = property;
this.descending = descending; this.descending = descending;
@@ -59,7 +59,7 @@ public class ConnectionRecordSortPredicate {
* @return * @return
* The property that should be used when sorting ConnectionRecords. * The property that should be used when sorting ConnectionRecords.
*/ */
public ConnectionRecordSet.SortableProperty getProperty() { public ActivityRecordSet.SortableProperty getProperty() {
return property; return property;
} }

View File

@@ -24,6 +24,7 @@ import com.google.inject.Provider;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -232,6 +233,11 @@ public class ModeledConnection extends ModeledChildDirectoryObject<ConnectionMod
return getModel().getSharingProfileIdentifiers(); return getModel().getSharingProfileIdentifiers();
} }
@Override
public Date getLastActive() {
return null;
}
@Override @Override
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException { public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
return connectionService.retrieveHistory(getCurrentUser(), this); return connectionService.retrieveHistory(getCurrentUser(), this);

View File

@@ -21,6 +21,7 @@ package org.apache.guacamole.auth.jdbc.sharing.connection;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -146,6 +147,11 @@ public class SharedConnection implements Connection {
// Do nothing - changing attributes not supported // Do nothing - changing attributes not supported
} }
@Override
public Date getLastActive() {
return null;
}
@Override @Override
public List<? extends ConnectionRecord> getHistory() public List<? extends ConnectionRecord> getHistory()
throws GuacamoleException { throws GuacamoleException {

View File

@@ -20,9 +20,12 @@
package org.apache.guacamole.auth.jdbc.sharing.user; package org.apache.guacamole.auth.jdbc.sharing.user;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.sharing.permission.SharedObjectPermissionSet; import org.apache.guacamole.auth.jdbc.sharing.permission.SharedObjectPermissionSet;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.AuthenticatedUser; import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
@@ -88,6 +91,22 @@ public class SharedUser implements User {
// Do nothing - no attributes supported // Do nothing - no attributes supported
} }
@Override
public Date getLastActive() {
// History is not recorded for shared users
return null;
}
@Override
public List<ActivityRecord> getHistory() throws GuacamoleException {
// History is not recorded for shared users
return Collections.<ActivityRecord>emptyList();
}
@Override @Override
public String getPassword() { public String getPassword() {
return null; return null;

View File

@@ -28,16 +28,18 @@ import org.apache.guacamole.auth.jdbc.sharing.connectiongroup.SharedRootConnecti
import org.apache.guacamole.auth.jdbc.user.RemoteAuthenticatedUser; import org.apache.guacamole.auth.jdbc.user.RemoteAuthenticatedUser;
import org.apache.guacamole.form.Form; import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory; import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory;
import org.apache.guacamole.net.auth.simple.SimpleConnectionRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleDirectory; import org.apache.guacamole.net.auth.simple.SimpleDirectory;
/** /**
@@ -175,8 +177,14 @@ public class SharedUserContext implements UserContext {
} }
@Override @Override
public ConnectionRecordSet getConnectionHistory() { public ActivityRecordSet<ConnectionRecord> getConnectionHistory() {
return new SimpleConnectionRecordSet(); return new SimpleActivityRecordSet<ConnectionRecord>();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ActivityRecord>();
} }
@Override @Override

View File

@@ -29,6 +29,7 @@ import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObject; import org.apache.guacamole.auth.jdbc.base.ModeledDirectoryObject;
@@ -49,6 +50,7 @@ import org.apache.guacamole.form.Form;
import org.apache.guacamole.form.TextField; import org.apache.guacamole.form.TextField;
import org.apache.guacamole.form.TimeField; import org.apache.guacamole.form.TimeField;
import org.apache.guacamole.form.TimeZoneField; import org.apache.guacamole.form.TimeZoneField;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
import org.apache.guacamole.net.auth.permission.SystemPermission; import org.apache.guacamole.net.auth.permission.SystemPermission;
@@ -792,4 +794,14 @@ public class ModeledUser extends ModeledDirectoryObject<UserModel> implements Us
return getModel().isExpired(); return getModel().isExpired();
} }
@Override
public Date getLastActive() {
return null;
}
@Override
public List<ActivityRecord> getHistory() throws GuacamoleException {
return Collections.<ActivityRecord>emptyList();
}
} }

View File

@@ -36,12 +36,15 @@ import org.apache.guacamole.auth.jdbc.sharingprofile.ModeledSharingProfile;
import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileDirectory; import org.apache.guacamole.auth.jdbc.sharingprofile.SharingProfileDirectory;
import org.apache.guacamole.form.Form; import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
/** /**
* UserContext implementation which is driven by an arbitrary, underlying * UserContext implementation which is driven by an arbitrary, underlying
@@ -161,6 +164,12 @@ public class ModeledUserContext extends RestrictedObject
return connectionRecordSet; return connectionRecordSet;
} }
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ActivityRecord>();
}
@Override @Override
public ConnectionGroup getRootConnectionGroup() throws GuacamoleException { public ConnectionGroup getRootConnectionGroup() throws GuacamoleException {

View File

@@ -129,7 +129,7 @@
</foreach> </foreach>
<!-- Bind sort property enum values for sake of readability --> <!-- Bind sort property enum values for sake of readability -->
<bind name="START_DATE" value="@org.apache.guacamole.net.auth.ConnectionRecordSet$SortableProperty@START_DATE"/> <bind name="START_DATE" value="@org.apache.guacamole.net.auth.ActivityRecordSet$SortableProperty@START_DATE"/>
<!-- Sort predicates --> <!-- Sort predicates -->
<foreach collection="sortPredicates" item="sortPredicate" <foreach collection="sortPredicates" item="sortPredicate"
@@ -199,7 +199,7 @@
</foreach> </foreach>
<!-- Bind sort property enum values for sake of readability --> <!-- Bind sort property enum values for sake of readability -->
<bind name="START_DATE" value="@org.apache.guacamole.net.auth.ConnectionRecordSet$SortableProperty@START_DATE"/> <bind name="START_DATE" value="@org.apache.guacamole.net.auth.ActivityRecordSet$SortableProperty@START_DATE"/>
<!-- Sort predicates --> <!-- Sort predicates -->
<foreach collection="sortPredicates" item="sortPredicate" <foreach collection="sortPredicates" item="sortPredicate"

View File

@@ -127,7 +127,7 @@
</foreach> </foreach>
<!-- Bind sort property enum values for sake of readability --> <!-- Bind sort property enum values for sake of readability -->
<bind name="START_DATE" value="@org.apache.guacamole.net.auth.ConnectionRecordSet$SortableProperty@START_DATE"/> <bind name="START_DATE" value="@org.apache.guacamole.net.auth.ActivityRecordSet$SortableProperty@START_DATE"/>
<!-- Sort predicates --> <!-- Sort predicates -->
<foreach collection="sortPredicates" item="sortPredicate" <foreach collection="sortPredicates" item="sortPredicate"
@@ -197,7 +197,7 @@
</foreach> </foreach>
<!-- Bind sort property enum values for sake of readability --> <!-- Bind sort property enum values for sake of readability -->
<bind name="START_DATE" value="@org.apache.guacamole.net.auth.ConnectionRecordSet$SortableProperty@START_DATE"/> <bind name="START_DATE" value="@org.apache.guacamole.net.auth.ActivityRecordSet$SortableProperty@START_DATE"/>
<!-- Sort predicates --> <!-- Sort predicates -->
<foreach collection="sortPredicates" item="sortPredicate" <foreach collection="sortPredicates" item="sortPredicate"

View File

@@ -28,17 +28,19 @@ import org.apache.guacamole.auth.ldap.connection.ConnectionService;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.form.Form; import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
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.AuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.simple.SimpleActivityRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroup; import org.apache.guacamole.net.auth.simple.SimpleConnectionGroup;
import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory; import org.apache.guacamole.net.auth.simple.SimpleConnectionGroupDirectory;
import org.apache.guacamole.net.auth.simple.SimpleConnectionRecordSet;
import org.apache.guacamole.net.auth.simple.SimpleDirectory; import org.apache.guacamole.net.auth.simple.SimpleDirectory;
import org.apache.guacamole.net.auth.simple.SimpleUser; import org.apache.guacamole.net.auth.simple.SimpleUser;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -204,9 +206,15 @@ public class UserContext implements org.apache.guacamole.net.auth.UserContext {
} }
@Override @Override
public ConnectionRecordSet getConnectionHistory() public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException { throws GuacamoleException {
return new SimpleConnectionRecordSet(); return new SimpleActivityRecordSet<ConnectionRecord>();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ActivityRecord>();
} }
@Override @Override

View File

@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.guacamole.net.auth;
import java.util.Date;
/**
* A logging record describing when a user started and ended a particular
* activity.
*/
public interface ActivityRecord {
/**
* Returns the date and time the activity began.
*
* @return
* The date and time the activity began.
*/
public Date getStartDate();
/**
* Returns the date and time the activity ended, if applicable.
*
* @return
* The date and time the activity ended, or null if the activity is
* still ongoing or if the end time is unknown.
*/
public Date getEndDate();
/**
* Returns the hostname or IP address of the remote host that performed the
* activity associated with this record, if known. If the hostname or IP
* address is not known, null is returned.
*
* @return
* The hostname or IP address of the remote host, or null if this
* information is not available.
*/
public String getRemoteHost();
/**
* Returns the name of the user who performed or is performing the activity
* at the times given by this record.
*
* @return
* The name of the user who performed or is performing the associated
* activity.
*/
public String getUsername();
/**
* Returns whether the activity associated with this record is still
* ongoing.
*
* @return
* true if the activity associated with this record is still ongoing,
* false otherwise.
*/
public boolean isActive();
}

View File

@@ -0,0 +1,128 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.guacamole.net.auth;
import java.util.Collection;
import org.apache.guacamole.GuacamoleException;
/**
* A set of all available records related to a type of activity which has a
* defined start and end time, such as a user being logged in or connected, or a
* subset of those records.
*
* @param <RecordType>
* The type of ActivityRecord contained within this set.
*/
public interface ActivityRecordSet<RecordType extends ActivityRecord> {
/**
* All properties of activity records which can be used as sorting
* criteria.
*/
enum SortableProperty {
/**
* The date and time when the activity associated with the record
* began.
*/
START_DATE
};
/**
* Returns all records within this set as a standard Collection.
*
* @return
* A collection containing all records within this set.
*
* @throws GuacamoleException
* If an error occurs while retrieving the records within this set.
*/
Collection<RecordType> asCollection() throws GuacamoleException;
/**
* Returns the subset of records which contain the given value. The
* properties and semantics involved with determining whether a particular
* record "contains" the given value is implementation dependent. This
* function may affect the contents of the current ActivityRecordSet. The
* contents of the current ActivityRecordSet should NOT be relied upon
* after this function is called.
*
* @param value
* The value which all records within the resulting subset should
* contain.
*
* @return
* The subset of records which contain the specified value.
*
* @throws GuacamoleException
* If an error occurs while restricting the current subset.
*/
ActivityRecordSet<RecordType> contains(String value)
throws GuacamoleException;
/**
* Returns the subset of records containing only the first
* <code>limit</code> records. If the subset has fewer than
* <code>limit</code> records, then this function has no effect. This
* function may also affect the contents of the current ActivityRecordSet.
* The contents of the current ActivityRecordSet should NOT be relied upon
* after this function is called.
*
* @param limit
* The maximum number of records that the new subset should contain.
*
* @return
* The subset of records that containing only the first
* <code>limit</code> records.
*
* @throws GuacamoleException
* If an error occurs while limiting the current subset.
*/
ActivityRecordSet<RecordType> limit(int limit) throws GuacamoleException;
/**
* Returns a ActivityRecordSet containing identically the records within
* this set, sorted according to the specified criteria. The sort operation
* performed is guaranteed to be stable with respect to any past call to
* sort(). This function may also affect the contents of the current
* ActivityRecordSet. The contents of the current ActivityRecordSet
* should NOT be relied upon after this function is called.
*
* @param property
* The property by which the records within the resulting set should be
* sorted.
*
* @param desc
* Whether the records should be sorted according to the specified
* property in descending order. If false, records will be sorted
* according to the specified property in ascending order.
*
* @return
* The ActivityRecordSet, sorted according to the specified criteria.
*
* @throws GuacamoleException
* If an error occurs while sorting the current subset, or if the given
* property is not supported by the implementation.
*/
ActivityRecordSet<RecordType> sort(SortableProperty property, boolean desc)
throws GuacamoleException;
}

View File

@@ -19,6 +19,7 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -102,6 +103,18 @@ public interface Connection extends Identifiable, Connectable {
*/ */
void setAttributes(Map<String, String> attributes); void setAttributes(Map<String, String> attributes);
/**
* Returns the date and time that this connection was last used. If the
* connection was never used, the time that the connection was last used is
* unknown, or this information is not visible to the current user, this
* may be null.
*
* @return
* The date and time this connection was last used, or null if this
* information is unavailable or inapplicable.
*/
Date getLastActive();
/** /**
* Returns a list of ConnectionRecords representing the usage history * Returns a list of ConnectionRecords representing the usage history
* of this Connection, including any active users. ConnectionRecords * of this Connection, including any active users. ConnectionRecords

View File

@@ -19,13 +19,11 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Date;
/** /**
* A logging record describing when a user started and ended usage of a * A logging record describing when a user started and ended usage of a
* particular connection. * particular connection.
*/ */
public interface ConnectionRecord { public interface ConnectionRecord extends ActivityRecord {
/** /**
* Returns the identifier of the connection associated with this * Returns the identifier of the connection associated with this
@@ -72,48 +70,4 @@ public interface ConnectionRecord {
*/ */
public String getSharingProfileName(); public String getSharingProfileName();
/**
* Returns the date and time the connection began.
*
* @return The date and time the connection began.
*/
public Date getStartDate();
/**
* Returns the date and time the connection ended, if applicable.
*
* @return The date and time the connection ended, or null if the
* connection is still running or if the end time is unknown.
*/
public Date getEndDate();
/**
* Returns the hostname or IP address of the remote host that used the
* connection associated with this record, if known. If the hostname or IP
* address is not known, null is returned.
*
* @return
* The hostname or IP address of the remote host, or null if this
* information is not available.
*/
public String getRemoteHost();
/**
* Returns the name of the user who used or is using the connection at the
* times given by this connection record.
*
* @return The name of the user who used or is using the associated
* connection.
*/
public String getUsername();
/**
* Returns whether the connection associated with this record is still
* active.
*
* @return true if the connection associated with this record is still
* active, false otherwise.
*/
public boolean isActive();
} }

View File

@@ -19,107 +19,13 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Collection;
import org.apache.guacamole.GuacamoleException;
/** /**
* The set of all available connection records, or a subset of those records. * The set of all available connection records, or a subset of those records.
*
* @deprecated
* Use {@link ActivityRecordSet}&lt;{@link ConnectionRecord}&gt; instead.
*/ */
public interface ConnectionRecordSet { @Deprecated
public interface ConnectionRecordSet
/** extends ActivityRecordSet<ConnectionRecord> {
* All properties of connection records which can be used as sorting
* criteria.
*/
enum SortableProperty {
/**
* The date and time when the connection associated with the
* connection record began.
*/
START_DATE
};
/**
* Returns all connection records within this set as a standard Collection.
*
* @return
* A collection containing all connection records within this set.
*
* @throws GuacamoleException
* If an error occurs while retrieving the connection records within
* this set.
*/
Collection<ConnectionRecord> asCollection() throws GuacamoleException;
/**
* Returns the subset of connection records to only those where the
* connection name, user identifier, or any associated date field contain
* the given value. This function may also affect the contents of the
* current ConnectionRecordSet. The contents of the current
* ConnectionRecordSet should NOT be relied upon after this function is
* called.
*
* @param value
* The value which all connection records within the resulting subset
* should contain within their associated connection name or user
* identifier.
*
* @return
* The subset of connection history records which contain the specified
* value within their associated connection name or user identifier.
*
* @throws GuacamoleException
* If an error occurs while restricting the current subset.
*/
ConnectionRecordSet contains(String value) throws GuacamoleException;
/**
* Returns the subset of connection history records containing only the
* first <code>limit</code> records. If the subset has fewer than
* <code>limit</code> records, then this function has no effect. This
* function may also affect the contents of the current
* ConnectionRecordSet. The contents of the current ConnectionRecordSet
* should NOT be relied upon after this function is called.
*
* @param limit
* The maximum number of records that the new subset should contain.
*
* @return
* The subset of connection history records that containing only the
* first <code>limit</code> records.
*
* @throws GuacamoleException
* If an error occurs while limiting the current subset.
*/
ConnectionRecordSet limit(int limit) throws GuacamoleException;
/**
* Returns a ConnectionRecordSet containing identically the records within
* this set, sorted according to the specified criteria. The sort operation
* performed is guaranteed to be stable with respect to any past call to
* sort(). This function may also affect the contents of the current
* ConnectionRecordSet. The contents of the current ConnectionRecordSet
* should NOT be relied upon after this function is called.
*
* @param property
* The property by which the connection records within the resulting
* set should be sorted.
*
* @param desc
* Whether the records should be sorted according to the specified
* property in descending order. If false, records will be sorted
* according to the specified property in ascending order.
*
* @return
* The ConnnectionRecordSet, sorted according to the specified
* criteria.
*
* @throws GuacamoleException
* If an error occurs while sorting the current subset.
*/
ConnectionRecordSet sort(SortableProperty property, boolean desc)
throws GuacamoleException;
} }

View File

@@ -19,6 +19,8 @@
package org.apache.guacamole.net.auth; package org.apache.guacamole.net.auth;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
@@ -100,6 +102,34 @@ public interface User extends Identifiable {
*/ */
void setAttributes(Map<String, String> attributes); void setAttributes(Map<String, String> attributes);
/**
* Returns the date and time that this user was last active. If the user
* was never active, the time that the user was last active is unknown, or
* this information is not visible to the current user, this may be null.
*
* @return
* The date and time this user was last active, or null if this
* information is unavailable or inapplicable.
*/
Date getLastActive();
/**
* Returns a list of ActivityRecords representing the login history
* 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).
*
* @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.
*/
List<? extends ActivityRecord> getHistory() throws GuacamoleException;
/** /**
* Returns all system-level permissions given to this user. * Returns all system-level permissions given to this user.
* *

View File

@@ -143,9 +143,11 @@ public interface UserContext {
throws GuacamoleException; throws GuacamoleException;
/** /**
* Retrieves all connection records visible to current user. The resulting * Retrieves all connection records visible to current user. Connection
* set of connection records can be further filtered and ordered using the * history records describe the start and end times of connections, and
* methods defined on ConnectionRecordSet. * correspond to the times that users connect or disconnect to individual
* remote desktops. The resulting set of connection records can be further
* filtered and ordered using the methods defined on ActivityRecordSet.
* *
* @return * @return
* A set of all connection records visible to the current user. * A set of all connection records visible to the current user.
@@ -153,7 +155,23 @@ public interface UserContext {
* @throws GuacamoleException * @throws GuacamoleException
* If an error occurs while retrieving the connection records. * If an error occurs while retrieving the connection records.
*/ */
ConnectionRecordSet getConnectionHistory() throws GuacamoleException; ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException;
/**
* Retrieves all user history records visible to current user. User history
* records describe the start and end times of user sessions, and correspond
* to the times that users logged in or out. The resulting set of user
* records can be further filtered and ordered using the methods defined on
* ActivityRecordSet.
*
* @return
* A set of all user records visible to the current user.
*
* @throws GuacamoleException
* If an error occurs while retrieving the user records.
*/
ActivityRecordSet<ActivityRecord> getUserHistory() throws GuacamoleException;
/** /**
* Retrieves a connection group which can be used to view and manipulate * Retrieves a connection group which can be used to view and manipulate

View File

@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.guacamole.net.auth.simple;
import java.util.Collection;
import java.util.Collections;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.ActivityRecordSet.SortableProperty;
/**
* An immutable and empty ActivityRecordSet.
*
* @param <RecordType>
* The type of ActivityRecord contained within this set.
*/
public class SimpleActivityRecordSet<RecordType extends ActivityRecord>
implements ActivityRecordSet<RecordType> {
@Override
public Collection<RecordType> asCollection()
throws GuacamoleException {
return Collections.<RecordType>emptyList();
}
@Override
public ActivityRecordSet<RecordType> contains(String value)
throws GuacamoleException {
return this;
}
@Override
public ActivityRecordSet<RecordType> limit(int limit)
throws GuacamoleException {
return this;
}
@Override
public ActivityRecordSet<RecordType> sort(SortableProperty property,
boolean desc) throws GuacamoleException {
return this;
}
}

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.net.auth.simple; package org.apache.guacamole.net.auth.simple;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
@@ -136,6 +137,11 @@ public class SimpleConnection extends AbstractConnection {
} }
@Override
public Date getLastActive() {
return null;
}
@Override @Override
public List<ConnectionRecord> getHistory() throws GuacamoleException { public List<ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.<ConnectionRecord>emptyList(); return Collections.<ConnectionRecord>emptyList();

View File

@@ -23,12 +23,16 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.ConnectionRecord; import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.ConnectionRecordSet;
/** /**
* An immutable and empty ConnectionRecordSet. * An immutable and empty ConnectionRecordSet.
*
* @deprecated
* Use {@link SimpleActivityRecordSet}&lt;{@link ConnectionRecord}&gt;
* instead.
*/ */
public class SimpleConnectionRecordSet implements ConnectionRecordSet { @Deprecated
public class SimpleConnectionRecordSet implements org.apache.guacamole.net.auth.ConnectionRecordSet {
@Override @Override
public Collection<ConnectionRecord> asCollection() public Collection<ConnectionRecord> asCollection()
@@ -37,19 +41,19 @@ public class SimpleConnectionRecordSet implements ConnectionRecordSet {
} }
@Override @Override
public ConnectionRecordSet contains(String value) public org.apache.guacamole.net.auth.ConnectionRecordSet contains(String value)
throws GuacamoleException { throws GuacamoleException {
return this; return this;
} }
@Override @Override
public ConnectionRecordSet limit(int limit) public org.apache.guacamole.net.auth.ConnectionRecordSet limit(int limit)
throws GuacamoleException { throws GuacamoleException {
return this; return this;
} }
@Override @Override
public ConnectionRecordSet sort(SortableProperty property, boolean desc) public org.apache.guacamole.net.auth.ConnectionRecordSet sort(SortableProperty property, boolean desc)
throws GuacamoleException { throws GuacamoleException {
return this; return this;
} }

View File

@@ -21,11 +21,14 @@ package org.apache.guacamole.net.auth.simple;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.AbstractUser; import org.apache.guacamole.net.auth.AbstractUser;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.permission.ObjectPermission; import org.apache.guacamole.net.auth.permission.ObjectPermission;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
import org.apache.guacamole.net.auth.permission.SystemPermissionSet; import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
@@ -163,6 +166,16 @@ public class SimpleUser extends AbstractUser {
// Do nothing - there are no attributes // Do nothing - there are no attributes
} }
@Override
public Date getLastActive() {
return null;
}
@Override
public List<ActivityRecord> getHistory() throws GuacamoleException {
return Collections.<ActivityRecord>emptyList();
}
@Override @Override
public SystemPermissionSet getSystemPermissions() public SystemPermissionSet getSystemPermissions()
throws GuacamoleException { throws GuacamoleException {

View File

@@ -27,10 +27,12 @@ import java.util.UUID;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.form.Form; import org.apache.guacamole.form.Form;
import org.apache.guacamole.net.auth.ActiveConnection; import org.apache.guacamole.net.auth.ActiveConnection;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.Connection; import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup; import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.Directory; import org.apache.guacamole.net.auth.Directory;
import org.apache.guacamole.net.auth.SharingProfile; import org.apache.guacamole.net.auth.SharingProfile;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
@@ -209,9 +211,15 @@ public class SimpleUserContext implements UserContext {
} }
@Override @Override
public ConnectionRecordSet getConnectionHistory() public ActivityRecordSet<ConnectionRecord> getConnectionHistory()
throws GuacamoleException { throws GuacamoleException {
return new SimpleConnectionRecordSet(); return new SimpleActivityRecordSet<ConnectionRecord>();
}
@Override
public ActivityRecordSet<ActivityRecord> getUserHistory()
throws GuacamoleException {
return new SimpleActivityRecordSet<ActivityRecord>();
} }
@Override @Override

View File

@@ -20,6 +20,7 @@
package org.apache.guacamole.rest.connection; package org.apache.guacamole.rest.connection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -131,6 +132,11 @@ public class APIConnectionWrapper implements Connection {
throw new UnsupportedOperationException("Operation not supported."); throw new UnsupportedOperationException("Operation not supported.");
} }
@Override
public Date getLastActive() {
return null;
}
@Override @Override
public List<? extends ConnectionRecord> getHistory() throws GuacamoleException { public List<? extends ConnectionRecord> getHistory() throws GuacamoleException {
return Collections.<ConnectionRecord>emptyList(); return Collections.<ConnectionRecord>emptyList();

View File

@@ -21,7 +21,7 @@ package org.apache.guacamole.rest.history;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.guacamole.GuacamoleClientException; import org.apache.guacamole.GuacamoleClientException;
import org.apache.guacamole.net.auth.ConnectionRecordSet; import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.rest.APIException; import org.apache.guacamole.rest.APIException;
/** /**
@@ -38,7 +38,7 @@ public class APIConnectionRecordSortPredicate {
/** /**
* All possible property name strings and their corresponding * All possible property name strings and their corresponding
* ConnectionRecordSet.SortableProperty values. * ActivityRecordSet.SortableProperty values.
*/ */
public enum SortableProperty { public enum SortableProperty {
@@ -46,24 +46,24 @@ public class APIConnectionRecordSortPredicate {
* The date that the connection associated with the connection record * The date that the connection associated with the connection record
* began (connected). * began (connected).
*/ */
startDate(ConnectionRecordSet.SortableProperty.START_DATE); startDate(ActivityRecordSet.SortableProperty.START_DATE);
/** /**
* The ConnectionRecordSet.SortableProperty that this property name * The ActivityRecordSet.SortableProperty that this property name
* string represents. * string represents.
*/ */
public final ConnectionRecordSet.SortableProperty recordProperty; public final ActivityRecordSet.SortableProperty recordProperty;
/** /**
* Creates a new SortableProperty which associates the property name * Creates a new SortableProperty which associates the property name
* string (identical to its own name) with the given * string (identical to its own name) with the given
* ConnectionRecordSet.SortableProperty value. * ActivityRecordSet.SortableProperty value.
* *
* @param recordProperty * @param recordProperty
* The ConnectionRecordSet.SortableProperty value to associate with * The ActivityRecordSet.SortableProperty value to associate with
* the new SortableProperty. * the new SortableProperty.
*/ */
SortableProperty(ConnectionRecordSet.SortableProperty recordProperty) { SortableProperty(ActivityRecordSet.SortableProperty recordProperty) {
this.recordProperty = recordProperty; this.recordProperty = recordProperty;
} }
@@ -72,7 +72,7 @@ public class APIConnectionRecordSortPredicate {
/** /**
* The property to use when sorting ConnectionRecords. * The property to use when sorting ConnectionRecords.
*/ */
private ConnectionRecordSet.SortableProperty property; private ActivityRecordSet.SortableProperty property;
/** /**
* Whether the requested sort order is descending (true) or ascending * Whether the requested sort order is descending (true) or ascending
@@ -102,7 +102,7 @@ public class APIConnectionRecordSortPredicate {
value = value.substring(DESCENDING_PREFIX.length()); value = value.substring(DESCENDING_PREFIX.length());
} }
// Parse sorting property into ConnectionRecordSet.SortableProperty // Parse sorting property into ActivityRecordSet.SortableProperty
try { try {
this.property = SortableProperty.valueOf(value).recordProperty; this.property = SortableProperty.valueOf(value).recordProperty;
} }
@@ -118,15 +118,15 @@ public class APIConnectionRecordSortPredicate {
} }
/** /**
* Returns the SortableProperty defined by ConnectionRecordSet which * Returns the SortableProperty defined by ActivityRecordSet which
* represents the property requested. * represents the property requested.
* *
* @return * @return
* The ConnectionRecordSet.SortableProperty which refers to the same * The ActivityRecordSet.SortableProperty which refers to the same
* property as the string originally provided when this * property as the string originally provided when this
* APIConnectionRecordSortPredicate was created. * APIConnectionRecordSortPredicate was created.
*/ */
public ConnectionRecordSet.SortableProperty getProperty() { public ActivityRecordSet.SortableProperty getProperty() {
return property; return property;
} }

View File

@@ -28,8 +28,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.auth.ActivityRecordSet;
import org.apache.guacamole.net.auth.ConnectionRecord; import org.apache.guacamole.net.auth.ConnectionRecord;
import org.apache.guacamole.net.auth.ConnectionRecordSet;
import org.apache.guacamole.net.auth.UserContext; import org.apache.guacamole.net.auth.UserContext;
/** /**
@@ -92,7 +92,7 @@ public class HistoryResource {
throws GuacamoleException { throws GuacamoleException {
// Retrieve overall connection history // Retrieve overall connection history
ConnectionRecordSet history = userContext.getConnectionHistory(); ActivityRecordSet<ConnectionRecord> history = userContext.getConnectionHistory();
// Restrict to records which contain the specified strings // Restrict to records which contain the specified strings
for (String required : requiredContents) { for (String required : requiredContents) {

View File

@@ -19,9 +19,13 @@
package org.apache.guacamole.rest.user; package org.apache.guacamole.rest.user;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleUnsupportedException; import org.apache.guacamole.GuacamoleUnsupportedException;
import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
import org.apache.guacamole.net.auth.permission.SystemPermissionSet; import org.apache.guacamole.net.auth.permission.SystemPermissionSet;
@@ -112,4 +116,14 @@ public class APIUserWrapper implements User {
throw new GuacamoleUnsupportedException("APIUserWrapper does not provide permission access."); throw new GuacamoleUnsupportedException("APIUserWrapper does not provide permission access.");
} }
@Override
public Date getLastActive() {
return null;
}
@Override
public List<? extends ActivityRecord> getHistory() throws GuacamoleException {
return Collections.<ActivityRecord>emptyList();
}
} }