Ticket #269: More style fixes, remove unnecessary interface declaration.

This commit is contained in:
Michael Jumper
2013-02-23 00:34:57 -08:00
parent 8f734f5294
commit 4c034f091b
4 changed files with 59 additions and 27 deletions

View File

@@ -1,3 +1,6 @@
package net.sourceforge.guacamole.net.auth.mysql;
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@@ -33,15 +36,14 @@
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
package net.sourceforge.guacamole.net.auth.mysql;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
/** /**
* Represents the set of currently active Connections. Whenever a socket is opened, * Represents the set of currently active Connections. Whenever a socket is
* the connection ID should be added to this set, and whenever a socket is closed, * opened, the connection ID should be added to this set, and whenever a socket
* the connection ID should be removed from this set. * is closed, the connection ID should be removed from this set.
* @author dagger10k *
* @author James Muehlner
*/ */
public class ActiveConnectionSet extends HashSet<Integer> implements Set<Integer> {} public class ActiveConnectionSet extends HashSet<Integer> {}

View File

@@ -1,3 +1,6 @@
package net.sourceforge.guacamole.net.auth.mysql;
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@@ -33,7 +36,6 @@
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
package net.sourceforge.guacamole.net.auth.mysql;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Guice; import com.google.inject.Guice;
@@ -63,20 +65,24 @@ import net.sourceforge.guacamole.properties.GuacamoleProperties;
import org.mybatis.guice.MyBatisModule; import org.mybatis.guice.MyBatisModule;
import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider; import org.mybatis.guice.datasource.builtin.PooledDataSourceProvider;
import org.mybatis.guice.datasource.helper.JdbcHelper; import org.mybatis.guice.datasource.helper.JdbcHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Provides a MySQL based implementation of the AuthenticationProvider * Provides a MySQL based implementation of the AuthenticationProvider
* functionality. * functionality.
*
* @author James Muehlner * @author James Muehlner
*/ */
public class MySQLAuthenticationProvider implements AuthenticationProvider { public class MySQLAuthenticationProvider implements AuthenticationProvider {
private Logger logger = LoggerFactory.getLogger(MySQLUserContext.class); /**
* Set of all active connections.
*/
private ActiveConnectionSet activeConnectionSet = new ActiveConnectionSet(); private ActiveConnectionSet activeConnectionSet = new ActiveConnectionSet();
/**
* Injector which will manage the object graph of this authentication
* provider.
*/
private Injector injector; private Injector injector;
@Override @Override
@@ -86,9 +92,19 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
return context; return context;
} }
/**
* Creates a new MySQLAuthenticationProvider that reads and writes
* authentication data to a MySQL database defined by properties in
* guacamole.properties.
*
* @throws GuacamoleException If a required property is missing, or
* an error occurs while parsing a property.
*/
public MySQLAuthenticationProvider() throws GuacamoleException { public MySQLAuthenticationProvider() throws GuacamoleException {
final Properties myBatisProperties = new Properties(); final Properties myBatisProperties = new Properties();
//set the mysql properties for MyBatis.
// Set the mysql properties for MyBatis.
myBatisProperties.setProperty("mybatis.environment.id", "guacamole"); myBatisProperties.setProperty("mybatis.environment.id", "guacamole");
myBatisProperties.setProperty("JDBC.host", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_HOSTNAME)); myBatisProperties.setProperty("JDBC.host", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_HOSTNAME));
myBatisProperties.setProperty("JDBC.port", String.valueOf(GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PORT))); myBatisProperties.setProperty("JDBC.port", String.valueOf(GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PORT)));
@@ -100,21 +116,30 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
// Set up Guice injector. // Set up Guice injector.
injector = Guice.createInjector( injector = Guice.createInjector(
JdbcHelper.MySQL, JdbcHelper.MySQL,
new Module() { new Module() {
@Override @Override
public void configure(Binder binder) { public void configure(Binder binder) {
Names.bindProperties(binder, myBatisProperties); Names.bindProperties(binder, myBatisProperties);
} }
},new MyBatisModule() { },
new MyBatisModule() {
@Override @Override
protected void initialize() { protected void initialize() {
// Datasource
bindDataSourceProviderType(PooledDataSourceProvider.class); bindDataSourceProviderType(PooledDataSourceProvider.class);
// Add MyBatis mappers
addMapperClass(ConnectionMapper.class); addMapperClass(ConnectionMapper.class);
addMapperClass(ConnectionParameterMapper.class); addMapperClass(ConnectionParameterMapper.class);
addMapperClass(ConnectionPermissionMapper.class); addMapperClass(ConnectionPermissionMapper.class);
addMapperClass(SystemPermissionMapper.class); addMapperClass(SystemPermissionMapper.class);
addMapperClass(UserMapper.class); addMapperClass(UserMapper.class);
addMapperClass(UserPermissionMapper.class); addMapperClass(UserPermissionMapper.class);
// Bind interfaces
bind(MySQLUserContext.class); bind(MySQLUserContext.class);
bind(UserDirectory.class); bind(UserDirectory.class);
bind(MySQLUser.class); bind(MySQLUser.class);
@@ -124,8 +149,11 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
bind(ProviderUtility.class); bind(ProviderUtility.class);
bind(ConfigurationTranslationUtility.class); bind(ConfigurationTranslationUtility.class);
bind(ActiveConnectionSet.class).toInstance(activeConnectionSet); bind(ActiveConnectionSet.class).toInstance(activeConnectionSet);
} }
} } // end of mybatis module
); );
} } // end of constructor
} }

View File

@@ -130,7 +130,9 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
/** /**
* Set the user for this directory. * Set the user for this directory.
* @param user *
* @param user The user whose permissions define the visibility of other
* users in this directory.
*/ */
void init(MySQLUser user) { void init(MySQLUser user) {
this.user = user; this.user = user;