Added hierarchical permissions support to permission resolvers, improved Permissions support.

This commit is contained in:
sk89q 2011-01-29 09:01:21 -08:00
parent 02de4c8200
commit f683959420
4 changed files with 21 additions and 1 deletions

View File

@ -94,6 +94,13 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
} }
public boolean hasPermission(String player, String permission) { public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase()); Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) { if (perms == null) {
return defaultPermissionsCache.contains(permission) return defaultPermissionsCache.contains(permission)

View File

@ -153,6 +153,13 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
} }
public boolean hasPermission(String player, String permission) { public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase()); Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) { if (perms == null) {
return defaultPermissionsCache.contains(permission) return defaultPermissionsCache.contains(permission)

View File

@ -55,6 +55,12 @@ public class GroupUsersPemissionsResolver implements PermissionsResolver {
try { try {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) return false; if (player == null) return false;
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(name, permission.substring(0, dotPos))) {
return true;
}
}
return groupUsers.playerCanUseCommand(player, permission); return groupUsers.playerCanUseCommand(player, permission);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();

View File

@ -67,7 +67,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
try { try {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) return false; if (player == null) return false;
return group.equals(api.Security.getGroup(player.getName())); return api.Security.inGroup(name, group);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
return false; return false;