summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUdo Walter2020-05-14 05:35:13 +0200
committerUdo Walter2020-05-14 05:35:13 +0200
commitcdabaaebd6059077149a4856778ba51bcfd088fd (patch)
tree05a7848738e1456b30f5de0fcc6dff98833bbbf8
parentFix bug where user could reconnect to an old connection. (diff)
downloadbwlp-guacamole-ext-cdabaaebd6059077149a4856778ba51bcfd088fd.tar.gz
bwlp-guacamole-ext-cdabaaebd6059077149a4856778ba51bcfd088fd.tar.xz
bwlp-guacamole-ext-cdabaaebd6059077149a4856778ba51bcfd088fd.zip
Keep track of the number of tunnels per user.
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java b/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java
index 26aa93c..265bfc7 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java
@@ -7,7 +7,7 @@ import org.apache.guacamole.net.event.listener.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashSet;
+import java.util.HashMap;
/**
* A listener to track whether a user currently is connected to a tunnel.
@@ -16,10 +16,10 @@ public class TunnelListener implements Listener {
private static final Logger LOGGER = LoggerFactory.getLogger(TunnelListener.class);
- private static final HashSet<String> usersWithTunnel = new HashSet<String>();
+ private static final HashMap<String, Integer> userTunnelCount = new HashMap<String, Integer>();
public static boolean hasTunnel(String username) {
- return usersWithTunnel.contains(username);
+ return userTunnelCount.get(username) != null;
}
@Override
@@ -27,12 +27,24 @@ public class TunnelListener implements Listener {
if (event instanceof TunnelConnectEvent) {
String username = ((TunnelConnectEvent)event).getCredentials().getUsername();
LOGGER.info("User " + username + " connected to a tunnel.");
- usersWithTunnel.add(username);
+
+ Integer count = userTunnelCount.get(username);
+ if (count == null) count = 1;
+ else count++;
+ userTunnelCount.put(username, count);
+
+ LOGGER.info("Tunnel count: " + count);
}
else if (event instanceof TunnelCloseEvent) {
String username = ((TunnelCloseEvent)event).getCredentials().getUsername();
LOGGER.info("User " + username + " closed a tunnel.");
- usersWithTunnel.remove(username);
+
+ Integer count = userTunnelCount.get(username);
+ if (count != null) {
+ if (count > 1) userTunnelCount.put(username, count - 1);
+ else userTunnelCount.remove(username);
+ LOGGER.info("Tunnel count: " + (count - 1));
+ }
}
}