Fix permission lookups being case sensitive

This commit is contained in:
Luck 2016-09-26 18:52:01 +01:00
parent e72d91503c
commit ab6b011225
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 16 additions and 12 deletions

View File

@ -78,7 +78,7 @@ public class VaultPermissionHook extends Permission {
Map<String, Boolean> toApply = object.exportNodes( Map<String, Boolean> toApply = object.exportNodes(
new Contexts(context, includeGlobal, includeGlobal, true, true, true), new Contexts(context, includeGlobal, includeGlobal, true, true, true),
Collections.emptyList() Collections.emptyList(), true
); );
return toApply.containsKey(permission) && toApply.get(permission); return toApply.containsKey(permission) && toApply.get(permission);
@ -217,7 +217,7 @@ public class VaultPermissionHook extends Permission {
Map<String, Boolean> toApply = user.exportNodes( Map<String, Boolean> toApply = user.exportNodes(
new Contexts(context, includeGlobal, includeGlobal, true, true, true), new Contexts(context, includeGlobal, includeGlobal, true, true, true),
Collections.emptyList() Collections.emptyList(), true
); );
return toApply.entrySet().stream() return toApply.entrySet().stream()

View File

@ -71,7 +71,8 @@ public class BukkitUser extends User {
plugin.getConfiguration().isApplyingGlobalGroups(), plugin.getConfiguration().isApplyingGlobalGroups(),
plugin.getConfiguration().isApplyingGlobalWorldGroups() plugin.getConfiguration().isApplyingGlobalWorldGroups()
), ),
Collections.emptyList() Collections.emptyList(),
true
); );
try { try {

View File

@ -69,7 +69,8 @@ public class BungeeUser extends User {
plugin.getConfiguration().isApplyingGlobalGroups(), plugin.getConfiguration().isApplyingGlobalGroups(),
plugin.getConfiguration().isApplyingGlobalWorldGroups() plugin.getConfiguration().isApplyingGlobalWorldGroups()
), ),
Collections.emptyList() Collections.emptyList(),
true
); );
Map<String, Boolean> existing = playerCache.getPermissions(); Map<String, Boolean> existing = playerCache.getPermissions();

View File

@ -262,7 +262,7 @@ public class PermissionHolderLink implements PermissionHolder {
if (world != null && !world.equals("")) { if (world != null && !world.equals("")) {
extraContext.put("world", world); extraContext.put("world", world);
} }
return master.exportNodes(new Contexts(extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes); return master.exportNodes(new Contexts(extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes, false);
} }
@Override @Override

View File

@ -262,22 +262,23 @@ public abstract class PermissionHolder {
* @param possibleNodes a list of possible nodes for wildcards and regex permissions * @param possibleNodes a list of possible nodes for wildcards and regex permissions
* @return a map of permissions * @return a map of permissions
*/ */
public Map<String, Boolean> exportNodes(Contexts context, List<String> possibleNodes) { public Map<String, Boolean> exportNodes(Contexts context, List<String> possibleNodes, boolean lowerCase) {
Map<String, Boolean> perms = new HashMap<>(); Map<String, Boolean> perms = new HashMap<>();
for (Node node : getAllNodesFiltered(context)) { for (Node node : getAllNodesFiltered(context)) {
if (possibleNodes != null && !possibleNodes.isEmpty()) { if (possibleNodes != null && !possibleNodes.isEmpty()) {
if (node.getPermission().equals("*") || node.getPermission().equals("'*'")) { if (node.getPermission().equals("*") || node.getPermission().equals("'*'")) {
if (plugin.getConfiguration().isApplyingWildcards()) { if (plugin.getConfiguration().isApplyingWildcards()) {
possibleNodes.forEach(n -> perms.put(n, true)); possibleNodes.forEach(n -> perms.put(lowerCase ? n.toLowerCase() : n, true));
} }
} }
} }
perms.put(node.getPermission(), node.getValue()); perms.put(lowerCase ? node.getPermission().toLowerCase() : node.getPermission(), node.getValue());
if (plugin.getConfiguration().isApplyingShorthand()) { if (plugin.getConfiguration().isApplyingShorthand()) {
node.resolveShorthand().stream() node.resolveShorthand().stream()
.map(s -> lowerCase ? s.toLowerCase() : s)
.filter(s -> !perms.containsKey(s)) .filter(s -> !perms.containsKey(s))
.forEach(s -> perms.put(s, node.getValue())); .forEach(s -> perms.put(s, node.getValue()));
} }
@ -285,6 +286,7 @@ public abstract class PermissionHolder {
if (possibleNodes != null && !possibleNodes.isEmpty()) { if (possibleNodes != null && !possibleNodes.isEmpty()) {
if (plugin.getConfiguration().isApplyingWildcards()) { if (plugin.getConfiguration().isApplyingWildcards()) {
node.resolveWildcard(possibleNodes).stream() node.resolveWildcard(possibleNodes).stream()
.map(s -> lowerCase ? s.toLowerCase() : s)
.filter(s -> !perms.containsKey(s)) .filter(s -> !perms.containsKey(s))
.forEach(s -> perms.put(s, node.getValue())); .forEach(s -> perms.put(s, node.getValue()));
} }
@ -576,7 +578,7 @@ public abstract class PermissionHolder {
if (world != null && !world.equals("")) { if (world != null && !world.equals("")) {
context.put("world", world); context.put("world", world);
} }
return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList()); return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList(), false);
} }
@Deprecated @Deprecated
@ -588,7 +590,7 @@ public abstract class PermissionHolder {
if (world != null && !world.equals("")) { if (world != null && !world.equals("")) {
context.put("world", world); context.put("world", world);
} }
return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList()); return exportNodes(new Contexts(context, plugin.getConfiguration().isIncludingGlobalPerms(), true, true, true, true), Collections.emptyList(), false);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -39,7 +39,6 @@ import org.spongepowered.api.util.Tristate;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class LuckPermsUserSubject extends LuckPermsSubject { public class LuckPermsUserSubject extends LuckPermsSubject {
@ -83,7 +82,8 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
service.getPlugin().getConfiguration().isApplyingGlobalGroups(), service.getPlugin().getConfiguration().isApplyingGlobalGroups(),
service.getPlugin().getConfiguration().isApplyingGlobalWorldGroups() service.getPlugin().getConfiguration().isApplyingGlobalWorldGroups()
), ),
Collections.emptyList() Collections.emptyList(),
true
); );
ContextData existing = contextData.get(context); ContextData existing = contextData.get(context);