From 71c72085f8484b3bb35d4c5cf195c31b1b2564a2 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Tue, 23 Jul 2013 22:17:29 -0700 Subject: [PATCH] Ticket #263: Improved guacamole-ext and added ConnectionGroup mapper. --- .../mysql/MySQLAuthenticationProvider.java | 2 + .../net/auth/mysql/MySQLConnectionGroup.java | 140 ++++++ .../net/auth/mysql/MySQLUserContext.java | 13 +- .../mysql/service/ConnectionGroupService.java | 456 ++++++++++++++++++ .../src/main/resources/generatorConfig.xml | 10 + .../auth/simple/SimpleConnectionGroup.java | 87 ++++ .../SimpleConnectionGroupDirectory.java | 89 ++++ 7 files changed, 787 insertions(+), 10 deletions(-) create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java create mode 100644 guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroup.java create mode 100644 guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java index 122e18ef6..1c5c28fe7 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java @@ -47,6 +47,7 @@ import net.sourceforge.guacamole.GuacamoleException; import net.sourceforge.guacamole.net.auth.AuthenticationProvider; import net.sourceforge.guacamole.net.auth.Credentials; import net.sourceforge.guacamole.net.auth.UserContext; +import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionGroupMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionHistoryMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionParameterMapper; @@ -156,6 +157,7 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider { // Add MyBatis mappers addMapperClass(ConnectionHistoryMapper.class); addMapperClass(ConnectionMapper.class); + addMapperClass(ConnectionGroupMapper.class); addMapperClass(ConnectionParameterMapper.class); addMapperClass(ConnectionPermissionMapper.class); addMapperClass(SystemPermissionMapper.class); diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java new file mode 100644 index 000000000..18b042fa7 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnectionGroup.java @@ -0,0 +1,140 @@ + +package net.sourceforge.guacamole.net.auth.mysql; + +/* ***** 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-mysql. + * + * The Initial Developer of the Original Code is + * James Muehlner. + * 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 com.google.inject.Inject; +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.net.GuacamoleSocket; +import net.sourceforge.guacamole.net.auth.AbstractConnectionGroup; +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.protocol.GuacamoleClientInformation; + +/** + * A MySQL based implementation of the ConnectionGroup object. + * @author James Muehlner + */ +public class MySQLConnectionGroup extends AbstractConnectionGroup { + + /** + * The ID associated with this connection group in the database. + */ + private Integer connectionGroupID; + + /** + * The ID of the user who queried or created this connection group. + */ + private int userID; + + /** + * A Directory of connections that have this connection group as a parent. + */ + private Directory connectionDirectory; + + /** + * A Directory of connection groups that have this connection group as a parent. + */ + private Directory connectionGroupDirectory; + + /** + * Service for managing connection groups. + */ + //@Inject + //private ConnectionGroupService connectionGroupService; + + /** + * Create a default, empty connection group. + */ + public MySQLConnectionGroup() { + } + + /** + * Get the ID of the corresponding connection group record. + * @return The ID of the corresponding connection group, if any. + */ + public Integer getConnectionGroupID() { + return connectionGroupID; + } + + /** + * Sets the ID of the corresponding connection group record. + * @param connectionID The ID to assign to this connection group. + */ + public void setConnectionID(Integer connectionGroupID) { + this.connectionGroupID = connectionGroupID; + } + + /** + * Initialize from explicit values. + * + * @param connectionGroupID The ID of the associated database record, if any. + * @param identifier The unique identifier associated with this connection group. + * @param config The GuacamoleConfiguration associated with this connection. + * @param history All ConnectionRecords associated with this connection. + * @param userID The IID of the user who queried this connection. + */ + public void init(Integer connectionGroupID, String identifier, + Directory connectionDirectory, + Directory connectionGroupDirectory, + int userID) { + + this.connectionGroupID = connectionGroupID; + setIdentifier(identifier); + this.connectionDirectory = connectionDirectory; + this.connectionGroupDirectory = connectionGroupDirectory; + this.userID = userID; + + } + + @Override + public GuacamoleSocket connect(GuacamoleClientInformation info) throws GuacamoleException { + return connectionGroupService.connect(this, info, userID); + } + + @Override + public Directory getConnectionDirectory() throws GuacamoleException { + return connectionDirectory; + } + + @Override + public Directory getConnectionGroupDirectory() throws GuacamoleException { + return connectionGroupDirectory; + } + +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java index 94cc3991e..b0fa2a63f 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java @@ -40,6 +40,7 @@ package net.sourceforge.guacamole.net.auth.mysql; import com.google.inject.Inject; 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; import net.sourceforge.guacamole.net.auth.UserContext; @@ -64,13 +65,6 @@ public class MySQLUserContext implements UserContext { @Inject private UserDirectory userDirectory; - /** - * Connection directory restricted by the permissions of the user associated - * with this context. - */ - @Inject - private ConnectionDirectory connectionDirectory; - /** * Service for accessing users. */ @@ -85,7 +79,6 @@ public class MySQLUserContext implements UserContext { public void init(int user_id) { this.user_id = user_id; userDirectory.init(user_id); - connectionDirectory.init(user_id); } @Override @@ -99,8 +92,8 @@ public class MySQLUserContext implements UserContext { } @Override - public Directory getConnectionDirectory() throws GuacamoleException { - return connectionDirectory; + public ConnectionGroup getConnectionGroup() throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java new file mode 100644 index 000000000..7e1949ead --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionGroupService.java @@ -0,0 +1,456 @@ + +package net.sourceforge.guacamole.net.auth.mysql.service; + +/* ***** 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-mysql. + * + * The Initial Developer of the Original Code is + * James Muehlner. + * 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 com.google.common.collect.Lists; +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import net.sourceforge.guacamole.GuacamoleClientException; +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.net.GuacamoleSocket; +import net.sourceforge.guacamole.net.InetGuacamoleSocket; +import net.sourceforge.guacamole.net.auth.mysql.ActiveConnectionSet; +import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection; +import net.sourceforge.guacamole.net.auth.mysql.MySQLConnectionRecord; +import net.sourceforge.guacamole.net.auth.mysql.MySQLGuacamoleSocket; +import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionHistoryMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionParameterMapper; +import net.sourceforge.guacamole.net.auth.mysql.model.Connection; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionExample; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionHistory; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionHistoryExample; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionParameter; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionParameterExample; +import net.sourceforge.guacamole.net.auth.mysql.properties.MySQLGuacamoleProperties; +import net.sourceforge.guacamole.properties.GuacamoleProperties; +import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket; +import net.sourceforge.guacamole.protocol.GuacamoleClientInformation; +import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; +import org.apache.ibatis.session.RowBounds; + +/** + * Service which provides convenience methods for creating, retrieving, and + * manipulating connections. + * + * @author Michael Jumper, James Muehlner + */ +public class ConnectionGroupService { + + /** + * DAO for accessing connections. + */ + @Inject + private ConnectionMapper connectionDAO; + + /** + * DAO for accessing connection parameters. + */ + @Inject + private ConnectionParameterMapper connectionParameterDAO; + + /** + * DAO for accessing connection history. + */ + @Inject + private ConnectionHistoryMapper connectionHistoryDAO; + + /** + * Provider which creates MySQLConnections. + */ + @Inject + private Provider mySQLConnectionProvider; + + /** + * Provider which creates MySQLGuacamoleSockets. + */ + @Inject + private Provider mySQLGuacamoleSocketProvider; + + /** + * Set of all currently active connections. + */ + @Inject + private ActiveConnectionSet activeConnectionSet; + + /** + * Service managing users. + */ + @Inject + private UserService userService; + + /** + * Retrieves the connection having the given name from the database. + * + * @param name The name of the connection to return. + * @param userID The ID of the user who queried this connection. + * @return The connection having the given name, or null if no such + * connection could be found. + */ + public MySQLConnection retrieveConnection(String name, int userID) { + + // Query connection by connection identifier (name) + ConnectionExample example = new ConnectionExample(); + example.createCriteria().andConnection_nameEqualTo(name); + List connections = + connectionDAO.selectByExample(example); + + // If no connection found, return null + if(connections.isEmpty()) + return null; + + // Assert only one connection found + assert connections.size() == 1 : "Multiple connections with same name."; + + // Otherwise, return found connection + return toMySQLConnection(connections.get(0), userID); + + } + + /** + * Retrieves the connection having the given ID from the database. + * + * @param id The ID of the connection to retrieve. + * @param userID The ID of the user who queried this connection. + * @return The connection having the given ID, or null if no such + * connection was found. + */ + public MySQLConnection retrieveConnection(int id, int userID) { + + // Query connection by ID + Connection connection = connectionDAO.selectByPrimaryKey(id); + + // If no connection found, return null + if(connection == null) + return null; + + // Otherwise, return found connection + return toMySQLConnection(connection, userID); + } + + /** + * Retrieves a translation map of connection names to their corresponding + * IDs. + * + * @param ids The IDs of the connections to retrieve the names of. + * @return A map containing the names of all connections and their + * corresponding IDs. + */ + public Map translateNames(List ids) { + + // If no IDs given, just return empty map + if (ids.isEmpty()) + return Collections.EMPTY_MAP; + + // Map of all names onto their corresponding IDs. + Map names = new HashMap(); + + // Get all connections having the given IDs + ConnectionExample example = new ConnectionExample(); + example.createCriteria().andConnection_idIn(ids); + List connections = connectionDAO.selectByExample(example); + + // Produce set of names + for (Connection connection : connections) + names.put(connection.getConnection_name(), + connection.getConnection_id()); + + return names; + + } + + /** + * Retrieves a map of all connection names for the given IDs. + * + * @param ids The IDs of the connections to retrieve the names of. + * @return A map containing the names of all connections and their + * corresponding IDs. + */ + public Map retrieveNames(Collection ids) { + + // If no IDs given, just return empty map + if (ids.isEmpty()) + return Collections.EMPTY_MAP; + + // Map of all names onto their corresponding IDs. + Map names = new HashMap(); + + // Get all connections having the given IDs + ConnectionExample example = new ConnectionExample(); + example.createCriteria().andConnection_idIn(Lists.newArrayList(ids)); + List connections = connectionDAO.selectByExample(example); + + // Produce set of names + for (Connection connection : connections) + names.put(connection.getConnection_id(), + connection.getConnection_name()); + + return names; + + } + + /** + * Convert the given database-retrieved Connection into a MySQLConnection. + * The parameters of the given connection will be read and added to the + * MySQLConnection in the process. + * + * @param connection The connection to convert. + * @param userID The user who queried this connection. + * @return A new MySQLConnection containing all data associated with the + * specified connection. + */ + private MySQLConnection toMySQLConnection(Connection connection, int userID) { + + // Build configuration + GuacamoleConfiguration config = new GuacamoleConfiguration(); + + // Query parameters for configuration + ConnectionParameterExample connectionParameterExample = new ConnectionParameterExample(); + connectionParameterExample.createCriteria().andConnection_idEqualTo(connection.getConnection_id()); + List connectionParameters = + connectionParameterDAO.selectByExample(connectionParameterExample); + + // Set protocol + config.setProtocol(connection.getProtocol()); + + // Set all values for all parameters + for (ConnectionParameter parameter : connectionParameters) + config.setParameter(parameter.getParameter_name(), + parameter.getParameter_value()); + + // Create new MySQLConnection from retrieved data + MySQLConnection mySQLConnection = mySQLConnectionProvider.get(); + mySQLConnection.init( + connection.getConnection_id(), + connection.getConnection_name(), + config, + retrieveHistory(connection.getConnection_id()), + userID + ); + + return mySQLConnection; + + } + + /** + * Retrieves the history of the connection having the given ID. + * + * @param connectionID The ID of the connection to retrieve the history of. + * @return A list of MySQLConnectionRecord documenting the history of this + * connection. + */ + public List retrieveHistory(int connectionID) { + + // Retrieve history records relating to given connection ID + ConnectionHistoryExample example = new ConnectionHistoryExample(); + example.createCriteria().andConnection_idEqualTo(connectionID); + + // We want to return the newest records first + example.setOrderByClause("start_date DESC"); + + // Set the maximum number of history records returned to 100 + RowBounds rowBounds = new RowBounds(0, 100); + + // Retrieve all connection history entries + List connectionHistories = + connectionHistoryDAO.selectByExampleWithRowbounds(example, rowBounds); + + // Convert history entries to connection records + List connectionRecords = new ArrayList(); + Set userIDSet = new HashSet(); + for(ConnectionHistory history : connectionHistories) { + userIDSet.add(history.getUser_id()); + } + + // Get all the usernames for the users who are in the history + Map usernameMap = userService.retrieveUsernames(userIDSet); + + // Create the new ConnectionRecords + for(ConnectionHistory history : connectionHistories) { + Date startDate = history.getStart_date(); + Date endDate = history.getEnd_date(); + String username = usernameMap.get(history.getUser_id()); + MySQLConnectionRecord connectionRecord = new MySQLConnectionRecord(startDate, endDate, username); + connectionRecords.add(connectionRecord); + } + + return connectionRecords; + } + + /** + * Create a MySQLGuacamoleSocket using the provided connection. + * + * @param connection The connection to use when connecting the socket. + * @param info The information to use when performing the connection + * handshake. + * @param userID The ID of the user who is connecting to the socket. + * @return The connected socket. + * @throws GuacamoleException If an error occurs while connecting the + * socket. + */ + public MySQLGuacamoleSocket connect(MySQLConnection connection, + GuacamoleClientInformation info, int userID) + throws GuacamoleException { + + // If the given connection is active, and multiple simultaneous + // connections are not allowed, disallow connection + if(GuacamoleProperties.getProperty( + MySQLGuacamoleProperties.MYSQL_DISALLOW_SIMULTANEOUS_CONNECTIONS, false) + && activeConnectionSet.isActive(connection.getConnectionID())) + throw new GuacamoleClientException("Cannot connect. This connection is in use."); + + // Get guacd connection information + String host = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_HOSTNAME); + int port = GuacamoleProperties.getProperty(GuacamoleProperties.GUACD_PORT); + + // Get socket + GuacamoleSocket socket = new ConfiguredGuacamoleSocket( + new InetGuacamoleSocket(host, port), + connection.getConfiguration(), info + ); + + // Mark this connection as active + int historyID = activeConnectionSet.openConnection(connection.getConnectionID(), userID); + + // Return new MySQLGuacamoleSocket + MySQLGuacamoleSocket mySQLGuacamoleSocket = mySQLGuacamoleSocketProvider.get(); + mySQLGuacamoleSocket.init(socket, connection.getConnectionID(), historyID); + return mySQLGuacamoleSocket; + + } + + /** + * Creates a new connection having the given name and protocol. + * + * @param name The name to assign to the new connection. + * @param protocol The protocol to assign to the new connection. + * @param userID The ID of the user who created this connection. + * @return A new MySQLConnection containing the data of the newly created + * connection. + */ + public MySQLConnection createConnection(String name, String protocol, int userID) { + + // Initialize database connection + Connection connection = new Connection(); + connection.setConnection_name(name); + connection.setProtocol(protocol); + + // Create connection + connectionDAO.insert(connection); + return toMySQLConnection(connection, userID); + + } + + /** + * Deletes the connection having the given ID from the database. + * @param id The ID of the connection to delete. + */ + public void deleteConnection(int id) { + connectionDAO.deleteByPrimaryKey(id); + } + + /** + * Updates the connection in the database corresponding to the given + * MySQLConnection. + * + * @param mySQLConnection The MySQLConnection to update (save) to the + * database. This connection must already exist. + */ + public void updateConnection(MySQLConnection mySQLConnection) { + + // Populate connection + Connection connection = new Connection(); + connection.setConnection_id(mySQLConnection.getConnectionID()); + connection.setConnection_name(mySQLConnection.getIdentifier()); + connection.setProtocol(mySQLConnection.getConfiguration().getProtocol()); + + // Update the connection in the database + connectionDAO.updateByPrimaryKeySelective(connection); + + } + + /** + * Get the names of all the connections defined in the system. + * + * @return A Set of names of all the connections defined in the system. + */ + public Set getAllConnectionNames() { + + // Set of all present connection names + Set names = new HashSet(); + + // Query all connection names + List connections = + connectionDAO.selectByExample(new ConnectionExample()); + for (Connection connection : connections) + names.add(connection.getConnection_name()); + + return names; + + } + + /** + * Get the connection IDs of all the connections defined in the system. + * + * @return A list of connection IDs of all the connections defined in the system. + */ + public List getAllConnectionIDs() { + + // Set of all present connection IDs + List connectionIDs = new ArrayList(); + + // Query all connection IDs + List connections = + connectionDAO.selectByExample(new ConnectionExample()); + for (Connection connection : connections) + connectionIDs.add(connection.getConnection_id()); + + return connectionIDs; + + } + +} diff --git a/extensions/guacamole-auth-mysql/src/main/resources/generatorConfig.xml b/extensions/guacamole-auth-mysql/src/main/resources/generatorConfig.xml index 879ed22c5..9ea226a7d 100644 --- a/extensions/guacamole-auth-mysql/src/main/resources/generatorConfig.xml +++ b/extensions/guacamole-auth-mysql/src/main/resources/generatorConfig.xml @@ -39,6 +39,16 @@ sqlStatement="SELECT LAST_INSERT_ID()"/> + + + + +
+ connectionDirectory; + private final Directory connectionGroupDirectory; + + + public SimpleConnectionGroup(Directory connectionDirectory, + Directory connectionGroupDirectory) { + this.connectionDirectory = connectionDirectory; + this.connectionGroupDirectory = connectionGroupDirectory; + } + + @Override + public Directory getConnectionDirectory() + throws GuacamoleException { + return connectionDirectory; + } + + @Override + public Directory getConnectionGroupDirectory() + throws GuacamoleException { + return connectionGroupDirectory; + } + + @Override + public GuacamoleSocket connect(GuacamoleClientInformation info) + throws GuacamoleException { + throw new GuacamoleSecurityException("Permission denied."); + } + +} 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 new file mode 100644 index 000000000..38cd107bc --- /dev/null +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/net/auth/simple/SimpleConnectionGroupDirectory.java @@ -0,0 +1,89 @@ + +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): James Muehlner + * + * 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 java.util.Collections; +import java.util.Set; +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.GuacamoleSecurityException; +import net.sourceforge.guacamole.net.auth.ConnectionGroup; +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. + * + * @author James Muehlner + */ +public class SimpleConnectionGroupDirectory + implements Directory { + + /** + * Creates a new SimpleConnectionGroupDirectory */ + public SimpleConnectionGroupDirectory() {} + + @Override + public ConnectionGroup get(String identifier) + throws GuacamoleException { + return null; + } + + @Override + public Set getIdentifiers() throws GuacamoleException { + return Collections.EMPTY_SET; + } + + @Override + public void add(ConnectionGroup connectionGroup) + throws GuacamoleException { + throw new GuacamoleSecurityException("Permission denied."); + } + + @Override + public void update(ConnectionGroup connectionGroup) + throws GuacamoleException { + throw new GuacamoleSecurityException("Permission denied."); + } + + @Override + public void remove(String identifier) throws GuacamoleException { + throw new GuacamoleSecurityException("Permission denied."); + } + +}