GUAC-1132: Implement tracking of all active connections.

This commit is contained in:
Michael Jumper
2015-03-16 16:32:47 -07:00
parent 1e8d68d611
commit c7827e0e3f
3 changed files with 49 additions and 3 deletions

View File

@@ -29,6 +29,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
@@ -94,6 +96,12 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
@Inject
private ConnectionRecordMapper connectionRecordMapper;
/**
* All records associated with active connections.
*/
private final Set<ConnectionRecord> activeConnectionRecords =
Collections.newSetFromMap(new ConcurrentHashMap<ConnectionRecord, Boolean>());
/**
* All active connections to a connection having a given identifier.
*/
@@ -321,6 +329,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
// Release connection
activeConnections.remove(identifier, activeConnection);
activeConnectionGroups.remove(parentIdentifier, activeConnection);
activeConnectionRecords.remove(activeConnection);
release(user, connection);
// Release any associated group
@@ -369,6 +378,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
// Record new active connection
Runnable cleanupTask = new ConnectionCleanupTask(activeConnection);
activeConnectionRecords.add(activeConnection);
activeConnections.put(connection.getIdentifier(), activeConnection);
activeConnectionGroups.put(connection.getParentIdentifier(), activeConnection);
@@ -432,6 +442,18 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
}
@Override
public Collection<ConnectionRecord> getActiveConnections(AuthenticatedUser user)
throws GuacamoleException {
// Only administrators may see all active connections
if (!user.getUser().isAdministrator())
return Collections.EMPTY_LIST;
return Collections.unmodifiableCollection(activeConnectionRecords);
}
@Override
@Transactional
public GuacamoleSocket getGuacamoleSocket(final AuthenticatedUser user,

View File

@@ -42,6 +42,24 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
*/
public interface GuacamoleSocketService {
/**
* Returns a connection containing connection records representing all
* currently-active connections visible by the given user.
*
* @param user
* The user retrieving active connections.
*
* @return
* A collection containing connection records representing all
* currently-active connections.
*
* @throws GuacamoleException
* If an error occurs while retrieving all active connections, or if
* permission is denied.
*/
public Collection<ConnectionRecord> getActiveConnections(AuthenticatedUser user)
throws GuacamoleException;
/**
* Creates a socket for the given user which connects to the given
* connection. The given client information will be passed to guacd when
@@ -81,7 +99,7 @@ public interface GuacamoleSocketService {
* The connection to check.
*
* @return
* A connection containing connection records representing all
* A collection containing connection records representing all
* currently-active connections.
*/
public Collection<ConnectionRecord> getActiveConnections(Connection connection);

View File

@@ -32,6 +32,7 @@ import java.util.Collection;
import java.util.Collections;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
import org.glyptodon.guacamole.auth.jdbc.socket.GuacamoleSocketService;
import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
@@ -48,6 +49,12 @@ import org.glyptodon.guacamole.net.auth.User;
public class UserContext extends RestrictedObject
implements org.glyptodon.guacamole.net.auth.UserContext {
/**
* Service for creating and tracking sockets.
*/
@Inject
private GuacamoleSocketService socketService;
/**
* User directory restricted by the permissions of the user associated
* with this context.
@@ -119,8 +126,7 @@ public class UserContext extends RestrictedObject
@Override
public Collection<ConnectionRecord> getActiveConnections() throws GuacamoleException {
// STUB
return Collections.EMPTY_LIST;
return socketService.getActiveConnections(getCurrentUser());
}
}