diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java index a3d3bea19..fbcef6b5c 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/Directory.java @@ -48,6 +48,9 @@ import net.sourceforge.guacamole.GuacamoleException; * function. * * @author Michael Jumper + * @param The type of identifier used to identify objects + * stored within this Directory. + * @param The type of objects stored within this Directory. */ public interface Directory { @@ -82,13 +85,12 @@ public interface Directory { /** * Adds the given object to the overall set. * - * @param identifier The identifier to use when adding the object. * @param object The object to add. * * @throws GuacamoleException If an error occurs while adding the object , or * if adding the object is not allowed. */ - void add(IdentifierType identifier, ObjectType object) + void add(ObjectType object) throws GuacamoleException; /** @@ -101,7 +103,7 @@ public interface Directory { * @throws GuacamoleException If an error occurs while updating the object, * or if updating the object is not allowed. */ - void update(IdentifierType identifier, ObjectType object) + void update(ObjectType object) throws GuacamoleException; /** diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java index be2d4441b..0444b7c56 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/UserContext.java @@ -38,7 +38,6 @@ package net.sourceforge.guacamole.net.auth; * ***** END LICENSE BLOCK ***** */ import net.sourceforge.guacamole.GuacamoleException; -import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; /** * The context of an active user. The functions of this class enforce all @@ -58,31 +57,30 @@ public interface UserContext { User self(); /** - * Retrieves a UserDirectory which can be used to view and manipulate other + * Retrieves a Directory which can be used to view and manipulate other * users, but only as allowed by the permissions given to the user of this * UserContext. * - * @return A UserDirectory whose operations are bound by the restrictions + * @return A Directory whose operations are bound by the restrictions * of this UserContext. * * @throws GuacamoleException If an error occurs while creating the - * UserDirectory. + * Directory. */ Directory getUserDirectory() throws GuacamoleException; /** - * Retrieves a GuacamoleConfigurationDirectory which can be used to view - * and manipulate configurations, but only as allowed by the permissions - * given to the user of this UserContext. + * Retrieves a Directory which can be used to view and manipulate + * connections and their configurations, but only as allowed by the + * permissions given to the user of this UserContext. * - * @return A GuacamoleConfigurationdirectory whose operations are bound by - * the restrictions of this UserContext. + * @return A Directory whose operations are bound by the restrictions + * of this UserContext. * * @throws GuacamoleException If an error occurs while creating the - * GuacamoleConfigurationDirectory. + * Directory. */ - Directory - getGuacamoleConfigurationDirectory() + Directory getConnectionDirectory() throws GuacamoleException; } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationDirectoryPermission.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionDirectoryPermission.java similarity index 88% rename from guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationDirectoryPermission.java rename to guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionDirectoryPermission.java index 71a24ffef..54e8dfdd4 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationDirectoryPermission.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionDirectoryPermission.java @@ -43,7 +43,7 @@ package net.sourceforge.guacamole.net.auth.permission; * * @author Michael Jumper */ -public class GuacamoleConfigurationDirectoryPermission +public class ConnectionDirectoryPermission implements SystemPermission { /** @@ -52,12 +52,12 @@ public class GuacamoleConfigurationDirectoryPermission private Type type; /** - * Creates a new GuacamoleConfigurationDirectoryPermission with the given + * Creates a new ConnectionDirectoryPermission with the given * type. * * @param type The type of operation controlled by this permission. */ - public GuacamoleConfigurationDirectoryPermission(Type type) { + public ConnectionDirectoryPermission(Type type) { this.type = type; } @@ -78,8 +78,8 @@ public class GuacamoleConfigurationDirectoryPermission if (obj == null) return false; if (getClass() != obj.getClass()) return false; - final GuacamoleConfigurationDirectoryPermission other = - (GuacamoleConfigurationDirectoryPermission) obj; + final ConnectionDirectoryPermission other = + (ConnectionDirectoryPermission) obj; // Compare types if (type != other.type) diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationPermission.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionPermission.java similarity index 92% rename from guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationPermission.java rename to guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionPermission.java index 1661c5c93..bc75f89c4 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/GuacamoleConfigurationPermission.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/permission/ConnectionPermission.java @@ -46,7 +46,7 @@ package net.sourceforge.guacamole.net.auth.permission; * * @author Michael Jumper */ -public class GuacamoleConfigurationPermission +public class ConnectionPermission implements ObjectPermission { /** @@ -61,7 +61,7 @@ public class GuacamoleConfigurationPermission private Type type; /** - * Creates a new GuacamoleConfigurationPermission having the given type + * Creates a new ConnectionPermission having the given type * and identifier. The identifier must be the unique identifier assigned * to the GuacamoleConfiguration by the AuthenticationProvider in use. * @@ -69,7 +69,7 @@ public class GuacamoleConfigurationPermission * @param identifier The identifier of the GuacamoleConfiguration associated * with the operation affected by this permission. */ - public GuacamoleConfigurationPermission(Type type, String identifier) { + public ConnectionPermission(Type type, String identifier) { this.identifier = identifier; this.type = type; @@ -101,8 +101,8 @@ public class GuacamoleConfigurationPermission if (obj == null) return false; if (getClass() != obj.getClass()) return false; - final GuacamoleConfigurationPermission other = - (GuacamoleConfigurationPermission) obj; + final ConnectionPermission other = + (ConnectionPermission) obj; // Not equal if different type if (this.type != other.type) diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnection.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnection.java new file mode 100644 index 000000000..b85a5b6b9 --- /dev/null +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnection.java @@ -0,0 +1,104 @@ + +package net.sourceforge.guacamole.net.auth.simple; + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is guacamole-auth. + * + * The Initial Developer of the Original Code is + * Michael Jumper. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.net.GuacamoleSocket; +import net.sourceforge.guacamole.net.InetGuacamoleSocket; +import net.sourceforge.guacamole.net.auth.AbstractConnection; +import net.sourceforge.guacamole.properties.GuacamoleProperties; +import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket; +import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; +import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; + + +/** + * An extremely basic Connection implementation. + * + * @author Michael Jumper + */ +public class SimpleConnection extends AbstractConnection { + + /** + * Backing configuration, containing all sensitive information. + */ + private GuacamoleConfiguration config; + + /** + * Creates a completely uninitialized SimpleConnection. + */ + public SimpleConnection() { + } + + /** + * Creates a new SimpleConnection having the given identifier and + * GuacamoleConfiguration. + * + * @param identifier The identifier to associated with this connection. + * @param config The configuration describing how to connect to this + * connection. + */ + public SimpleConnection(String identifier, + GuacamoleConfiguration config) { + + // Set identifier + setIdentifier(identifier); + + // Set config + setConfiguration(config); + this.config = config; + + } + + @Override + public GuacamoleSocket connect(GuacamoleClientInformation info) + throws GuacamoleException { + + // Get guacd connection parameters + String hostname = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME); + int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT); + + // Return connected socket + return new ConfiguredGuacamoleSocket( + new InetGuacamoleSocket(hostname, port), + config, info + ); + + } + +} diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleGuacamoleConfigurationDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java similarity index 76% rename from guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleGuacamoleConfigurationDirectory.java rename to guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java index 686bda3ee..cc5ca3852 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleGuacamoleConfigurationDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionDirectory.java @@ -37,10 +37,13 @@ package net.sourceforge.guacamole.net.auth.simple; * * ***** END LICENSE BLOCK ***** */ +import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleSecurityException; +import net.sourceforge.guacamole.net.auth.Connection; import net.sourceforge.guacamole.net.auth.Directory; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; @@ -52,44 +55,50 @@ import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; * * @author Michael Jumper */ -public class SimpleGuacamoleConfigurationDirectory - implements Directory { +public class SimpleConnectionDirectory + implements Directory { /** - * The Map of GuacamoleConfigurations to provide access to. + * The Map of Connections to provide access to. */ - private Map configs; + private Map connections = + new HashMap(); /** - * Creates a new SimpleGuacamoleConfigurationDirectory which provides + * Creates a new SimpleConnectionDirectory which provides * access to the configurations contained within the given Map. * * @param configs The Map of GuacamoleConfigurations to provide access to. */ - public SimpleGuacamoleConfigurationDirectory( + public SimpleConnectionDirectory( Map configs) { - this.configs = configs; + + // Create connections for each config + for (Entry entry : configs.entrySet()) + connections.put(entry.getKey(), + new SimpleConnection(entry.getKey(), entry.getValue())); + } @Override - public GuacamoleConfiguration get(String identifier) + public Connection get(String identifier) throws GuacamoleException { - return configs.get(identifier); + return connections.get(identifier); } @Override public Set getIdentifiers() throws GuacamoleException { - return configs.keySet(); + return connections.keySet(); } @Override - public void add(String identifier, GuacamoleConfiguration config) + public void add(Connection connection) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } @Override - public void update(String identifier, GuacamoleConfiguration config) + public void update(Connection connection) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUser.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUser.java index 5d0172f40..40596d442 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUser.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUser.java @@ -43,7 +43,7 @@ import java.util.Set; import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleSecurityException; import net.sourceforge.guacamole.net.auth.AbstractUser; -import net.sourceforge.guacamole.net.auth.permission.GuacamoleConfigurationPermission; +import net.sourceforge.guacamole.net.auth.permission.ConnectionPermission; import net.sourceforge.guacamole.net.auth.permission.ObjectPermission; import net.sourceforge.guacamole.net.auth.permission.Permission; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; @@ -83,7 +83,7 @@ public class SimpleUser extends AbstractUser { for (String identifier : configs.keySet()) { // Create permission - Permission permission = new GuacamoleConfigurationPermission( + Permission permission = new ConnectionPermission( ObjectPermission.Type.READ, 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 ea2e8cdf0..7a4201545 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 @@ -39,6 +39,7 @@ package net.sourceforge.guacamole.net.auth.simple; import java.util.Map; import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.net.auth.Connection; import net.sourceforge.guacamole.net.auth.Directory; import net.sourceforge.guacamole.net.auth.User; import net.sourceforge.guacamole.net.auth.UserContext; @@ -60,14 +61,13 @@ public class SimpleUserContext implements UserContext { private final User self; /** - * The GuacamoleConfigurationDirectory with access only to those - * configurations that the User associated with this UserContext has - * read access to. + * The Directory with access only to those Connections that the User + * associated with this UserContext has access to. */ - private final Directory configDirectory; + private final Directory connectionDirectory; /** - * The UserDirectory with access only to the User associated with this + * The Directory with access only to the User associated with this * UserContext. */ private final Directory userDirectory; @@ -87,8 +87,8 @@ public class SimpleUserContext implements UserContext { this.self = self; - this.configDirectory = - new SimpleGuacamoleConfigurationDirectory(configs); + this.connectionDirectory = + new SimpleConnectionDirectory(configs); this.userDirectory = new SimpleUserDirectory(self); @@ -100,10 +100,9 @@ public class SimpleUserContext implements UserContext { } @Override - public Directory - getGuacamoleConfigurationDirectory() + public Directory getConnectionDirectory() throws GuacamoleException { - return configDirectory; + return connectionDirectory; } @Override diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java index baff1ba1c..ccaf23887 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleUserDirectory.java @@ -86,12 +86,12 @@ public class SimpleUserDirectory implements Directory { } @Override - public void add(String username, User user) throws GuacamoleException { + public void add(User user) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); } @Override - public void update(String username, User user) throws GuacamoleException { + public void update(User user) throws GuacamoleException { throw new GuacamoleSecurityException("Permission denied."); }