diff --git a/extensions/guacamole-auth-mysql/.README.swp b/extensions/guacamole-auth-mysql/.README.swp new file mode 100644 index 000000000..fbf9aa735 Binary files /dev/null and b/extensions/guacamole-auth-mysql/.README.swp differ 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"; } + + }; +}