From 8a5c18f90d68ce1e803bc3656f7e976474e392be Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 22 Aug 2013 17:19:38 -0700 Subject: [PATCH] Implement SimpleConnectionGroupDirectory. --- .../auth/simple/SimpleConnectionGroup.java | 39 +++++++++++-- .../SimpleConnectionGroupDirectory.java | 57 ++++++++++++++++--- .../net/auth/simple/SimpleUserContext.java | 26 ++------- 3 files changed, 90 insertions(+), 32 deletions(-) diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroup.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroup.java index 8973367c0..1f8361e27 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroup.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroup.java @@ -55,16 +55,47 @@ import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; * @author James Muehlner */ public class SimpleConnectionGroup extends AbstractConnectionGroup { - + + /** + * Underlying connection directory, containing all connections within this + * group. + */ private final Directory connectionDirectory; + + /** + * Underlying connection group directory, containing all connections within + * this group. + */ private final Directory connectionGroupDirectory; - - public SimpleConnectionGroup(Directory connectionDirectory, + /** + * Creates a new SimpleConnectionGroup having the given name and identifier + * which will expose the given directories as its contents. + * + * @param name The name to associate with this connection. + * @param identifier The identifier to associate with this connection. + * @param connectionDirectory The connection directory to expose when + * requested. + * @param connectionGroupDirectory The connection group directory to expose + * when requested. + */ + public SimpleConnectionGroup(String name, String identifier, + Directory connectionDirectory, Directory connectionGroupDirectory) { + + // Set name + setName(name); + + // Set identifier + setIdentifier(identifier); + + // Set group type + setType(ConnectionGroup.Type.ORGANIZATIONAL); + + // Assign directories this.connectionDirectory = connectionDirectory; this.connectionGroupDirectory = connectionGroupDirectory; - this.setType(ConnectionGroup.Type.ORGANIZATIONAL); + } @Override diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java index 003911d9c..9f252f1a3 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java @@ -37,7 +37,9 @@ package net.sourceforge.guacamole.net.auth.simple; * * ***** END LICENSE BLOCK ***** */ -import java.util.Collections; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleSecurityException; @@ -47,26 +49,44 @@ import net.sourceforge.guacamole.net.auth.Directory; /** * An extremely simple read-only implementation of a Directory of - * ConnectionGroup which provides an empty set of connection groups. + * ConnectionGroup which provides which provides access to a pre-defined + * Collection of ConnectionGroups. * * @author James Muehlner */ public class SimpleConnectionGroupDirectory implements Directory { - + /** - * Creates a new SimpleConnectionGroupDirectory */ - public SimpleConnectionGroupDirectory() {} + * The Map of ConnectionGroups to provide access to. + */ + private Map connectionGroups = + new HashMap(); + + /** + * Creates a new SimpleConnectionGroupDirectory which contains the given + * groups. + * + * @param groups A Collection of all groups that should be present in this + * connection group directory. + */ + public SimpleConnectionGroupDirectory(Collection groups) { + + // Add all given groups + for (ConnectionGroup group : groups) + connectionGroups.put(group.getIdentifier(), group); + + } @Override public ConnectionGroup get(String identifier) throws GuacamoleException { - return null; + return connectionGroups.get(identifier); } @Override public Set getIdentifiers() throws GuacamoleException { - return Collections.EMPTY_SET; + return connectionGroups.keySet(); } @Override @@ -92,4 +112,27 @@ public class SimpleConnectionGroupDirectory throw new GuacamoleSecurityException("Permission denied."); } + /** + * An internal method for modifying the ConnectionGroups in this Directory. + * Returns the previous connection group for the given identifier, if found. + * + * @param connectionGroup The connection group to add or update the + * Directory with. + * @return The previous connection group for the connection group + * identifier, if found. + */ + public ConnectionGroup putConnectionGroup(ConnectionGroup connectionGroup) { + return connectionGroups.put(connectionGroup.getIdentifier(), connectionGroup); + } + + /** + * An internal method for removing a ConnectionGroup from this Directory. + * + * @param identifier The identifier of the ConnectionGroup to remove. + * @return The previous connection group for the given identifier, if found. + */ + public ConnectionGroup removeConnectionGroup(String identifier) { + return connectionGroups.remove(identifier); + } + } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java index 08ec1151d..083bc4eb7 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserContext.java @@ -37,9 +37,9 @@ package net.sourceforge.guacamole.net.auth.simple; * * ***** END LICENSE BLOCK ***** */ +import java.util.Collections; import java.util.Map; import net.sourceforge.guacamole.GuacamoleException; -import net.sourceforge.guacamole.net.auth.Connection; import net.sourceforge.guacamole.net.auth.ConnectionGroup; import net.sourceforge.guacamole.net.auth.Directory; import net.sourceforge.guacamole.net.auth.User; @@ -61,18 +61,6 @@ public class SimpleUserContext implements UserContext { */ private final User self; - /** - * The Directory with access only to those Connections that the User - * associated with this UserContext has access to. - */ - private final Directory connectionDirectory; - - /** - * The Directory with access only to those Connection Groups that the User - * associated with this UserContext has access to. - */ - private final Directory connectionGroupDirectory; - /** * The Directory with access only to the User associated with this * UserContext. @@ -99,16 +87,12 @@ public class SimpleUserContext implements UserContext { Map configs) { this.self = self; - - this.connectionDirectory = - new SimpleConnectionDirectory(configs); - - this.connectionGroupDirectory = new SimpleConnectionGroupDirectory(); - this.userDirectory = new SimpleUserDirectory(self); - this.connectionGroup = new SimpleConnectionGroup(this.connectionDirectory, - this.connectionGroupDirectory); + // Add root group that contains only configurations + this.connectionGroup = new SimpleConnectionGroup("ROOT", "ROOT", + new SimpleConnectionDirectory(configs), + new SimpleConnectionGroupDirectory(Collections.EMPTY_LIST)); }