mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 21:51:23 +00:00
GUAC-1132: Implement tracking of all active connections.
This commit is contained in:
@@ -29,6 +29,8 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
import org.glyptodon.guacamole.auth.jdbc.user.AuthenticatedUser;
|
||||||
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
|
import org.glyptodon.guacamole.auth.jdbc.connection.ModeledConnection;
|
||||||
@@ -94,6 +96,12 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
@Inject
|
@Inject
|
||||||
private ConnectionRecordMapper connectionRecordMapper;
|
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.
|
* All active connections to a connection having a given identifier.
|
||||||
*/
|
*/
|
||||||
@@ -321,6 +329,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
// Release connection
|
// Release connection
|
||||||
activeConnections.remove(identifier, activeConnection);
|
activeConnections.remove(identifier, activeConnection);
|
||||||
activeConnectionGroups.remove(parentIdentifier, activeConnection);
|
activeConnectionGroups.remove(parentIdentifier, activeConnection);
|
||||||
|
activeConnectionRecords.remove(activeConnection);
|
||||||
release(user, connection);
|
release(user, connection);
|
||||||
|
|
||||||
// Release any associated group
|
// Release any associated group
|
||||||
@@ -369,6 +378,7 @@ public abstract class AbstractGuacamoleSocketService implements GuacamoleSocketS
|
|||||||
|
|
||||||
// Record new active connection
|
// Record new active connection
|
||||||
Runnable cleanupTask = new ConnectionCleanupTask(activeConnection);
|
Runnable cleanupTask = new ConnectionCleanupTask(activeConnection);
|
||||||
|
activeConnectionRecords.add(activeConnection);
|
||||||
activeConnections.put(connection.getIdentifier(), activeConnection);
|
activeConnections.put(connection.getIdentifier(), activeConnection);
|
||||||
activeConnectionGroups.put(connection.getParentIdentifier(), 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
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public GuacamoleSocket getGuacamoleSocket(final AuthenticatedUser user,
|
public GuacamoleSocket getGuacamoleSocket(final AuthenticatedUser user,
|
||||||
|
@@ -42,6 +42,24 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation;
|
|||||||
*/
|
*/
|
||||||
public interface GuacamoleSocketService {
|
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
|
* Creates a socket for the given user which connects to the given
|
||||||
* connection. The given client information will be passed to guacd when
|
* connection. The given client information will be passed to guacd when
|
||||||
@@ -81,7 +99,7 @@ public interface GuacamoleSocketService {
|
|||||||
* The connection to check.
|
* The connection to check.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* A connection containing connection records representing all
|
* A collection containing connection records representing all
|
||||||
* currently-active connections.
|
* currently-active connections.
|
||||||
*/
|
*/
|
||||||
public Collection<ConnectionRecord> getActiveConnections(Connection connection);
|
public Collection<ConnectionRecord> getActiveConnections(Connection connection);
|
||||||
|
@@ -32,6 +32,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.auth.jdbc.base.RestrictedObject;
|
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.Connection;
|
||||||
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
import org.glyptodon.guacamole.net.auth.ConnectionGroup;
|
||||||
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
import org.glyptodon.guacamole.net.auth.ConnectionRecord;
|
||||||
@@ -48,6 +49,12 @@ import org.glyptodon.guacamole.net.auth.User;
|
|||||||
public class UserContext extends RestrictedObject
|
public class UserContext extends RestrictedObject
|
||||||
implements org.glyptodon.guacamole.net.auth.UserContext {
|
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
|
* User directory restricted by the permissions of the user associated
|
||||||
* with this context.
|
* with this context.
|
||||||
@@ -119,8 +126,7 @@ public class UserContext extends RestrictedObject
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ConnectionRecord> getActiveConnections() throws GuacamoleException {
|
public Collection<ConnectionRecord> getActiveConnections() throws GuacamoleException {
|
||||||
// STUB
|
return socketService.getActiveConnections(getCurrentUser());
|
||||||
return Collections.EMPTY_LIST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user