mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1100: Keep parent identifiers within SimpleUserContext consistent with reality.
This commit is contained in:
@@ -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<Connection> {
|
||||
new HashMap<String, Connection>();
|
||||
|
||||
/**
|
||||
* 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<String, GuacamoleConfiguration> configs) {
|
||||
public SimpleConnectionDirectory(Collection<Connection> connections) {
|
||||
|
||||
// Create connections for each config
|
||||
for (Entry<String, GuacamoleConfiguration> 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);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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<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
|
||||
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
|
||||
|
Reference in New Issue
Block a user