diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java index 901d4d88f..4f3068f86 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/MySQLConnection.java @@ -72,12 +72,6 @@ public class MySQLConnection extends AbstractConnection { @Inject private ConnectionService connectionService; - /** - * Set of all currently active connections. - */ - @Inject - private ActiveConnectionSet activeConnectionSet; - /** * Create a default, empty connection. */ diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/UserDirectory.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/UserDirectory.java index e04905177..4dca4b45b 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/UserDirectory.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/UserDirectory.java @@ -501,40 +501,17 @@ public class UserDirectory implements Directory permissions) { + // If no permissions given, stop now if(permissions.isEmpty()) return; - // Build list of requested system permissions - List systemPermissionTypes = new ArrayList(); + // Insert all requested permissions for (SystemPermission permission : permissions) { - switch (permission.getType()) { // TODO: Move this into MySQLConstants - - // Create connection permission - case CREATE_CONNECTION: - systemPermissionTypes.add(MySQLConstants.SYSTEM_CONNECTION_CREATE); - break; - - // Create user permission - case CREATE_USER: - systemPermissionTypes.add(MySQLConstants.SYSTEM_USER_CREATE); - break; - - // Fail if unexpected type encountered - default: - assert false : "Unsupported type: " + permission.getType(); - - } - - } // end for each system permission - - // Finally, insert any NEW system permissions for this user - for (String systemPermissionType : systemPermissionTypes) { - // Insert permission SystemPermissionKey newSystemPermission = new SystemPermissionKey(); newSystemPermission.setUser_id(user_id); - newSystemPermission.setPermission(systemPermissionType); + newSystemPermission.setPermission(MySQLConstants.getSystemConstant(permission.getType())); systemPermissionDAO.insert(newSystemPermission); } @@ -552,34 +529,16 @@ public class UserDirectory implements Directory permissions) { + // If no permissions given, stop now if (permissions.isEmpty()) return; // Build list of requested system permissions List systemPermissionTypes = new ArrayList(); - for (SystemPermission permission : permissions) { + for (SystemPermission permission : permissions) + systemPermissionTypes.add(MySQLConstants.getSystemConstant(permission.getType())); - switch (permission.getType()) { - - // Create connection permission - case CREATE_CONNECTION: - systemPermissionTypes.add(MySQLConstants.SYSTEM_CONNECTION_CREATE); - break; - - // Create user permission - case CREATE_USER: - systemPermissionTypes.add(MySQLConstants.SYSTEM_USER_CREATE); - break; - - // Fail if unexpected type encountered - default: - assert false : "Unsupported type: " + permission.getType(); - - } - - } // end for each system permission - - // Finally, delete the requested system permissions for this user + // Delete the requested system permissions for this user SystemPermissionExample systemPermissionExample = new SystemPermissionExample(); systemPermissionExample.createCriteria().andUser_idEqualTo(user_id) .andPermissionIn(systemPermissionTypes); diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java index 17ac42cec..9dc1bade0 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/ConnectionService.java @@ -259,7 +259,7 @@ public class ConnectionService { connection.getConnection_id(), connection.getConnection_name(), config, - Collections.EMPTY_LIST // TODO: Read history + retrieveHistory(connection.getConnection_id()) ); return mySQLConnection; @@ -333,6 +333,8 @@ public class ConnectionService { // Mark this connection as active activeConnectionSet.add(connection.getConnectionID()); + // TODO: Actually update history... + // Return new MySQLGuacamoleSocket MySQLGuacamoleSocket mySQLGuacamoleSocket = mySQLGuacamoleSocketProvider.get(); mySQLGuacamoleSocket.init(socket, connection.getConnectionID()); diff --git a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/PermissionCheckService.java b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/PermissionCheckService.java index a2dcd3731..f6669bf33 100644 --- a/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/PermissionCheckService.java +++ b/extensions/guacamole-auth-mysql/src/main/java/net/sourceforge/guacamole/net/auth/mysql/service/PermissionCheckService.java @@ -307,8 +307,8 @@ public class PermissionCheckService { * given ID. * * @param userID The ID of the user to retrieve permissions of. - * @return A set of all user permissions granted to the user having the - * given ID. + * @return A set of all connection permissions granted to the user having + * the given ID. */ public Set retrieveConnectionPermissions(int userID) { @@ -348,6 +348,44 @@ public class PermissionCheckService { } + /** + * Retrieves all system permissions granted to the user having the + * given ID. + * + * @param userID The ID of the user to retrieve permissions of. + * @return A set of all system permissions granted to the user having the + * given ID. + */ + public Set retrieveSystemPermissions(int userID) { + + // Set of all permissions + Set permissions = new HashSet(); + + // And finally, system permissions + SystemPermissionExample systemPermissionExample = new SystemPermissionExample(); + systemPermissionExample.createCriteria().andUser_idEqualTo(userID); + List systemPermissions = + systemPermissionDAO.selectByExample(systemPermissionExample); + for(SystemPermissionKey systemPermission : systemPermissions) { + + // User creation permission + if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_USER_CREATE)) + permissions.add(new SystemPermission(SystemPermission.Type.CREATE_USER)); + + // System creation permission + else if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_CONNECTION_CREATE)) + permissions.add(new SystemPermission(SystemPermission.Type.CREATE_CONNECTION)); + + // System administration permission + else if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_ADMINISTER)) + permissions.add(new SystemPermission(SystemPermission.Type.ADMINISTER)); + + } + + return permissions; + + } + /** * Retrieves all permissions granted to the user having the given ID. * @@ -366,28 +404,8 @@ public class PermissionCheckService { // Add connection permissions allPermissions.addAll(retrieveConnectionPermissions(userID)); - // TODO: Move to retrieveSystemPermissions() - - // And finally, system permissions - SystemPermissionExample systemPermissionExample = new SystemPermissionExample(); - systemPermissionExample.createCriteria().andUser_idEqualTo(userID); - List systemPermissions = - systemPermissionDAO.selectByExample(systemPermissionExample); - for(SystemPermissionKey systemPermission : systemPermissions) { - - // User creation permission - if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_USER_CREATE)) - allPermissions.add(new SystemPermission(SystemPermission.Type.CREATE_USER)); - - // System creation permission - else if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_CONNECTION_CREATE)) - allPermissions.add(new SystemPermission(SystemPermission.Type.CREATE_CONNECTION)); - - // System administration permission - else if(systemPermission.getPermission().equals(MySQLConstants.SYSTEM_ADMINISTER)) - allPermissions.add(new SystemPermission(SystemPermission.Type.ADMINISTER)); - - } + // Add system permissions + allPermissions.addAll(retrieveSystemPermissions(userID)); return allPermissions; }