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 *****
* 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.
*
* ***** END LICENSE BLOCK ***** */
package net.sourceforge.guacamole.net.auth.mysql;
import java.util.HashSet;
import java.util.Set;
/**
* Represents the set of currently active Connections. Whenever a socket is opened,
* the connection ID should be added to this set, and whenever a socket is closed,
* the connection ID should be removed from this set.
* @author dagger10k
* Represents the set of currently active Connections. Whenever a socket is
* opened, the connection ID should be added to this set, and whenever a socket
* is closed, the connection ID should be removed from this set.
*
* @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 *****
* 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.
*
* ***** END LICENSE BLOCK ***** */
package net.sourceforge.guacamole.net.auth.mysql;
import com.google.inject.Binder;
import com.google.inject.Guice;
@@ -63,20 +65,24 @@ 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides a MySQL based implementation of the AuthenticationProvider
* functionality.
*
* @author James Muehlner
*/
public class MySQLAuthenticationProvider implements AuthenticationProvider {
private Logger logger = LoggerFactory.getLogger(MySQLUserContext.class);
/**
* Set of all active connections.
*/
private ActiveConnectionSet activeConnectionSet = new ActiveConnectionSet();
/**
* Injector which will manage the object graph of this authentication
* provider.
*/
private Injector injector;
@Override
@@ -86,9 +92,19 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
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 {
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("JDBC.host", GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_HOSTNAME));
myBatisProperties.setProperty("JDBC.port", String.valueOf(GuacamoleProperties.getRequiredProperty(MySQLGuacamoleProperties.MYSQL_PORT)));
@@ -100,21 +116,30 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
// Set up Guice injector.
injector = Guice.createInjector(
JdbcHelper.MySQL,
new Module() {
@Override
public void configure(Binder binder) {
Names.bindProperties(binder, myBatisProperties);
}
},new MyBatisModule() {
},
new MyBatisModule() {
@Override
protected void initialize() {
// Datasource
bindDataSourceProviderType(PooledDataSourceProvider.class);
// Add MyBatis mappers
addMapperClass(ConnectionMapper.class);
addMapperClass(ConnectionParameterMapper.class);
addMapperClass(ConnectionPermissionMapper.class);
addMapperClass(SystemPermissionMapper.class);
addMapperClass(UserMapper.class);
addMapperClass(UserPermissionMapper.class);
// Bind interfaces
bind(MySQLUserContext.class);
bind(UserDirectory.class);
bind(MySQLUser.class);
@@ -124,8 +149,11 @@ public class MySQLAuthenticationProvider implements AuthenticationProvider {
bind(ProviderUtility.class);
bind(ConfigurationTranslationUtility.class);
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.
* @param user
*
* @param user The user whose permissions define the visibility of other
* users in this directory.
*/
void init(MySQLUser user) {
this.user = user;
@@ -150,7 +152,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
// Get set of all readable users
Set<MySQLUser> users = permissionCheckUtility.getReadableUsers(user.getUserID());
// Build set of usernames of readable users
Set<String> userNameSet = new HashSet<String>();
for (MySQLUser mySQLUser : users)
@@ -202,7 +204,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
* Update all the permissions for a given user to be only those specified in the user object.
* Delete any permissions not in the list, and create any in the list that do not exist
* in the database.
*
*
* @param user The user whose permissions should be updated.
* @throws GuacamoleException If an error occurs while updating the
* permissions of the given user.
@@ -213,7 +215,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
List<UserPermission> userPermissions = new ArrayList<UserPermission>();
List<ConnectionPermission> connectionPermissions = new ArrayList<ConnectionPermission>();
List<SystemPermission> systemPermissions = new ArrayList<SystemPermission>();
for (Permission permission : user.getPermissions()) {
if (permission instanceof UserPermission)
@@ -231,12 +233,12 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
updateUserPermissions(userPermissions, user);
updateConnectionPermissions(connectionPermissions, user);
updateSystemPermissions(systemPermissions, user);
}
/**
* Update all the permissions having to do with users for a given user.
*
*
* @param permissions The permissions the given user should have when
* this operation completes.
* @param user The user to change the permissions of.
@@ -334,7 +336,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
/**
* Update all the permissions having to do with connections for a given
* user.
*
*
* @param permissions The permissions the user should have after this
* operation completes.
* @param user The user to assign or remove permissions from.
@@ -432,7 +434,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
* the given list not already granted to the user will be inserted, and all
* permissions not in the list but already granted to the user will be
* deleted.
*
*
* @param permissions The system permissions that the given user should
* have.
* @param user The user whose permissions should be updated.
@@ -526,7 +528,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
/**
* Delete all permissions associated with the provided user. This is only
* used when deleting a user.
*
*
* @param user The user to delete all permissions of.
*/
private void deleteAllPermissions(MySQLUser user) {

View File

@@ -57,7 +57,7 @@ public class Sha256PasswordEncryptionUtility implements PasswordEncryptionUtilit
// If usernames don't match, don't bother comparing passwords, just fail
if (!dbUsername.equals(credentials.getUsername()))
return false;
// Compare bytes of password in credentials against hashed password
byte[] passwordBytes = createPasswordHash(credentials.getPassword(), dbSalt);
return Arrays.equals(passwordBytes, dbPasswordHash);
@@ -73,7 +73,7 @@ public class Sha256PasswordEncryptionUtility implements PasswordEncryptionUtilit
StringBuilder builder = new StringBuilder();
builder.append(password);
builder.append(DatatypeConverter.printHexBinary(salt));
// Hash UTF-8 bytes of salted password
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(builder.toString().getBytes("UTF-8"));