mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Ticket #269: Complete some TODO items, replace with others.
This commit is contained in:
@@ -72,12 +72,6 @@ public class MySQLConnection extends AbstractConnection {
|
|||||||
@Inject
|
@Inject
|
||||||
private ConnectionService connectionService;
|
private ConnectionService connectionService;
|
||||||
|
|
||||||
/**
|
|
||||||
* Set of all currently active connections.
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
private ActiveConnectionSet activeConnectionSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default, empty connection.
|
* Create a default, empty connection.
|
||||||
*/
|
*/
|
||||||
|
@@ -501,40 +501,17 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
|
|||||||
private void createSystemPermissions(int user_id,
|
private void createSystemPermissions(int user_id,
|
||||||
Collection<SystemPermission> permissions) {
|
Collection<SystemPermission> permissions) {
|
||||||
|
|
||||||
|
// If no permissions given, stop now
|
||||||
if(permissions.isEmpty())
|
if(permissions.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Build list of requested system permissions
|
// Insert all requested permissions
|
||||||
List<String> systemPermissionTypes = new ArrayList<String>();
|
|
||||||
for (SystemPermission permission : 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
|
// Insert permission
|
||||||
SystemPermissionKey newSystemPermission = new SystemPermissionKey();
|
SystemPermissionKey newSystemPermission = new SystemPermissionKey();
|
||||||
newSystemPermission.setUser_id(user_id);
|
newSystemPermission.setUser_id(user_id);
|
||||||
newSystemPermission.setPermission(systemPermissionType);
|
newSystemPermission.setPermission(MySQLConstants.getSystemConstant(permission.getType()));
|
||||||
systemPermissionDAO.insert(newSystemPermission);
|
systemPermissionDAO.insert(newSystemPermission);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -552,34 +529,16 @@ public class UserDirectory implements Directory<String, net.sourceforge.guacamol
|
|||||||
private void deleteSystemPermissions(int user_id,
|
private void deleteSystemPermissions(int user_id,
|
||||||
Collection<SystemPermission> permissions) {
|
Collection<SystemPermission> permissions) {
|
||||||
|
|
||||||
|
// If no permissions given, stop now
|
||||||
if (permissions.isEmpty())
|
if (permissions.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Build list of requested system permissions
|
// Build list of requested system permissions
|
||||||
List<String> systemPermissionTypes = new ArrayList<String>();
|
List<String> systemPermissionTypes = new ArrayList<String>();
|
||||||
for (SystemPermission permission : permissions) {
|
for (SystemPermission permission : permissions)
|
||||||
|
systemPermissionTypes.add(MySQLConstants.getSystemConstant(permission.getType()));
|
||||||
|
|
||||||
switch (permission.getType()) {
|
// Delete the requested system permissions for this user
|
||||||
|
|
||||||
// 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
|
|
||||||
SystemPermissionExample systemPermissionExample = new SystemPermissionExample();
|
SystemPermissionExample systemPermissionExample = new SystemPermissionExample();
|
||||||
systemPermissionExample.createCriteria().andUser_idEqualTo(user_id)
|
systemPermissionExample.createCriteria().andUser_idEqualTo(user_id)
|
||||||
.andPermissionIn(systemPermissionTypes);
|
.andPermissionIn(systemPermissionTypes);
|
||||||
|
@@ -259,7 +259,7 @@ public class ConnectionService {
|
|||||||
connection.getConnection_id(),
|
connection.getConnection_id(),
|
||||||
connection.getConnection_name(),
|
connection.getConnection_name(),
|
||||||
config,
|
config,
|
||||||
Collections.EMPTY_LIST // TODO: Read history
|
retrieveHistory(connection.getConnection_id())
|
||||||
);
|
);
|
||||||
|
|
||||||
return mySQLConnection;
|
return mySQLConnection;
|
||||||
@@ -333,6 +333,8 @@ public class ConnectionService {
|
|||||||
// Mark this connection as active
|
// Mark this connection as active
|
||||||
activeConnectionSet.add(connection.getConnectionID());
|
activeConnectionSet.add(connection.getConnectionID());
|
||||||
|
|
||||||
|
// TODO: Actually update history...
|
||||||
|
|
||||||
// Return new MySQLGuacamoleSocket
|
// Return new MySQLGuacamoleSocket
|
||||||
MySQLGuacamoleSocket mySQLGuacamoleSocket = mySQLGuacamoleSocketProvider.get();
|
MySQLGuacamoleSocket mySQLGuacamoleSocket = mySQLGuacamoleSocketProvider.get();
|
||||||
mySQLGuacamoleSocket.init(socket, connection.getConnectionID());
|
mySQLGuacamoleSocket.init(socket, connection.getConnectionID());
|
||||||
|
@@ -307,8 +307,8 @@ public class PermissionCheckService {
|
|||||||
* given ID.
|
* given ID.
|
||||||
*
|
*
|
||||||
* @param userID The ID of the user to retrieve permissions of.
|
* @param userID The ID of the user to retrieve permissions of.
|
||||||
* @return A set of all user permissions granted to the user having the
|
* @return A set of all connection permissions granted to the user having
|
||||||
* given ID.
|
* the given ID.
|
||||||
*/
|
*/
|
||||||
public Set<ConnectionPermission> retrieveConnectionPermissions(int userID) {
|
public Set<ConnectionPermission> 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<SystemPermission> retrieveSystemPermissions(int userID) {
|
||||||
|
|
||||||
|
// Set of all permissions
|
||||||
|
Set<SystemPermission> permissions = new HashSet<SystemPermission>();
|
||||||
|
|
||||||
|
// And finally, system permissions
|
||||||
|
SystemPermissionExample systemPermissionExample = new SystemPermissionExample();
|
||||||
|
systemPermissionExample.createCriteria().andUser_idEqualTo(userID);
|
||||||
|
List<SystemPermissionKey> 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.
|
* Retrieves all permissions granted to the user having the given ID.
|
||||||
*
|
*
|
||||||
@@ -366,28 +404,8 @@ public class PermissionCheckService {
|
|||||||
// Add connection permissions
|
// Add connection permissions
|
||||||
allPermissions.addAll(retrieveConnectionPermissions(userID));
|
allPermissions.addAll(retrieveConnectionPermissions(userID));
|
||||||
|
|
||||||
// TODO: Move to retrieveSystemPermissions()
|
// Add system permissions
|
||||||
|
allPermissions.addAll(retrieveSystemPermissions(userID));
|
||||||
// And finally, system permissions
|
|
||||||
SystemPermissionExample systemPermissionExample = new SystemPermissionExample();
|
|
||||||
systemPermissionExample.createCriteria().andUser_idEqualTo(userID);
|
|
||||||
List<SystemPermissionKey> 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));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return allPermissions;
|
return allPermissions;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user