diff options
author | Simon Rettberg | 2020-05-15 16:46:38 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-05-15 16:46:38 +0200 |
commit | db675690eb2c946ab27a5985530a96bd0bdbb0cc (patch) | |
tree | a1dc8af81721060b85e446040d7ecf41c4c45759 /src | |
parent | Check if remote host actually repies with RFB handshake (diff) | |
download | bwlp-guacamole-ext-db675690eb2c946ab27a5985530a96bd0bdbb0cc.tar.gz bwlp-guacamole-ext-db675690eb2c946ab27a5985530a96bd0bdbb0cc.tar.xz bwlp-guacamole-ext-db675690eb2c946ab27a5985530a96bd0bdbb0cc.zip |
Try reusing old connection, even if we don't have a user context
Diffstat (limited to 'src')
3 files changed, 35 insertions, 5 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java index c59c477..017c806 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java @@ -65,11 +65,15 @@ public class BwlpAuthenticationProvider implements AuthenticationProvider { if (user != null && user.hasValidConnection()) return user; - - int groupid = requestGroup(credentials); - - LOGGER.warn("Doing the REdecoration"); - user = new BwlpUserContext(authenticatedUser, context, groupid); + + WrappedConnection exConn = ConnectionManager.getExistingConnection(username); + if (exConn != null) { + user = new BwlpUserContext(authenticatedUser, context, exConn); + } else { + int groupid = requestGroup(credentials); + LOGGER.warn("Doing the REdecoration"); + user = new BwlpUserContext(authenticatedUser, context, groupid); + } oldMappings.put(username, user); return user; diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java index 813b6f2..2fcc6a6 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java @@ -47,6 +47,13 @@ public class BwlpUserContext extends AbstractUserContext { addConn(); } + public BwlpUserContext(AuthenticatedUser authenticatedUser, UserContext context, WrappedConnection exConn) { + authUser = authenticatedUser; + originalContext = context; + this.groupid = -1; + connectionDirectory = new SimpleDirectory<Connection>(exConn); + } + private void addConn() throws GuacamoleCredentialsException { WrappedConnection connection = ConnectionManager.getForUser(authUser.getCredentials().getUsername(), groupid); if (connection != null) { diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java index 97dd851..62b54b6 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java @@ -45,6 +45,25 @@ public class ConnectionManager { private static final LinkedHashMap<Integer, JsonGroup> groupPool = new LinkedHashMap<Integer, JsonGroup>(); public static LinkedHashMap<Integer, JsonGroup> getGroupPool() { return groupPool; } + + public static WrappedConnection getExistingConnection(String user) { + AvailableClient freeClient = null; + synchronized (clientPool) { + for (AvailableClient ac : clientPool.values()) { + LOGGER.info("Looking for existing mapping: Checking client " + ac); + if (ac.isInUseBy(user)) { + LOGGER.info("Client " + ac + " is in use by " + user); + freeClient = ac; + break; + } + } + } + if (freeClient != null && freeClient.checkConnection(1)) { + LOGGER.info("Existing mapping for user " + user + " to " + freeClient); + return freeClient.getConnection(user); + } + return null; + } /** * Pass plain user name, get existing connection (if any), or a fresh one |