diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionSet.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionSet.java new file mode 100644 index 000000000..769b7f02f --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/ActiveConnectionSet.java @@ -0,0 +1,47 @@ +/* ***** 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 ***** */ +package net.sourceforge.guacamole.net.auth.mysql; + +import java.util.HashSet; +import java.util.Set; + +/** + * Represents the set of currently active Connections. Whenever a socket is opened, + * the connection ID should be added to this set, and whenever a socket is closed, + * the connection ID should be removed from this set. + * @author dagger10k + */ +public class ActiveConnectionSet extends HashSet implements Set {} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLGuacamoleSocket.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLGuacamoleSocket.java new file mode 100644 index 000000000..f35d76ae5 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLGuacamoleSocket.java @@ -0,0 +1,87 @@ +/* ***** 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 ***** */ +package net.sourceforge.guacamole.net.auth.mysql; + +import com.google.inject.Inject; +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.io.GuacamoleReader; +import net.sourceforge.guacamole.io.GuacamoleWriter; +import net.sourceforge.guacamole.net.GuacamoleSocket; +import net.sourceforge.guacamole.protocol.ConfiguredGuacamoleSocket; + +/** + * A MySQL specific wrapper around a ConfiguredGuacamoleSocket. + * @author James Muehlner + */ +public class MySQLGuacamoleSocket implements GuacamoleSocket { + + @Inject + ActiveConnectionSet activeConnectionSet; + + private ConfiguredGuacamoleSocket socket; + private int connectionID; + + /** + * Initialize this MySQLGuacamoleSocket with the provided ConfiguredGuacamoleSocket. + * @param socket the ConfiguredGuacamoleSocket to wrap. + */ + public void init(ConfiguredGuacamoleSocket socket, int connectionID) { + this.socket = socket; + this.connectionID = connectionID; + } + + @Override + public GuacamoleReader getReader() { + return socket.getReader(); + } + + @Override + public GuacamoleWriter getWriter() { + return socket.getWriter(); + } + + @Override + public void close() throws GuacamoleException { + socket.close(); + //mark this connection as inactive + activeConnectionSet.remove(connectionID); + } + + @Override + public boolean isOpen() { + return socket.isOpen(); + } +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/utility/ConfigurationTranslationUtility.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/utility/ConfigurationTranslationUtility.java new file mode 100644 index 000000000..98f3c2b28 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/utility/ConfigurationTranslationUtility.java @@ -0,0 +1,88 @@ +/* ***** 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 ***** */ +package net.sourceforge.guacamole.net.auth.mysql.utility; + +import java.util.ArrayList; +import java.util.List; +import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionParameter; +import net.sourceforge.guacamole.protocol.GuacamoleConfiguration; + +/** + * Provides functions for translating between GuacamoleConfiguration objects + * and a collection of ConnectionParameter database records. + * @author James Muehlner + */ +public class ConfigurationTranslationUtility { + + /** + * Get a GuacamoleConfiguration based on the provided protocol and parameters. + * @param protocol the protocol used (VNC, RDP, etc) + * @param parameters the parameter database records to translate + * @return + */ + public GuacamoleConfiguration getConfiguration(String protocol, Iterable parameters) { + GuacamoleConfiguration configuration = new GuacamoleConfiguration(); + configuration.setProtocol(protocol); + + for(ConnectionParameter parameter : parameters) { + configuration.setParameter(parameter.getParameter_name(), parameter.getParameter_value()); + } + + return configuration; + } + + /** + * Creates a list of ConnectionParameter database records based on the provided connectionID and GuacamoleConfiguration. + * @param connectionID the ID of the connection that these parameters are for + * @param configuration the configuration to pull the parameter values from + * @return + */ + public List getConnectionParameters(int connectionID, GuacamoleConfiguration configuration) { + List connectionParameters = new ArrayList(); + + for(String parameterName : configuration.getParameterNames()) { + ConnectionParameter connectionParameter = new ConnectionParameter(); + String parameterValue = configuration.getParameter(parameterName); + connectionParameter.setConnection_id(connectionID); + connectionParameter.setParameter_name(parameterName); + connectionParameter.setParameter_value(parameterValue); + + connectionParameters.add(connectionParameter); + } + + return connectionParameters; + } +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/utility/sedPPrchI b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/utility/sedPPrchI new file mode 100644 index 000000000..e69de29bb