diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionDirectory.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionDirectory.java index a8641cb6c..50e9d4ff5 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionDirectory.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleConnectionDirectory.java @@ -22,11 +22,10 @@ package org.glyptodon.guacamole.net.auth.simple; +import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import org.glyptodon.guacamole.net.auth.Connection; -import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** * An extremely simple read-only implementation of a Directory of @@ -44,22 +43,21 @@ public class SimpleConnectionDirectory extends SimpleDirectory { new HashMap(); /** - * Creates a new SimpleConnectionDirectory which provides - * access to the configurations contained within the given Map. + * Creates a new SimpleConnectionDirectory which provides access to the + * connections contained within the given Map. * - * @param configs The Map of GuacamoleConfigurations to provide access to. + * @param connections + * A Collection of all connections that should be present in this + * connection directory. */ - public SimpleConnectionDirectory( - Map configs) { + public SimpleConnectionDirectory(Collection connections) { - // Create connections for each config - for (Entry entry : configs.entrySet()) - connections.put(entry.getKey(), - new SimpleConnection(entry.getKey(), entry.getKey(), - entry.getValue())); + // Add all given connections + for (Connection connection : connections) + this.connections.put(connection.getIdentifier(), connection); - // Use the connection map to back the underlying AbstractDirectory - super.setObjects(connections); + // Use the connection map to back the underlying directory + super.setObjects(this.connections); } diff --git a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java index 474bc5373..032fc0dd4 100644 --- a/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/org/glyptodon/guacamole/net/auth/simple/SimpleUserContext.java @@ -22,10 +22,13 @@ package org.glyptodon.guacamole.net.auth.simple; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.UUID; import org.glyptodon.guacamole.GuacamoleException; +import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.ConnectionGroup; import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.User; @@ -41,6 +44,11 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; */ public class SimpleUserContext implements UserContext { + /** + * The unique identifier of the root connection group. + */ + private static final String ROOT_IDENTIFIER = "ROOT"; + /** * Reference to the user whose permissions dictate the configurations * accessible within this UserContext. @@ -82,9 +90,25 @@ public class SimpleUserContext implements UserContext { */ public SimpleUserContext(String username, Map configs) { + // Produce collection of connections from given configs + Collection connections = new ArrayList(configs.size()); + for (Map.Entry configEntry : configs.entrySet()) { + + // Get connection identifier and configuration + String identifier = configEntry.getKey(); + GuacamoleConfiguration config = configEntry.getValue(); + + // Add as simple connection + Connection connection = new SimpleConnection(identifier, identifier, config); + connection.setParentIdentifier(ROOT_IDENTIFIER); + connections.add(connection); + + } + // Add root group that contains only configurations - this.connectionGroup = new SimpleConnectionGroup("ROOT", "ROOT", - new SimpleConnectionDirectory(configs), + this.connectionGroup = new SimpleConnectionGroup( + ROOT_IDENTIFIER, ROOT_IDENTIFIER, + new SimpleConnectionDirectory(connections), new SimpleConnectionGroupDirectory(Collections.EMPTY_LIST)); // Build new user from credentials, giving the user an arbitrary name