#784 Perform bypass purge permission check with OfflinePlayer objects

- Move permission check inside PurgeTask to perform it with OfflinePlayer objects instead of lowercase names
- Move purge members into child "purge" package
- Unify online and offline default permission behavior in DefaultPermission
This commit is contained in:
ljacqu
2016-07-17 11:54:22 +02:00
parent b439a0391c
commit 2a4cda0709
18 changed files with 102 additions and 149 deletions
@@ -1,6 +1,6 @@
package fr.xephi.authme.permission;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.ServerOperator;
/**
* The default permission to fall back to if there is no support for permission nodes.
@@ -10,12 +10,7 @@ public enum DefaultPermission {
/** No one has permission. */
NOT_ALLOWED("No permission") {
@Override
public boolean evaluate(CommandSender sender) {
return false;
}
@Override
public boolean evaluateOffline(String name) {
public boolean evaluate(ServerOperator sender) {
return false;
}
},
@@ -23,26 +18,15 @@ public enum DefaultPermission {
/** Only players with OP status have permission. */
OP_ONLY("OP's only") {
@Override
public boolean evaluate(CommandSender sender) {
return sender.isOp();
}
@Override
public boolean evaluateOffline(String name) {
// TODO #784: Check if there is an elegant way to evaluate OP status
return false;
public boolean evaluate(ServerOperator sender) {
return sender != null && sender.isOp();
}
},
/** Everyone is granted permission. */
ALLOWED("Everyone allowed") {
@Override
public boolean evaluate(CommandSender sender) {
return true;
}
@Override
public boolean evaluateOffline(String name) {
public boolean evaluate(ServerOperator sender) {
return true;
}
};
@@ -64,15 +48,7 @@ public enum DefaultPermission {
* @param sender the sender to process
* @return true if the sender has permission, false otherwise
*/
public abstract boolean evaluate(CommandSender sender);
/**
* Evaluate whether permission is granted to an offline user.
*
* @param name The name to check
* @return True if the user has permission, false otherwise
*/
public abstract boolean evaluateOffline(String name);
public abstract boolean evaluate(ServerOperator sender);
/**
* Return the textual representation.
@@ -12,6 +12,7 @@ import fr.xephi.authme.permission.handlers.VaultHandler;
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
import fr.xephi.authme.util.StringUtils;
import org.anjocaido.groupmanager.GroupManager;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -210,22 +211,33 @@ public class PermissionsManager implements Reloadable {
* Check if a player has permission for the given permission node. This is for offline player checks. If no permissions
* system is used, then the player will not have permission.
*
* @param name The name of the player.
* @param permissionNode The permission node to verify.
* @param player The offline player
* @param permissionNode The permission node to verify
*
* @return
* @return true if the player has permission, false otherwise
*/
public boolean hasPermissionOffline(String name, PermissionNode permissionNode) {
public boolean hasPermissionOffline(OfflinePlayer player, PermissionNode permissionNode) {
// Check if the permission node is null
if (permissionNode == null) {
return true;
}
if (!isEnabled()) {
return permissionNode.getDefaultPermission().evaluateOffline(name);
return permissionNode.getDefaultPermission().evaluate(player);
}
return handler.hasPermission(name, permissionNode);
return handler.hasPermissionOffline(player.getName(), permissionNode);
}
public boolean hasPermissionOffline(String name, PermissionNode permissionNode) {
if (permissionNode == null) {
return true;
}
if (!isEnabled()) {
return permissionNode.getDefaultPermission().evaluate(null);
}
return handler.hasPermissionOffline(name, permissionNode);
}
/**
@@ -28,7 +28,7 @@ public class BPermissionsHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
return ApiLayer.hasPermission(null, CalculableType.USER, name, node.getNode());
}
@@ -36,7 +36,7 @@ public class GroupManagerHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(name);
List<String> perms = handler.getAllPlayersPermissions(name);
return perms.contains(node.getNode());
@@ -47,7 +47,7 @@ public interface PermissionHandler {
*
* @return True if the player has permission.
*/
boolean hasPermission(String name, PermissionNode node);
boolean hasPermissionOffline(String name, PermissionNode node);
/**
* Check whether the player is in the specified group.
@@ -26,7 +26,7 @@ public class PermissionsBukkitHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
return false;
}
@@ -44,7 +44,7 @@ public class PermissionsExHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
PermissionUser user = permissionManager.getUser(name);
return user.has(node.getNode());
}
@@ -50,7 +50,7 @@ public class VaultHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
return vaultProvider.has("", name, node.getNode());
}
@@ -43,7 +43,7 @@ public class ZPermissionsHandler implements PermissionHandler {
}
@Override
public boolean hasPermission(String name, PermissionNode node) {
public boolean hasPermissionOffline(String name, PermissionNode node) {
Map<String, Boolean> perms = zPermissionsService.getPlayerPermissions(null, null, name);
if (perms.containsKey(node.getNode()))
return perms.get(node.getNode());