if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
}
// Get permissions before removing from registry
PermissionLabel removedPermissionLabel = registryMessageBoxHandler.getPermission(
messageBoxId, permissionLabelName);
// Remove from registry allowed permission label
registryMessageBoxHandler.removePermission(messageBoxId, permissionLabelName);
// Get all the permissions associated with this message box
List<PermissionLabel> allPermissions =
registryMessageBoxHandler.getAllPermissions(messageBoxId);
/**
* There may be permissions set with other permission labels, duplicate permissions
* Before un-authorizing allowed permissions, search those permissions and add them
* to another list of permission labels
*/
List<PermissionLabel> otherAllowedPermissions = new ArrayList<PermissionLabel>();
// Check for all removed users
for (String removedSharedUser : removedPermissionLabel.getSharedUsers()) {
// for all permissions on this message box
for (PermissionLabel permissionLabel : allPermissions) {
// just check if shared users contains removed user, if not no need of processing further
if (permissionLabel.getSharedUsers().contains(removedSharedUser)) {
for (String removedOperation : removedPermissionLabel.getOperations()) {
if (permissionLabel.getOperations().contains(removedOperation)) {
// if removed operation is allowed in another label,
// that should not be unauthorized
List<String> duplicatedSharedUsers = new ArrayList<String>();
duplicatedSharedUsers.add(removedSharedUser);
List<String> duplicatedOperations = new ArrayList<String>();
duplicatedOperations.add(removedOperation);
PermissionLabel duplicatedPermissions =
new PermissionLabel("DuplicatedPermissions",
duplicatedSharedUsers, duplicatedOperations);
otherAllowedPermissions.add(duplicatedPermissions);
}
}