summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java14
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/BwlpUserContext.java7
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java19
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