GUAC-1100: Keep parent identifiers within SimpleUserContext consistent with reality.

This commit is contained in:
Michael Jumper
2015-02-21 23:42:22 -08:00
parent e9cebd181b
commit 220e33eca1
2 changed files with 38 additions and 16 deletions

View File

@@ -22,11 +22,10 @@
package org.glyptodon.guacamole.net.auth.simple; package org.glyptodon.guacamole.net.auth.simple;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.Connection;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
/** /**
* An extremely simple read-only implementation of a Directory of * An extremely simple read-only implementation of a Directory of
@@ -44,22 +43,21 @@ public class SimpleConnectionDirectory extends SimpleDirectory<Connection> {
new HashMap<String, Connection>(); new HashMap<String, Connection>();
/** /**
* Creates a new SimpleConnectionDirectory which provides * Creates a new SimpleConnectionDirectory which provides access to the
* access to the configurations contained within the given Map. * 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( public SimpleConnectionDirectory(Collection<Connection> connections) {
Map<String, GuacamoleConfiguration> configs) {
// Create connections for each config // Add all given connections
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) for (Connection connection : connections)
connections.put(entry.getKey(), this.connections.put(connection.getIdentifier(), connection);
new SimpleConnection(entry.getKey(), entry.getKey(),
entry.getValue()));
// Use the connection map to back the underlying AbstractDirectory // Use the connection map to back the underlying directory
super.setObjects(connections); super.setObjects(this.connections);
} }

View File

@@ -22,10 +22,13 @@
package org.glyptodon.guacamole.net.auth.simple; package org.glyptodon.guacamole.net.auth.simple;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.glyptodon.guacamole.GuacamoleException; 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.ConnectionGroup;
import org.glyptodon.guacamole.net.auth.Directory; import org.glyptodon.guacamole.net.auth.Directory;
import org.glyptodon.guacamole.net.auth.User; import org.glyptodon.guacamole.net.auth.User;
@@ -41,6 +44,11 @@ import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
*/ */
public class SimpleUserContext implements UserContext { 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 * Reference to the user whose permissions dictate the configurations
* accessible within this UserContext. * accessible within this UserContext.
@@ -82,9 +90,25 @@ public class SimpleUserContext implements UserContext {
*/ */
public SimpleUserContext(String username, Map<String, GuacamoleConfiguration> configs) { public SimpleUserContext(String username, Map<String, GuacamoleConfiguration> configs) {
// Produce collection of connections from given configs
Collection<Connection> connections = new ArrayList<Connection>(configs.size());
for (Map.Entry<String, GuacamoleConfiguration> 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 // Add root group that contains only configurations
this.connectionGroup = new SimpleConnectionGroup("ROOT", "ROOT", this.connectionGroup = new SimpleConnectionGroup(
new SimpleConnectionDirectory(configs), ROOT_IDENTIFIER, ROOT_IDENTIFIER,
new SimpleConnectionDirectory(connections),
new SimpleConnectionGroupDirectory(Collections.EMPTY_LIST)); new SimpleConnectionGroupDirectory(Collections.EMPTY_LIST));
// Build new user from credentials, giving the user an arbitrary name // Build new user from credentials, giving the user an arbitrary name