Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
GUAC-1101: Begin separating out the common JDBC base of everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-jumper committed Mar 1, 2015
1 parent c19b43c commit 883cc05
Show file tree
Hide file tree
Showing 66 changed files with 383 additions and 306 deletions.
Expand Up @@ -23,183 +23,27 @@
package net.sourceforge.guacamole.net.auth.mysql; package net.sourceforge.guacamole.net.auth.mysql;




import org.glyptodon.guacamole.auth.mysql.user.MySQLUserContext;
import org.glyptodon.guacamole.auth.mysql.connectiongroup.MySQLRootConnectionGroup;
import org.glyptodon.guacamole.auth.mysql.connectiongroup.MySQLConnectionGroup;
import org.glyptodon.guacamole.auth.mysql.connectiongroup.ConnectionGroupDirectory;
import org.glyptodon.guacamole.auth.mysql.connection.ConnectionDirectory;
import org.glyptodon.guacamole.auth.mysql.connection.MySQLGuacamoleConfiguration;
import org.glyptodon.guacamole.auth.mysql.connection.MySQLConnection;
import org.glyptodon.guacamole.auth.mysql.permission.MySQLSystemPermissionSet;
import org.glyptodon.guacamole.auth.mysql.user.MySQLUser;
import org.glyptodon.guacamole.auth.mysql.user.UserDirectory;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.name.Names;
import java.util.Properties;
import org.glyptodon.guacamole.auth.mysql.connectiongroup.ConnectionGroupMapper;
import org.glyptodon.guacamole.auth.mysql.connection.ConnectionMapper;
import org.glyptodon.guacamole.auth.mysql.connection.ConnectionRecordMapper;
import org.glyptodon.guacamole.auth.mysql.connection.ParameterMapper;
import org.glyptodon.guacamole.auth.mysql.permission.SystemPermissionMapper;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.auth.AuthenticationProvider; import org.glyptodon.guacamole.auth.jdbc.JDBCAuthenticationProvider;
import org.glyptodon.guacamole.net.auth.Credentials;
import org.glyptodon.guacamole.net.auth.UserContext;
import org.glyptodon.guacamole.auth.mysql.user.UserMapper;
import org.glyptodon.guacamole.auth.mysql.conf.MySQLGuacamoleProperties;
import org.glyptodon.guacamole.auth.mysql.connectiongroup.ConnectionGroupService;
import org.glyptodon.guacamole.auth.mysql.connection.ConnectionService;
import org.glyptodon.guacamole.auth.mysql.socket.GuacamoleSocketService;
import org.glyptodon.guacamole.auth.mysql.security.PasswordEncryptionService;
import org.glyptodon.guacamole.auth.mysql.security.SHA256PasswordEncryptionService;
import org.glyptodon.guacamole.auth.mysql.security.SaltService;
import org.glyptodon.guacamole.auth.mysql.security.SecureRandomSaltService;
import org.glyptodon.guacamole.auth.mysql.permission.SystemPermissionService;
import org.glyptodon.guacamole.auth.mysql.socket.UnrestrictedGuacamoleSocketService;
import org.glyptodon.guacamole.auth.mysql.user.UserService;
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;


/** /**
* 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 extends JDBCAuthenticationProvider {

/**
* Injector which will manage the object graph of this authentication
* provider.
*/
private final Injector injector;

@Override
public UserContext getUserContext(Credentials credentials) throws GuacamoleException {

// Get user service
UserService userService = injector.getInstance(UserService.class);

// Authenticate user
MySQLUser user = userService.retrieveUser(credentials);
if (user != null) {

// Upon successful authentication, return new user context
MySQLUserContext context = injector.getInstance(MySQLUserContext.class);
context.init(user.getCurrentUser());
return context;

}

// Otherwise, unauthorized
return null;

}


/** /**
* Creates a new MySQLAuthenticationProvider that reads and writes * Creates a new MySQLAuthenticationProvider that reads and writes
* authentication data to a MySQL database defined by properties in * authentication data to a MySQL database defined by properties in
* guacamole.properties. * guacamole.properties.
* *
* @throws GuacamoleException If a required property is missing, or * @throws GuacamoleException
* an error occurs while parsing a property. * If a required property is missing, or an error occurs while parsing
* a property.
*/ */
public MySQLAuthenticationProvider() throws GuacamoleException { 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", 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");
driverProperties.setProperty("characterEncoding","UTF-8");

// Set up Guice injector.
injector = Guice.createInjector(
JdbcHelper.MySQL,

new Module() {
@Override
public void configure(Binder binder) {
Names.bindProperties(binder, myBatisProperties);
binder.bind(Properties.class)
.annotatedWith(Names.named("JDBC.driverProperties"))
.toInstance(driverProperties);
}
},

new MyBatisModule() {
@Override
protected void initialize() {

// Datasource
bindDataSourceProviderType(PooledDataSourceProvider.class);

// Transaction factory
bindTransactionFactoryType(JdbcTransactionFactory.class);

// Add MyBatis mappers
addMapperClass(ConnectionMapper.class);
addMapperClass(ConnectionGroupMapper.class);
addMapperClass(ConnectionRecordMapper.class);
addMapperClass(ParameterMapper.class);
addMapperClass(SystemPermissionMapper.class);
addMapperClass(UserMapper.class);

// Bind core implementations of guacamole-ext classes
bind(Environment.class).toInstance(environment);
bind(ConnectionDirectory.class);
bind(ConnectionGroupDirectory.class);
bind(MySQLConnection.class);
bind(MySQLConnectionGroup.class);
bind(MySQLGuacamoleConfiguration.class);
bind(MySQLUser.class);
bind(MySQLUserContext.class);
bind(MySQLRootConnectionGroup.class);
bind(MySQLSystemPermissionSet.class);
bind(UserDirectory.class);

// Bind services
bind(ConnectionService.class);
bind(ConnectionGroupService.class);
bind(PasswordEncryptionService.class).to(SHA256PasswordEncryptionService.class);
bind(SaltService.class).to(SecureRandomSaltService.class);
bind(SystemPermissionService.class);
bind(UserService.class);

// Bind appropriate socket service based on policy
bind(GuacamoleSocketService.class).to(UnrestrictedGuacamoleSocketService.class);

}
} // end of mybatis module

);
} // end of constructor

@Override
public UserContext updateUserContext(UserContext context,
Credentials credentials) throws GuacamoleException {

// No need to update the context
return context;

} }

} }
Expand Up @@ -22,7 +22,6 @@


/** /**
* The MySQL authentication provider. This package exists purely for backwards- * The MySQL authentication provider. This package exists purely for backwards-
* compatibility. All other classes have been moved to packages within * compatibility.
* org.glyptodon.guacamole.auth.mysql.
*/ */
package net.sourceforge.guacamole.net.auth.mysql; package net.sourceforge.guacamole.net.auth.mysql;

0 comments on commit 883cc05

Please sign in to comment.