mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
GUAC-1100: Use getAll() for retrieval of multiple users.
This commit is contained in:
@@ -24,6 +24,7 @@ package org.glyptodon.guacamole.net.basic.rest.user;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -113,40 +114,6 @@ public class UserRESTService {
|
|||||||
@Inject
|
@Inject
|
||||||
private ObjectRetrievalService retrievalService;
|
private ObjectRetrievalService retrievalService;
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the given user has at least one of the given
|
|
||||||
* permissions for the user having the given username.
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* The user to check permissions for.
|
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
* The username of the user to check permissions for.
|
|
||||||
*
|
|
||||||
* @param permissions
|
|
||||||
* The permissions to check. The given user must have one or more of
|
|
||||||
* these permissions for this function to return true.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* true if the user has at least one of the given permissions.
|
|
||||||
*/
|
|
||||||
private boolean hasUserPermission(User user, String username,
|
|
||||||
List<ObjectPermission.Type> permissions) throws GuacamoleException {
|
|
||||||
|
|
||||||
// Retrieve user permissions
|
|
||||||
ObjectPermissionSet<String> userPermissions = user.getUserPermissions();
|
|
||||||
|
|
||||||
// Determine whether user has at least one of the given permissions
|
|
||||||
for (ObjectPermission.Type permission : permissions) {
|
|
||||||
if (userPermissions.hasPermission(permission, username))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// None of the given permissions were present
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of users in the system, filtering the returned list by the
|
* Gets a list of users in the system, filtering the returned list by the
|
||||||
* given permission, if specified.
|
* given permission, if specified.
|
||||||
@@ -188,18 +155,20 @@ public class UserRESTService {
|
|||||||
// Get the directory
|
// Get the directory
|
||||||
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
Directory<String, User> userDirectory = userContext.getUserDirectory();
|
||||||
|
|
||||||
List<APIUser> users = new ArrayList<APIUser>();
|
// Filter users, if requested
|
||||||
|
Collection<String> userIdentifiers = userDirectory.getIdentifiers();
|
||||||
// Add all users matching the given permission filter
|
if (!isAdmin && permissions != null) {
|
||||||
for (String username : userDirectory.getIdentifiers()) {
|
ObjectPermissionSet<String> userPermissions = self.getUserPermissions();
|
||||||
|
userIdentifiers = userPermissions.getAccessibleObjects(permissions, userIdentifiers);
|
||||||
if (isAdmin || permissions == null || hasUserPermission(self, username, permissions))
|
|
||||||
users.add(new APIUser(userDirectory.get(username)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the user directory listing
|
// Retrieve all users, converting to API users
|
||||||
return users;
|
List<APIUser> apiUsers = new ArrayList<APIUser>();
|
||||||
|
for (User user : userDirectory.getAll(userIdentifiers))
|
||||||
|
apiUsers.add(new APIUser(user));
|
||||||
|
|
||||||
|
// Return the converted user list
|
||||||
|
return apiUsers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user