diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java index 9ac828bce..06bd5256e 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/glyptodon/guacamole/auth/jdbc/user/UserContext.java @@ -39,8 +39,10 @@ import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; +import org.glyptodon.guacamole.net.auth.ConnectionRecordSet; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; +import org.glyptodon.guacamole.net.auth.simple.SimpleConnectionRecordSet; /** * UserContext implementation which is driven by an arbitrary, underlying @@ -136,6 +138,12 @@ public class UserContext extends RestrictedObject return activeConnectionDirectory; } + @Override + public ConnectionRecordSet getConnectionHistory() + throws GuacamoleException { + return new SimpleConnectionRecordSet(); + } + @Override public ConnectionGroup getRootConnectionGroup() throws GuacamoleException { diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/glyptodon/guacamole/auth/ldap/user/UserContext.java b/extensions/guacamole-auth-ldap/src/main/java/org/glyptodon/guacamole/auth/ldap/user/UserContext.java index 75fa66eff..fd2e27eb7 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/glyptodon/guacamole/auth/ldap/user/UserContext.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/glyptodon/guacamole/auth/ldap/user/UserContext.java @@ -35,10 +35,12 @@ import org.glyptodon.guacamole.net.auth.AuthenticatedUser; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; +import org.glyptodon.guacamole.net.auth.ConnectionRecordSet; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.simple.SimpleConnectionGroup; import org.glyptodon.guacamole.net.auth.simple.SimpleConnectionGroupDirectory; +import org.glyptodon.guacamole.net.auth.simple.SimpleConnectionRecordSet; import org.glyptodon.guacamole.net.auth.simple.SimpleDirectory; import org.glyptodon.guacamole.net.auth.simple.SimpleUser; import org.slf4j.Logger; @@ -194,6 +196,12 @@ public class UserContext implements org.glyptodon.guacamole.net.auth.UserContext return new SimpleDirectory(); } + @Override + public ConnectionRecordSet getConnectionHistory() + throws GuacamoleException { + return new SimpleConnectionRecordSet(); + } + @Override public Collection
getUserAttributes() { return Collections.emptyList(); diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionRecordSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionRecordSet.java new file mode 100644 index 000000000..3e40474a4 --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/ConnectionRecordSet.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.auth; + +import java.util.Collection; +import java.util.Date; +import org.glyptodon.guacamole.GuacamoleException; + +/** + * The set of all available connection records, or a subset of those records. + * + * @author James Muehlner + * @author Michael Jumper + */ +public interface ConnectionRecordSet { + + /** + * All properties of connection records which can be used as sorting + * criteria. + */ + enum SortableProperty { + + /** + * The name (not identifier) of the connection associated with the + * connection record. + */ + CONNECTION_NAME, + + /** + * The identifier (username) of the user that used the connection + * associated with the connection record. + */ + USER_IDENTIFIER, + + /** + * The date and time when the connection associated with the + * connection record began. + */ + START_DATE, + + /** + * The date and time when the connection associated with the + * connection record ended. + */ + END_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 asCollection() throws GuacamoleException; + + /** + * Returns the subset of connection records to only those that began after + * the given date and time. + * + * @param date + * The date and time after which all connection records within the + * resulting subset should begin. + * + * @return + * The subset of connection history records which begin after the + * specified date and time. + * + * @throws GuacamoleException + * If an error occurs while restricting the current subset. + */ + ConnectionRecordSet after(Date date) throws GuacamoleException; + + /** + * Returns the subset of connection records to only those that ended before + * the given date and time. + * + * @param date + * The date and time before which all connection records within the + * resulting subset should end. + * + * @return + * The subset of connection history records which end before the + * specified date and time. + * + * @throws GuacamoleException + * If an error occurs while restricting the current subset. + */ + ConnectionRecordSet before(Date date) throws GuacamoleException; + + /** + * Returns the subset of connection records to only those where the + * connection name or user identifier contain the given value. + * + * @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 limit records. If the subset has fewer than + * limit records, then this function has no effect. + * + * @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 limit 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(). + * + * @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; + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java index f668a3586..f38fad8f8 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/UserContext.java @@ -109,6 +109,19 @@ public interface UserContext { Directory getActiveConnectionDirectory() throws GuacamoleException; + /** + * Retrieves all connection records visible to current user. The resulting + * set of connection records can be further filtered and ordered using the + * methods defined on ConnectionRecordSet. + * + * @return + * A set of all connection records visible to the current user. + * + * @throws GuacamoleException + * If an error occurs while retrieving the connection records. + */ + ConnectionRecordSet getConnectionHistory() throws GuacamoleException; + /** * Retrieves a connection group which can be used to view and manipulate * connections, but only as allowed by the permissions given to the user of diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionRecordSet.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionRecordSet.java new file mode 100644 index 000000000..c9bb2b4bc --- /dev/null +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionRecordSet.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.glyptodon.guacamole.net.auth.simple; + +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.ConnectionRecord; +import org.glyptodon.guacamole.net.auth.ConnectionRecordSet; + +/** + * An immutable and empty ConnectionRecordSet. + * + * @author Michael Jumper + */ +public class SimpleConnectionRecordSet implements ConnectionRecordSet { + + @Override + public Collection asCollection() + throws GuacamoleException { + return Collections.emptyList(); + } + + @Override + public ConnectionRecordSet after(Date date) + throws GuacamoleException { + return this; + } + + @Override + public ConnectionRecordSet before(Date date) + throws GuacamoleException { + return this; + } + + @Override + public ConnectionRecordSet contains(String value) + throws GuacamoleException { + return this; + } + + @Override + public ConnectionRecordSet limit(int limit) + throws GuacamoleException { + return this; + } + + @Override + public ConnectionRecordSet sort(SortableProperty property, boolean desc) + throws GuacamoleException { + return this; + } + +} diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index 9293d46b3..a47fd0bf5 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -33,6 +33,7 @@ import org.glyptodon.guacamole.net.auth.ActiveConnection; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; +import org.glyptodon.guacamole.net.auth.ConnectionRecordSet; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.UserContext; @@ -200,6 +201,12 @@ public class SimpleUserContext implements UserContext { return new SimpleDirectory(); } + @Override + public ConnectionRecordSet getConnectionHistory() + throws GuacamoleException { + return new SimpleConnectionRecordSet(); + } + @Override public Collection getUserAttributes() { return Collections.emptyList();