Refactor Directory interface to require objects which contain their own identifiers. Refactor to Connection directory rather than GuacamoleConfiguration directory.

This commit is contained in:
Michael Jumper
2013-01-31 14:29:24 -08:00
parent ef8ec1e123
commit d95fe6fa53
9 changed files with 163 additions and 51 deletions

View File

@@ -48,6 +48,9 @@ import net.sourceforge.guacamole.GuacamoleException;
* function. * function.
* *
* @author Michael Jumper * @author Michael Jumper
* @param <IdentifierType> The type of identifier used to identify objects
* stored within this Directory.
* @param <ObjectType> The type of objects stored within this Directory.
*/ */
public interface Directory<IdentifierType, ObjectType> { public interface Directory<IdentifierType, ObjectType> {
@@ -82,13 +85,12 @@ public interface Directory<IdentifierType, ObjectType> {
/** /**
* Adds the given object to the overall set. * Adds the given object to the overall set.
* *
* @param identifier The identifier to use when adding the object.
* @param object The object to add. * @param object The object to add.
* *
* @throws GuacamoleException If an error occurs while adding the object , or * @throws GuacamoleException If an error occurs while adding the object , or
* if adding the object is not allowed. * if adding the object is not allowed.
*/ */
void add(IdentifierType identifier, ObjectType object) void add(ObjectType object)
throws GuacamoleException; throws GuacamoleException;
/** /**
@@ -101,7 +103,7 @@ public interface Directory<IdentifierType, ObjectType> {
* @throws GuacamoleException If an error occurs while updating the object, * @throws GuacamoleException If an error occurs while updating the object,
* or if updating the object is not allowed. * or if updating the object is not allowed.
*/ */
void update(IdentifierType identifier, ObjectType object) void update(ObjectType object)
throws GuacamoleException; throws GuacamoleException;
/** /**

View File

@@ -38,7 +38,6 @@ package net.sourceforge.guacamole.net.auth;
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
/** /**
* The context of an active user. The functions of this class enforce all * The context of an active user. The functions of this class enforce all
@@ -58,31 +57,30 @@ public interface UserContext {
User self(); 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 * users, but only as allowed by the permissions given to the user of this
* UserContext. * UserContext.
* *
* @return A UserDirectory whose operations are bound by the restrictions * @return A Directory whose operations are bound by the restrictions
* of this UserContext. * of this UserContext.
* *
* @throws GuacamoleException If an error occurs while creating the * @throws GuacamoleException If an error occurs while creating the
* UserDirectory. * Directory.
*/ */
Directory<String, User> getUserDirectory() throws GuacamoleException; Directory<String, User> getUserDirectory() throws GuacamoleException;
/** /**
* Retrieves a GuacamoleConfigurationDirectory which can be used to view * Retrieves a Directory which can be used to view and manipulate
* and manipulate configurations, but only as allowed by the permissions * connections and their configurations, but only as allowed by the
* given to the user of this UserContext. * permissions given to the user of this UserContext.
* *
* @return A GuacamoleConfigurationdirectory whose operations are bound by * @return A Directory whose operations are bound by the restrictions
* the restrictions of this UserContext. * of this UserContext.
* *
* @throws GuacamoleException If an error occurs while creating the * @throws GuacamoleException If an error occurs while creating the
* GuacamoleConfigurationDirectory. * Directory.
*/ */
Directory<String, GuacamoleConfiguration> Directory<String, Connection> getConnectionDirectory()
getGuacamoleConfigurationDirectory()
throws GuacamoleException; throws GuacamoleException;
} }

View File

@@ -43,7 +43,7 @@ package net.sourceforge.guacamole.net.auth.permission;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public class GuacamoleConfigurationDirectoryPermission public class ConnectionDirectoryPermission
implements SystemPermission { implements SystemPermission {
/** /**
@@ -52,12 +52,12 @@ public class GuacamoleConfigurationDirectoryPermission
private Type type; private Type type;
/** /**
* Creates a new GuacamoleConfigurationDirectoryPermission with the given * Creates a new ConnectionDirectoryPermission with the given
* type. * type.
* *
* @param type The type of operation controlled by this permission. * @param type The type of operation controlled by this permission.
*/ */
public GuacamoleConfigurationDirectoryPermission(Type type) { public ConnectionDirectoryPermission(Type type) {
this.type = type; this.type = type;
} }
@@ -78,8 +78,8 @@ public class GuacamoleConfigurationDirectoryPermission
if (obj == null) return false; if (obj == null) return false;
if (getClass() != obj.getClass()) return false; if (getClass() != obj.getClass()) return false;
final GuacamoleConfigurationDirectoryPermission other = final ConnectionDirectoryPermission other =
(GuacamoleConfigurationDirectoryPermission) obj; (ConnectionDirectoryPermission) obj;
// Compare types // Compare types
if (type != other.type) if (type != other.type)

View File

@@ -46,7 +46,7 @@ package net.sourceforge.guacamole.net.auth.permission;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public class GuacamoleConfigurationPermission public class ConnectionPermission
implements ObjectPermission<String> { implements ObjectPermission<String> {
/** /**
@@ -61,7 +61,7 @@ public class GuacamoleConfigurationPermission
private Type type; 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 * and identifier. The identifier must be the unique identifier assigned
* to the GuacamoleConfiguration by the AuthenticationProvider in use. * to the GuacamoleConfiguration by the AuthenticationProvider in use.
* *
@@ -69,7 +69,7 @@ public class GuacamoleConfigurationPermission
* @param identifier The identifier of the GuacamoleConfiguration associated * @param identifier The identifier of the GuacamoleConfiguration associated
* with the operation affected by this permission. * with the operation affected by this permission.
*/ */
public GuacamoleConfigurationPermission(Type type, String identifier) { public ConnectionPermission(Type type, String identifier) {
this.identifier = identifier; this.identifier = identifier;
this.type = type; this.type = type;
@@ -101,8 +101,8 @@ public class GuacamoleConfigurationPermission
if (obj == null) return false; if (obj == null) return false;
if (getClass() != obj.getClass()) return false; if (getClass() != obj.getClass()) return false;
final GuacamoleConfigurationPermission other = final ConnectionPermission other =
(GuacamoleConfigurationPermission) obj; (ConnectionPermission) obj;
// Not equal if different type // Not equal if different type
if (this.type != other.type) if (this.type != other.type)

View File

@@ -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
);
}
}

View File

@@ -37,10 +37,13 @@ package net.sourceforge.guacamole.net.auth.simple;
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.GuacamoleSecurityException; import net.sourceforge.guacamole.GuacamoleSecurityException;
import net.sourceforge.guacamole.net.auth.Connection;
import net.sourceforge.guacamole.net.auth.Directory; import net.sourceforge.guacamole.net.auth.Directory;
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
@@ -52,44 +55,50 @@ import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
* *
* @author Michael Jumper * @author Michael Jumper
*/ */
public class SimpleGuacamoleConfigurationDirectory public class SimpleConnectionDirectory
implements Directory<String, GuacamoleConfiguration> { implements Directory<String, Connection> {
/** /**
* The Map of GuacamoleConfigurations to provide access to. * The Map of Connections to provide access to.
*/ */
private Map<String, GuacamoleConfiguration> configs; private Map<String, Connection> connections =
new HashMap<String, Connection>();
/** /**
* Creates a new SimpleGuacamoleConfigurationDirectory which provides * Creates a new SimpleConnectionDirectory which provides
* access to the configurations contained within the given Map. * access to the configurations contained within the given Map.
* *
* @param configs The Map of GuacamoleConfigurations to provide access to. * @param configs The Map of GuacamoleConfigurations to provide access to.
*/ */
public SimpleGuacamoleConfigurationDirectory( public SimpleConnectionDirectory(
Map<String, GuacamoleConfiguration> configs) { Map<String, GuacamoleConfiguration> configs) {
this.configs = configs;
// Create connections for each config
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet())
connections.put(entry.getKey(),
new SimpleConnection(entry.getKey(), entry.getValue()));
} }
@Override @Override
public GuacamoleConfiguration get(String identifier) public Connection get(String identifier)
throws GuacamoleException { throws GuacamoleException {
return configs.get(identifier); return connections.get(identifier);
} }
@Override @Override
public Set<String> getIdentifiers() throws GuacamoleException { public Set<String> getIdentifiers() throws GuacamoleException {
return configs.keySet(); return connections.keySet();
} }
@Override @Override
public void add(String identifier, GuacamoleConfiguration config) public void add(Connection connection)
throws GuacamoleException { throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }
@Override @Override
public void update(String identifier, GuacamoleConfiguration config) public void update(Connection connection)
throws GuacamoleException { throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }

View File

@@ -43,7 +43,7 @@ import java.util.Set;
import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.GuacamoleSecurityException; import net.sourceforge.guacamole.GuacamoleSecurityException;
import net.sourceforge.guacamole.net.auth.AbstractUser; 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.ObjectPermission;
import net.sourceforge.guacamole.net.auth.permission.Permission; import net.sourceforge.guacamole.net.auth.permission.Permission;
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
@@ -83,7 +83,7 @@ public class SimpleUser extends AbstractUser {
for (String identifier : configs.keySet()) { for (String identifier : configs.keySet()) {
// Create permission // Create permission
Permission permission = new GuacamoleConfigurationPermission( Permission permission = new ConnectionPermission(
ObjectPermission.Type.READ, ObjectPermission.Type.READ,
identifier identifier
); );

View File

@@ -39,6 +39,7 @@ package net.sourceforge.guacamole.net.auth.simple;
import java.util.Map; import java.util.Map;
import net.sourceforge.guacamole.GuacamoleException; 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.Directory;
import net.sourceforge.guacamole.net.auth.User; import net.sourceforge.guacamole.net.auth.User;
import net.sourceforge.guacamole.net.auth.UserContext; import net.sourceforge.guacamole.net.auth.UserContext;
@@ -60,14 +61,13 @@ public class SimpleUserContext implements UserContext {
private final User self; private final User self;
/** /**
* The GuacamoleConfigurationDirectory with access only to those * The Directory with access only to those Connections that the User
* configurations that the User associated with this UserContext has * associated with this UserContext has access to.
* read access to.
*/ */
private final Directory<String, GuacamoleConfiguration> configDirectory; private final Directory<String, Connection> connectionDirectory;
/** /**
* The UserDirectory with access only to the User associated with this * The Directory with access only to the User associated with this
* UserContext. * UserContext.
*/ */
private final Directory<String, User> userDirectory; private final Directory<String, User> userDirectory;
@@ -87,8 +87,8 @@ public class SimpleUserContext implements UserContext {
this.self = self; this.self = self;
this.configDirectory = this.connectionDirectory =
new SimpleGuacamoleConfigurationDirectory(configs); new SimpleConnectionDirectory(configs);
this.userDirectory = new SimpleUserDirectory(self); this.userDirectory = new SimpleUserDirectory(self);
@@ -100,10 +100,9 @@ public class SimpleUserContext implements UserContext {
} }
@Override @Override
public Directory<String, GuacamoleConfiguration> public Directory<String, Connection> getConnectionDirectory()
getGuacamoleConfigurationDirectory()
throws GuacamoleException { throws GuacamoleException {
return configDirectory; return connectionDirectory;
} }
@Override @Override

View File

@@ -86,12 +86,12 @@ public class SimpleUserDirectory implements Directory<String, User> {
} }
@Override @Override
public void add(String username, User user) throws GuacamoleException { public void add(User user) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }
@Override @Override
public void update(String username, User user) throws GuacamoleException { public void update(User user) throws GuacamoleException {
throw new GuacamoleSecurityException("Permission denied."); throw new GuacamoleSecurityException("Permission denied.");
} }