mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUACAMOLE-360: Change ActiveConnection elements to use the ObjectPermissionSet mechanism.
This commit is contained in:
@@ -96,8 +96,8 @@ public class ActiveConnectionPermissionService
|
|||||||
String identifier = record.getUUID().toString();
|
String identifier = record.getUUID().toString();
|
||||||
permissions.add(new ObjectPermission(ObjectPermission.Type.READ, identifier));
|
permissions.add(new ObjectPermission(ObjectPermission.Type.READ, identifier));
|
||||||
|
|
||||||
// If we're and admin, then we also have DELETE
|
// If we're and admin, or the connection is ours, then we also have DELETE
|
||||||
if (isAdmin)
|
if (isAdmin || targetUser.getIdentifier().equals(record.getUsername()))
|
||||||
permissions.add(new ObjectPermission(ObjectPermission.Type.DELETE, identifier));
|
permissions.add(new ObjectPermission(ObjectPermission.Type.DELETE, identifier));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ import org.apache.guacamole.auth.jdbc.tunnel.ActiveConnectionRecord;
|
|||||||
import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
import org.apache.guacamole.auth.jdbc.tunnel.GuacamoleTunnelService;
|
||||||
import org.apache.guacamole.net.GuacamoleTunnel;
|
import org.apache.guacamole.net.GuacamoleTunnel;
|
||||||
import org.apache.guacamole.net.auth.ActiveConnection;
|
import org.apache.guacamole.net.auth.ActiveConnection;
|
||||||
|
import org.apache.guacamole.net.auth.permission.ObjectPermission;
|
||||||
|
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service which provides convenience methods for creating, retrieving, and
|
* Service which provides convenience methods for creating, retrieving, and
|
||||||
@@ -111,11 +113,10 @@ public class ActiveConnectionService
|
|||||||
public void deleteObject(ModeledAuthenticatedUser user, String identifier)
|
public void deleteObject(ModeledAuthenticatedUser user, String identifier)
|
||||||
throws GuacamoleException {
|
throws GuacamoleException {
|
||||||
|
|
||||||
// Close connection, if it exists (and we have permission)
|
// Close connection, if it exists and we have permission
|
||||||
ActiveConnection activeConnection = retrieveObject(user, identifier);
|
ActiveConnection activeConnection = retrieveObject(user, identifier);
|
||||||
if (activeConnection != null &&
|
if (activeConnection != null
|
||||||
(user.getUser().isAdministrator()
|
&& hasObjectPermissions(user, identifier, ObjectPermission.Type.DELETE)) {
|
||||||
|| user.getIdentifier().equals(activeConnection.getUsername()))) {
|
|
||||||
|
|
||||||
// Close connection if not already closed
|
// Close connection if not already closed
|
||||||
GuacamoleTunnel tunnel = activeConnection.getTunnel();
|
GuacamoleTunnel tunnel = activeConnection.getTunnel();
|
||||||
@@ -162,4 +163,54 @@ public class ActiveConnectionService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the permission set for the specified user that relates
|
||||||
|
* to access to active connections.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* The user for which to retrieve the permission set.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* A permission set associated with the given user that specifies
|
||||||
|
* the permissions available for active connection objects.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If permission to read permissions for the user is denied.
|
||||||
|
*/
|
||||||
|
private ObjectPermissionSet getPermissionSet(ModeledAuthenticatedUser user)
|
||||||
|
throws GuacamoleException {
|
||||||
|
return user.getUser().getActiveConnectionPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a boolean value representing whether or not a user has the given
|
||||||
|
* permission available to them on the active connection with the given
|
||||||
|
* identifier.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* The user for which the permissions are being queried.
|
||||||
|
*
|
||||||
|
* @param identifier
|
||||||
|
* The identifier of the active connection we are wondering about.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* The type of permission being requested.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* True if the user has the necessary permission; otherwise false.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException
|
||||||
|
* If the user does not have access to read permissions.
|
||||||
|
*/
|
||||||
|
private boolean hasObjectPermissions(ModeledAuthenticatedUser user,
|
||||||
|
String identifier, ObjectPermission.Type type)
|
||||||
|
throws GuacamoleException {
|
||||||
|
|
||||||
|
ObjectPermissionSet permissionSet = getPermissionSet(user);
|
||||||
|
|
||||||
|
return user.getUser().isAdministrator()
|
||||||
|
|| permissionSet.hasPermission(type, identifier);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user