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 52487acb8..975e42bee 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 @@ -30,6 +30,7 @@ import com.google.inject.Module; import com.google.inject.name.Names; import java.util.Properties; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.ParameterMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.SystemPermissionMapper; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.net.auth.AuthenticationProvider; @@ -46,6 +47,8 @@ import net.sourceforge.guacamole.net.auth.mysql.service.SystemPermissionService; import net.sourceforge.guacamole.net.auth.mysql.service.UserService; import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; +import org.glyptodon.guacamole.environment.Environment; +import org.glyptodon.guacamole.environment.LocalEnvironment; import org.mybatis.guice.MyBatisModule; import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider; import org.mybatis.guice.datasource.helper.JdbcHelper; @@ -96,16 +99,19 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider { */ public MySQLAuthenticationProvider() throws GuacamoleException { + // Get local environment + final Environment environment = new LocalEnvironment(); + final Properties myBatisProperties = new Properties(); final Properties driverProperties = new Properties(); // Set the mysql properties for MyBatis. myBatisProperties.setProperty("mybatis.environment.id", "guacamole"); - myBatisProperties.setProperty("JDBC.host", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_HOSTNAME)); - myBatisProperties.setProperty("JDBC.port", String.valueOf(GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PORT))); - myBatisProperties.setProperty("JDBC.schema", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_DATABASE)); - myBatisProperties.setProperty("JDBC.username", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_USERNAME)); - myBatisProperties.setProperty("JDBC.password", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PASSWORD)); + myBatisProperties.setProperty("JDBC.host", environment.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_HOSTNAME)); + myBatisProperties.setProperty("JDBC.port", String.valueOf(environment.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PORT))); + myBatisProperties.setProperty("JDBC.schema", environment.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_DATABASE)); + myBatisProperties.setProperty("JDBC.username", environment.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_USERNAME)); + myBatisProperties.setProperty("JDBC.password", environment.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PASSWORD)); myBatisProperties.setProperty("JDBC.autoCommit", "false"); myBatisProperties.setProperty("mybatis.pooled.pingEnabled", "true"); myBatisProperties.setProperty("mybatis.pooled.pingQuery", "SELECT 1"); @@ -137,21 +143,25 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider { // Add MyBatis mappers addMapperClass(ConnectionMapper.class); + addMapperClass(ParameterMapper.class); addMapperClass(SystemPermissionMapper.class); addMapperClass(UserMapper.class); - // Bind interfaces + // Bind core implementations of guacamole-ext classes + bind(Environment.class).toInstance(environment); bind(ConnectionDirectory.class); - bind(ConnectionService.class); bind(MySQLConnection.class); bind(MySQLUser.class); bind(MySQLUserContext.class); bind(MySQLRootConnectionGroup.class); bind(MySQLSystemPermissionSet.class); + bind(UserDirectory.class); + + // Bind services + bind(ConnectionService.class); bind(PasswordEncryptionService.class).to(SHA256PasswordEncryptionService.class); bind(SaltService.class).to(SecureRandomSaltService.class); bind(SystemPermissionService.class); - bind(UserDirectory.class); bind(UserService.class); } diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.java new file mode 100644 index 000000000..9e40608c3 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package net.sourceforge.guacamole.net.auth.mysql.dao; + +import java.util.Collection; +import net.sourceforge.guacamole.net.auth.mysql.model.ParameterModel; +import org.apache.ibatis.annotations.Param; + +/** + * Mapper for connection parameter objects. + * + * @author Michael Jumper + */ +public interface ParameterMapper { + + /** + * Returns a collection of all parameters associated with the connection + * having the given identifier. + * + * @param identifier + * The identifier of the connection whose parameters are to be + * retrieved. + * + * @return + * A collection of all parameters associated with the connection + * having the given identifier. This collection will be empty if no + * such connection exists. + */ + Collection select(@Param("identifier") String identifier); + +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/model/ParameterModel.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/model/ParameterModel.java new file mode 100644 index 000000000..6764269c5 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/model/ParameterModel.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package net.sourceforge.guacamole.net.auth.mysql.model; + +/** + * A single parameter name/value pair belonging to a connection. + * + * @author Michael Jumper + */ +public class ParameterModel { + + /** + * The identifier of the connection associated with this parameter. + */ + private String connectionIdentifier; + + /** + * The name of the parameter. + */ + private String name; + + /** + * The value the parameter is set to. + */ + private String value; + + /** + * Returns the identifier of the connection associated with this parameter. + * + * @return + * The identifier of the connection associated with this parameter. + */ + public String getConnectionIdentifier() { + return connectionIdentifier; + } + + /** + * Sets the identifier of the connection associated with this parameter. + * + * @param connectionIdentifier + * The identifier of the connection to associate with this parameter. + */ + public void setConnectionIdentifier(String connectionIdentifier) { + this.connectionIdentifier = connectionIdentifier; + } + + /** + * Returns the name of this parameter. + * + * @return + * The name of this parameter. + */ + public String getName() { + return name; + } + + /** + * Sets the name of this parameter. + * + * @param name + * The name of this parameter. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the value of this parameter. + * + * @return + * The value of this parameter. + */ + public String getValue() { + return value; + } + + /** + * Sets the value of this parameter. + * + * @param value + * The value of this parameter. + */ + public void setValue(String value) { + this.value = value; + } + +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java index fe73f6145..ecc450b99 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java @@ -24,23 +24,29 @@ package net.sourceforge.guacamole.net.auth.mysql.service; import com.google.inject.Inject; import com.google.inject.Provider; +import java.util.Collection; import java.util.Set; import net.sourceforge.guacamole.net.auth.mysql.AuthenticatedUser; import net.sourceforge.guacamole.net.auth.mysql.MySQLConnection; import net.sourceforge.guacamole.net.auth.mysql.dao.ConnectionMapper; import net.sourceforge.guacamole.net.auth.mysql.dao.DirectoryObjectMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.ParameterMapper; import net.sourceforge.guacamole.net.auth.mysql.model.ConnectionModel; +import net.sourceforge.guacamole.net.auth.mysql.model.ParameterModel; import org.glyptodon.guacamole.GuacamoleClientException; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleSecurityException; -import org.glyptodon.guacamole.GuacamoleUnsupportedException; +import org.glyptodon.guacamole.environment.Environment; import org.glyptodon.guacamole.net.GuacamoleSocket; +import org.glyptodon.guacamole.net.InetGuacamoleSocket; import org.glyptodon.guacamole.net.auth.Connection; import org.glyptodon.guacamole.net.auth.permission.ObjectPermission; import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet; import org.glyptodon.guacamole.net.auth.permission.SystemPermission; import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet; +import org.glyptodon.guacamole.protocol.ConfiguredGuacamoleSocket; import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; +import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; /** * Service which provides convenience methods for creating, retrieving, and @@ -50,12 +56,24 @@ import org.glyptodon.guacamole.protocol.GuacamoleClientInformation; */ public class ConnectionService extends DirectoryObjectService { + /** + * The environment of the Guacamole server. + */ + @Inject + private Environment environment; + /** * Mapper for accessing connections. */ @Inject private ConnectionMapper connectionMapper; + /** + * Mapper for accessing connection parameters. + */ + @Inject + private ParameterMapper parameterMapper; + /** * Provider for creating connections. */ @@ -187,10 +205,32 @@ public class ConnectionService extends DirectoryObjectService parameters = parameterMapper.select(identifier); + for (ParameterModel parameter : parameters) + config.setParameter(parameter.getName(), parameter.getValue()); + + // Return new socket + return new ConfiguredGuacamoleSocket( + new InetGuacamoleSocket( + environment.getRequiredProperty(Environment.GUACD_HOSTNAME), + environment.getRequiredProperty(Environment.GUACD_PORT) + ), + config + ); + } // The user does not have permission to connect diff --git a/extensions/guacamole-auth-mysql/src/main/resources/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.xml b/extensions/guacamole-auth-mysql/src/main/resources/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.xml new file mode 100644 index 000000000..05d48b54a --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/resources/net/sourceforge/guacamole/net/auth/mysql/dao/ParameterMapper.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file