guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmuehl...@apache.org
Subject [1/3] incubator-guacamole-client git commit: GUACAMOLE-53: Implement session affinity within the GuacamoleTunnelService.
Date Wed, 15 Jun 2016 05:17:12 GMT
Repository: incubator-guacamole-client
Updated Branches:
  refs/heads/master f8d17e6be -> e8232315c


GUACAMOLE-53: Implement session affinity within the GuacamoleTunnelService.


Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/10344aeb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/10344aeb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/10344aeb

Branch: refs/heads/master
Commit: 10344aeba4ce23939e03500dc55fc662eaeb3cc5
Parents: b7ac434
Author: Michael Jumper <mjumper@apache.org>
Authored: Tue Jun 7 20:51:34 2016 -0700
Committer: Michael Jumper <mjumper@apache.org>
Committed: Tue Jun 14 22:14:41 2016 -0700

----------------------------------------------------------------------
 .../connectiongroup/ModeledConnectionGroup.java | 11 +++++
 .../tunnel/AbstractGuacamoleTunnelService.java  | 45 ++++++++++++++++++++
 .../auth/jdbc/user/AuthenticatedUser.java       | 44 +++++++++++++++++++
 3 files changed, 100 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/10344aeb/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java
b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java
index 85f6cec..a0675f4 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connectiongroup/ModeledConnectionGroup.java
@@ -257,5 +257,16 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<Connec
 
     }
 
+    /**
+     * Returns whether individual users should be consistently assigned the same
+     * connection within a balancing group until they log out.
+     *
+     * @return
+     *     Whether individual users should be consistently assigned the same
+     *     connection within a balancing group until they log out.
+     */
+    public boolean isSessionAffinityEnabled() {
+        return getModel().isSessionAffinityEnabled();
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/10344aeb/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java
b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java
index 95d5ab6..1b65ab8 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/AbstractGuacamoleTunnelService.java
@@ -413,6 +413,43 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
     }
 
     /**
+     * Filters the given collection of connection identifiers, returning a new
+     * collection which contains only those identifiers which are preferred. If
+     * no connection identifiers within the given collection are preferred, the
+     * collection is left untouched.
+     *
+     * @param user
+     *     The user whose preferred connections should be used to filter the
+     *     given collection of connection identifiers.
+     *
+     * @param identifiers
+     *     The collection of connection identifiers that should be filtered.
+     *
+     * @return
+     *     A collection of connection identifiers containing only the subset of
+     *     connection identifiers which are also preferred or, if none of the
+     *     provided identifiers are preferred, the original collection of
+     *     identifiers.
+     */
+    private Collection<String> getPreferredConnections(AuthenticatedUser user,
+            Collection<String> identifiers) {
+
+        // Search provided identifiers for any preferred connections
+        for (String identifier : identifiers) {
+
+            // If at least one prefferred connection is found, assume it is the
+            // only preferred connection
+            if (user.isPreferredConnection(identifier))
+                return Collections.singletonList(identifier);
+
+        }
+
+        // No preferred connections were found
+        return identifiers;
+
+    }
+
+    /**
      * Returns a list of all balanced connections within a given connection
      * group. If the connection group is not balancing, or it contains no
      * connections, an empty list is returned.
@@ -440,6 +477,10 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
         if (identifiers.isEmpty())
             return Collections.<ModeledConnection>emptyList();
 
+        // Restrict to preferred connections if session affinity is enabled
+        if (connectionGroup.isSessionAffinityEnabled())
+            identifiers = getPreferredConnections(user, identifiers);
+
         // Retrieve all children
         Collection<ConnectionModel> models = connectionMapper.select(identifiers);
         List<ModeledConnection> connections = new ArrayList<ModeledConnection>(models.size());
@@ -535,6 +576,10 @@ public abstract class AbstractGuacamoleTunnelService implements GuacamoleTunnelS
             throw e;
         }
 
+        // If session affinity is enabled, prefer this connection going forward
+        if (connectionGroup.isSessionAffinityEnabled())
+            user.preferConnection(connection.getIdentifier());
+
         // Connect to acquired child
         return assignGuacamoleTunnel(new ActiveConnectionRecord(user, connectionGroup, connection),
info);
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/10344aeb/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticatedUser.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticatedUser.java
b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticatedUser.java
index 3322a20..0696c88 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticatedUser.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/user/AuthenticatedUser.java
@@ -19,6 +19,9 @@
 
 package org.apache.guacamole.auth.jdbc.user;
 
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.servlet.http.HttpServletRequest;
@@ -74,6 +77,17 @@ public class AuthenticatedUser implements org.apache.guacamole.net.auth.Authenti
     private static final Pattern X_FORWARDED_FOR = Pattern.compile("^" + IP_ADDRESS_REGEX
+ "(, " + IP_ADDRESS_REGEX + ")*$");
 
     /**
+     * The connections which have been committed for use by this user in the
+     * context of a balancing connection group. Balancing connection groups
+     * will preferentially choose connections within this set, unless those
+     * connections are not children of the group in question. If a group DOES
+     * have at least one child connection within this set, no connections that
+     * are not in this set will be used.
+     */
+    private final Set<String> preferredConnections =
+            Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
+
+    /**
      * Derives the remote host of the authenticating user from the given
      * credentials object. The remote host is derived from X-Forwarded-For
      * in addition to the actual source IP of the request, and thus is not
@@ -157,6 +171,36 @@ public class AuthenticatedUser implements org.apache.guacamole.net.auth.Authenti
         return remoteHost;
     }
 
+    /**
+     * Returns whether the connection having the given identifier has been
+     * marked as preferred for this user's current Guacamole session. A
+     * preferred connection is always chosen in favor of other connections when
+     * it is a child of a balancing connection group.
+     *
+     * @param identifier
+     *     The identifier of the connection to test.
+     *
+     * @return
+     *     true if the connection having the given identifier has been marked
+     *     as preferred, false otherwise.
+     */
+    public boolean isPreferredConnection(String identifier) {
+        return preferredConnections.contains(identifier);
+    }
+
+    /**
+     * Marks the connection having the given identifier as preferred for this
+     * user's current Guacamole session. A preferred connection is always chosen
+     * in favor of other connections when it is a child of a balancing
+     * connection group.
+     *
+     * @param identifier
+     *     The identifier of the connection to prefer.
+     */
+    public void preferConnection(String identifier) {
+        preferredConnections.add(identifier);
+    }
+
     @Override
     public AuthenticationProvider getAuthenticationProvider() {
         return authenticationProvider;


Mime
View raw message