mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Ticket #269: More style fixes, remove unnecessary interface declaration.
This commit is contained in:
@@ -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> {}
|
||||||
|
@@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
@@ -150,7 +152,7 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
|
|||||||
|
|
||||||
// Get set of all readable users
|
// Get set of all readable users
|
||||||
Set<MySQLUser> users = permissionCheckUtility.getReadableUsers(user.getUserID());
|
Set<MySQLUser> users = permissionCheckUtility.getReadableUsers(user.getUserID());
|
||||||
|
|
||||||
// Build set of usernames of readable users
|
// Build set of usernames of readable users
|
||||||
Set<String> userNameSet = new HashSet<String>();
|
Set<String> userNameSet = new HashSet<String>();
|
||||||
for (MySQLUser mySQLUser : users)
|
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.
|
* 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
|
* Delete any permissions not in the list, and create any in the list that do not exist
|
||||||
* in the database.
|
* in the database.
|
||||||
*
|
*
|
||||||
* @param user The user whose permissions should be updated.
|
* @param user The user whose permissions should be updated.
|
||||||
* @throws GuacamoleException If an error occurs while updating the
|
* @throws GuacamoleException If an error occurs while updating the
|
||||||
* permissions of the given user.
|
* 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<UserPermission> userPermissions = new ArrayList<UserPermission>();
|
||||||
List<ConnectionPermission> connectionPermissions = new ArrayList<ConnectionPermission>();
|
List<ConnectionPermission> connectionPermissions = new ArrayList<ConnectionPermission>();
|
||||||
List<SystemPermission> systemPermissions = new ArrayList<SystemPermission>();
|
List<SystemPermission> systemPermissions = new ArrayList<SystemPermission>();
|
||||||
|
|
||||||
for (Permission permission : user.getPermissions()) {
|
for (Permission permission : user.getPermissions()) {
|
||||||
|
|
||||||
if (permission instanceof UserPermission)
|
if (permission instanceof UserPermission)
|
||||||
@@ -231,12 +233,12 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
|
|||||||
updateUserPermissions(userPermissions, user);
|
updateUserPermissions(userPermissions, user);
|
||||||
updateConnectionPermissions(connectionPermissions, user);
|
updateConnectionPermissions(connectionPermissions, user);
|
||||||
updateSystemPermissions(systemPermissions, user);
|
updateSystemPermissions(systemPermissions, user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update all the permissions having to do with users for a given user.
|
* Update all the permissions having to do with users for a given user.
|
||||||
*
|
*
|
||||||
* @param permissions The permissions the given user should have when
|
* @param permissions The permissions the given user should have when
|
||||||
* this operation completes.
|
* this operation completes.
|
||||||
* @param user The user to change the permissions of.
|
* @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
|
* Update all the permissions having to do with connections for a given
|
||||||
* user.
|
* user.
|
||||||
*
|
*
|
||||||
* @param permissions The permissions the user should have after this
|
* @param permissions The permissions the user should have after this
|
||||||
* operation completes.
|
* operation completes.
|
||||||
* @param user The user to assign or remove permissions from.
|
* @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
|
* 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
|
* permissions not in the list but already granted to the user will be
|
||||||
* deleted.
|
* deleted.
|
||||||
*
|
*
|
||||||
* @param permissions The system permissions that the given user should
|
* @param permissions The system permissions that the given user should
|
||||||
* have.
|
* have.
|
||||||
* @param user The user whose permissions should be updated.
|
* @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
|
* Delete all permissions associated with the provided user. This is only
|
||||||
* used when deleting a user.
|
* used when deleting a user.
|
||||||
*
|
*
|
||||||
* @param user The user to delete all permissions of.
|
* @param user The user to delete all permissions of.
|
||||||
*/
|
*/
|
||||||
private void deleteAllPermissions(MySQLUser user) {
|
private void deleteAllPermissions(MySQLUser user) {
|
||||||
|
@@ -57,7 +57,7 @@ public class Sha256PasswordEncryptionUtility implements PasswordEncryptionUtilit
|
|||||||
// If usernames don't match, don't bother comparing passwords, just fail
|
// If usernames don't match, don't bother comparing passwords, just fail
|
||||||
if (!dbUsername.equals(credentials.getUsername()))
|
if (!dbUsername.equals(credentials.getUsername()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Compare bytes of password in credentials against hashed password
|
// Compare bytes of password in credentials against hashed password
|
||||||
byte[] passwordBytes = createPasswordHash(credentials.getPassword(), dbSalt);
|
byte[] passwordBytes = createPasswordHash(credentials.getPassword(), dbSalt);
|
||||||
return Arrays.equals(passwordBytes, dbPasswordHash);
|
return Arrays.equals(passwordBytes, dbPasswordHash);
|
||||||
@@ -73,7 +73,7 @@ public class Sha256PasswordEncryptionUtility implements PasswordEncryptionUtilit
|
|||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(password);
|
builder.append(password);
|
||||||
builder.append(DatatypeConverter.printHexBinary(salt));
|
builder.append(DatatypeConverter.printHexBinary(salt));
|
||||||
|
|
||||||
// Hash UTF-8 bytes of salted password
|
// Hash UTF-8 bytes of salted password
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
md.update(builder.toString().getBytes("UTF-8"));
|
md.update(builder.toString().getBytes("UTF-8"));
|
||||||
|
Reference in New Issue
Block a user