From af9fccd7880346903b503cba6fe79d35ad142dfe Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Mon, 11 Feb 2013 00:26:30 -0800 Subject: [PATCH] Ticket #269: Added guice injection framework for ease of transaction management. --- extensions/guacamole-auth-mysql/.README.swp | Bin 0 -> 12288 bytes extensions/guacamole-auth-mysql/pom.xml | 7 ++ .../mysql/MySQLAuthenticationProvider.java | 116 ++++++++++++++++++ .../guacamole/net/auth/mysql/MySQLUser.java | 99 +++++++++++++++ .../net/auth/mysql/MySQLUserContext.java | 72 +++++++++++ .../properties/MySQLGuacamoleProperties.java | 70 +++++++++++ 6 files changed, 364 insertions(+) create mode 100644 extensions/guacamole-auth-mysql/.README.swp create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUser.java create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java create mode 100644 extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/properties/MySQLGuacamoleProperties.java diff --git a/extensions/guacamole-auth-mysql/.README.swp b/extensions/guacamole-auth-mysql/.README.swp new file mode 100644 index 0000000000000000000000000000000000000000..fbf9aa7350eedd006425a5d1259fbdf16eefe753 GIT binary patch literal 12288 zcmeHNNpBoQ6s{x?LP%Hz0!}Xu9D*`Ec8ox>kic0m2^c3%!jb?|b$5BDL1`-nF!uAK?d)3Q~Cnh4AQ&6|`Y3%8$_g;PPd#}oJ zxzkS_T%-q`S%K$fAs)GS%aMnUZxLsggz#mjqq3RlRepDw$5*}9e;NByJ*eGJvQ?c* zPqjO_^kkHTswH#NZAAlpI&3c=nBTv6;4&_oR}BLV16Rzzb}_qWW}2t%oZ3OR-Fp0r zEi@Av1{ww$1{ww$1{ww$1{ww$1{wygUIt9ML7YMO8_Oj;Uw&>F`z(K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3VL`XSrM>i)XZZ^3GL@x7er(sS1IOKdgIxQjIG8^VW+K*P5Nd8TTCe zGPM;!hfoxC-{BGkS14%16*bzx`^ueETTgR|Len*iBU*oW!tj9f*pPE9a*$0TH3-N>&Ib8E@701e3Hdx0NOsHpU_d SnN%b5Zj$q9zYb_ZUHk(l|4Zut literal 0 HcmV?d00001 diff --git a/extensions/guacamole-auth-mysql/pom.xml b/extensions/guacamole-auth-mysql/pom.xml index e7032bd3a..435100ddf 100644 --- a/extensions/guacamole-auth-mysql/pom.xml +++ b/extensions/guacamole-auth-mysql/pom.xml @@ -73,6 +73,13 @@ mybatis 3.1.1 + + + + org.mybatis + mybatis-guice + 3.2 + 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 new file mode 100644 index 000000000..0d992aa5f --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLAuthenticationProvider.java @@ -0,0 +1,116 @@ +/* ***** 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-ext. + * + * 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 ***** */ +package net.sourceforge.guacamole.net.auth.mysql; + +import com.google.inject.Binder; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.Provider; +import com.google.inject.name.Names; +import java.util.Properties; +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.guacamole.ConnectionMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.guacamole.ConnectionParameterMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.guacamole.ConnectionPermissionMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.guacamole.SystemPermissionMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.guacamole.UserMapper; +import net.sourceforge.guacamole.net.auth.mysql.dao.guacamole.UserPermissionMapper; +import net.sourceforge.guacamole.net.auth.mysql.properties.MySQLGuacamoleProperties; +import net.sourceforge.guacamole.properties.GuacamoleProperties; +import org.mybatis.guice.MyBatisModule; +import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider; +import org.mybatis.guice.datasource.helper.JdbcHelper; + +/** + * Provides a MySQL based implementation of the AuthenticationProvider + * functionality. + * @author dagger10k + */ +public class MySQLAuthenticationProvider implements AuthenticationProvider { + + private Injector injector; + private Credentials credentials; + + @Override + public UserContext getUserContext(Credentials credentials) throws GuacamoleException { + this.credentials = credentials; + UserContext context = injector.getInstance(UserContext.class); + return context; + } + + public MySQLAuthenticationProvider() throws GuacamoleException { + final Properties myBatisProperties = new Properties(); + 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.autoCommit", "false"); + + injector = Guice.createInjector( + JdbcHelper.MySQL, + new Module() { + @Override + public void configure(Binder binder) { + Names.bindProperties(binder, myBatisProperties); + } + },new MyBatisModule() { + @Override + protected void initialize() { + bindDataSourceProviderType(PooledDataSourceProvider.class); + addMapperClass(ConnectionMapper.class); + addMapperClass(ConnectionParameterMapper.class); + addMapperClass(ConnectionPermissionMapper.class); + addMapperClass(SystemPermissionMapper.class); + addMapperClass(UserMapper.class); + addMapperClass(UserPermissionMapper.class); + bind(UserContext.class).to(MySQLUserContext.class); + bind(Credentials.class).toProvider(new Provider() { + @Override + public Credentials get() { + return credentials; + } + }); + } + } + ); + } +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUser.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUser.java new file mode 100644 index 000000000..839115b22 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUser.java @@ -0,0 +1,99 @@ +/* ***** 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-ext. + * + * 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 ***** */ +package net.sourceforge.guacamole.net.auth.mysql; + +import java.util.Set; +import net.sourceforge.guacamole.GuacamoleException; +import net.sourceforge.guacamole.net.auth.Credentials; +import net.sourceforge.guacamole.net.auth.User; +import net.sourceforge.guacamole.net.auth.permission.Permission; + +/** + * + * @author dagger10k + */ +public class MySQLUser implements User { + + private String username; + private String userID; + private String salt; + + MySQLUser(Credentials credentials) { + //TODO: load the user from the DB if the credentials are correct, + // otherwise, throw some kind of exception + } + + @Override + public String getUsername() { + return username; + } + + @Override + public void setUsername(String username) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getPassword() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setPassword(String password) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Set getPermissions() throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean hasPermission(Permission permission) throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPermission(Permission permission) throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePermission(Permission permission) throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} 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 new file mode 100644 index 000000000..233e6f341 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLUserContext.java @@ -0,0 +1,72 @@ +/* ***** 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-ext. + * + * 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 ***** */ +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.Credentials; +import net.sourceforge.guacamole.net.auth.Directory; +import net.sourceforge.guacamole.net.auth.User; +import net.sourceforge.guacamole.net.auth.UserContext; + +/** + * + * @author dagger10k + */ +public class MySQLUserContext implements UserContext { + + @Inject + MySQLUserContext(Credentials credentials) { + + } + + @Override + public User self() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Directory getUserDirectory() throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Directory getConnectionDirectory() throws GuacamoleException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/properties/MySQLGuacamoleProperties.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/properties/MySQLGuacamoleProperties.java new file mode 100644 index 000000000..2d8a8a065 --- /dev/null +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/properties/MySQLGuacamoleProperties.java @@ -0,0 +1,70 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package net.sourceforge.guacamole.net.auth.mysql.properties; + +import net.sourceforge.guacamole.properties.IntegerGuacamoleProperty; +import net.sourceforge.guacamole.properties.StringGuacamoleProperty; + +/** + * Properties used by the MySQL Authentication plugin. + * @author dagger10k + */ +public class MySQLGuacamoleProperties { + + /** + * This class should not be instantiated. + */ + private MySQLGuacamoleProperties() {} + + /** + * The URL of the MySQL server hosting the guacamole authentication tables. + */ + public static final StringGuacamoleProperty MYSQL_HOSTNAME = new StringGuacamoleProperty() { + + @Override + public String getName() { return "mysql-hostname"; } + + }; + + /** + * The port of the MySQL server hosting the guacamole authentication tables. + */ + public static final IntegerGuacamoleProperty MYSQL_PORT = new IntegerGuacamoleProperty() { + + @Override + public String getName() { return "mysql-port"; } + + }; + + /** + * The name of the MySQL database containing the guacamole authentication tables. + */ + public static final StringGuacamoleProperty MYSQL_DATABASE = new StringGuacamoleProperty() { + + @Override + public String getName() { return "mysql-database"; } + + }; + + /** + * The username used to authenticate to the MySQL database containing the guacamole authentication tables. + */ + public static final StringGuacamoleProperty MYSQL_USERNAME = new StringGuacamoleProperty() { + + @Override + public String getName() { return "mysql-username"; } + + }; + + /** + * The password used to authenticate to the MySQL database containing the guacamole authentication tables. + */ + public static final StringGuacamoleProperty MYSQL_PASSWORD = new StringGuacamoleProperty() { + + @Override + public String getName() { return "mysql-password"; } + + }; +}