GUACAMOLE-53: Add session affinity attribute for connection groups.

This commit is contained in:
Michael Jumper
2016-06-07 19:35:07 -07:00
parent f8d17e6bef
commit b7ac434d41
9 changed files with 108 additions and 29 deletions

View File

@@ -54,6 +54,12 @@ public class ConnectionGroupModel extends GroupedObjectModel {
*/
private Integer maxConnectionsPerUser;
/**
* Whether individual users should be consistently assigned the same
* connection within a balancing group until they log out.
*/
private boolean sessionAffinityEnabled;
/**
* Creates a new, empty connection group.
*/
@@ -156,6 +162,30 @@ public class ConnectionGroupModel extends GroupedObjectModel {
this.maxConnectionsPerUser = maxConnectionsPerUser;
}
/**
* 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 sessionAffinityEnabled;
}
/**
* Sets whether individual users should be consistently assigned the same
* connection within a balancing group until they log out.
*
* @param sessionAffinityEnabled
* Whether individual users should be consistently assigned the same
* connection within a balancing group until they log out.
*/
public void setSessionAffinityEnabled(boolean sessionAffinityEnabled) {
this.sessionAffinityEnabled = sessionAffinityEnabled;
}
@Override
public String getIdentifier() {

View File

@@ -26,11 +26,12 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.guacamole.auth.jdbc.connection.ConnectionService;
import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.auth.jdbc.JDBCEnvironment;
import org.apache.guacamole.auth.jdbc.base.ModeledGroupedDirectoryObject;
import org.apache.guacamole.auth.jdbc.connection.ConnectionService;
import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
import org.apache.guacamole.form.BooleanField;
import org.apache.guacamole.form.Field;
import org.apache.guacamole.form.Form;
import org.apache.guacamole.form.NumericField;
@@ -67,13 +68,21 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<Connec
*/
public static final String MAX_CONNECTIONS_PER_USER_NAME = "max-connections-per-user";
/**
* The name of the attribute which controls whether individual users will be
* consistently assigned the same connection within a balancing group until
* they log out.
*/
public static final String ENABLE_SESSION_AFFINITY = "enable-session-affinity";
/**
* All attributes related to restricting user accounts, within a logical
* form.
*/
public static final Form CONCURRENCY_LIMITS = new Form("concurrency", Arrays.<Field>asList(
new NumericField(MAX_CONNECTIONS_NAME),
new NumericField(MAX_CONNECTIONS_PER_USER_NAME)
new NumericField(MAX_CONNECTIONS_PER_USER_NAME),
new BooleanField(ENABLE_SESSION_AFFINITY, "true")
));
/**
@@ -168,6 +177,10 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<Connec
// Set per-user connection limit attribute
attributes.put(MAX_CONNECTIONS_PER_USER_NAME, NumericField.format(getModel().getMaxConnectionsPerUser()));
// Set session affinity attribute
attributes.put(ENABLE_SESSION_AFFINITY,
getModel().isSessionAffinityEnabled() ? "true" : "");
return attributes;
}
@@ -188,6 +201,10 @@ public class ModeledConnectionGroup extends ModeledGroupedDirectoryObject<Connec
logger.debug("Unable to parse numeric attribute.", e);
}
// Translate session affinity attribute
getModel().setSessionAffinityEnabled(
"true".equals(attributes.get(ENABLE_SESSION_AFFINITY)));
}
/**

View File

@@ -26,6 +26,7 @@
"CONNECTION_GROUP_ATTRIBUTES" : {
"FIELD_HEADER_ENABLE_SESSION_AFFINITY" : "Enable session affinity:",
"FIELD_HEADER_MAX_CONNECTIONS" : "Maximum number of connections:",
"FIELD_HEADER_MAX_CONNECTIONS_PER_USER" : "Maximum number of connections per user:",