blob: 26aa93c0a7e3699a0349a710a66d7575c16046b4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package de.bwlehrpool.bwlp_guac;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.event.TunnelCloseEvent;
import org.apache.guacamole.net.event.TunnelConnectEvent;
import org.apache.guacamole.net.event.listener.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashSet;
/**
* A listener to track whether a user currently is connected to a tunnel.
*/
public class TunnelListener implements Listener {
private static final Logger LOGGER = LoggerFactory.getLogger(TunnelListener.class);
private static final HashSet<String> usersWithTunnel = new HashSet<String>();
public static boolean hasTunnel(String username) {
return usersWithTunnel.contains(username);
}
@Override
public void handleEvent(Object event) throws GuacamoleException {
if (event instanceof TunnelConnectEvent) {
String username = ((TunnelConnectEvent)event).getCredentials().getUsername();
LOGGER.info("User " + username + " connected to a tunnel.");
usersWithTunnel.add(username);
}
else if (event instanceof TunnelCloseEvent) {
String username = ((TunnelCloseEvent)event).getCredentials().getUsername();
LOGGER.info("User " + username + " closed a tunnel.");
usersWithTunnel.remove(username);
}
}
}
|