Add debug log for permission resolution + change api for Log debug

This commit is contained in:
Marc Baloup 2021-07-25 20:14:06 +02:00
parent a62b990dbe
commit 5eaaf8faa5
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
3 changed files with 28 additions and 21 deletions

View File

@ -8,6 +8,7 @@ import java.util.Set;
import fr.pandacube.lib.core.chat.ChatUtil.DisplayTreeNode; import fr.pandacube.lib.core.chat.ChatUtil.DisplayTreeNode;
import fr.pandacube.lib.core.permissions.PermissionsCachedBackendReader.CachedEntity; import fr.pandacube.lib.core.permissions.PermissionsCachedBackendReader.CachedEntity;
import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType; import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.core.util.Log;
public abstract class PermEntity { public abstract class PermEntity {
protected final String name; protected final String name;
@ -78,11 +79,11 @@ public abstract class PermEntity {
public Map<String, Boolean> listEffectivePermissions() { public Map<String, Boolean> listEffectivePermissions() {
return Permissions.resolver.getEffectivePermissionList(name, type, null, null); return listEffectivePermissions(null, null);
} }
public Map<String, Boolean> listEffectivePermissions(String server) { public Map<String, Boolean> listEffectivePermissions(String server) {
return Permissions.resolver.getEffectivePermissionList(name, type, server, null); return listEffectivePermissions(server, null);
} }
public Map<String, Boolean> listEffectivePermissions(String server, String world) { public Map<String, Boolean> listEffectivePermissions(String server, String world) {
@ -91,24 +92,28 @@ public abstract class PermEntity {
public Boolean hasPermission(String permission) { public Boolean hasPermission(String permission) {
return Permissions.resolver.getEffectivePermission(name, type, permission, null, null); return hasPermission(permission, null, null);
} }
public Boolean hasPermission(String permission, String server) { public Boolean hasPermission(String permission, String server) {
return Permissions.resolver.getEffectivePermission(name, type, permission, server, null); return hasPermission(permission, server, null);
} }
public Boolean hasPermission(String permission, String server, String world) { public Boolean hasPermission(String permission, String server, String world) {
return Permissions.resolver.getEffectivePermission(name, type, permission, server, world); Boolean ret = Permissions.resolver.getEffectivePermission(name, type, permission, server, world);
if (Log.isDebugEnabled()) {
Log.debug("[Perm] For " + type.toString().toLowerCase() + " " + getName() + ", '" + permission + "' is " + ret);
}
return ret;
} }
public DisplayTreeNode debugPermission(String permission) { public DisplayTreeNode debugPermission(String permission) {
return Permissions.resolver.debugPermission(name, type, permission, null, null); return debugPermission(permission, null, null);
} }
public DisplayTreeNode debugPermission(String permission, String server) { public DisplayTreeNode debugPermission(String permission, String server) {
return Permissions.resolver.debugPermission(name, type, permission, server, null); return debugPermission(permission, server, null);
} }
public DisplayTreeNode debugPermission(String permission, String server, String world) { public DisplayTreeNode debugPermission(String permission, String server, String world) {
@ -117,11 +122,11 @@ public abstract class PermEntity {
public void addSelfPermission(String permission) { public void addSelfPermission(String permission) {
Permissions.backendWriter.addSelfPermission(name, type, permission, null, null); addSelfPermission(permission, null, null);
} }
public void addSelfPermission(String permission, String server) { public void addSelfPermission(String permission, String server) {
Permissions.backendWriter.addSelfPermission(name, type, permission, server, null); addSelfPermission(permission, server, null);
} }
public void addSelfPermission(String permission, String server, String world) { public void addSelfPermission(String permission, String server, String world) {
@ -130,11 +135,11 @@ public abstract class PermEntity {
public void removeSelfPermission(String permission) { public void removeSelfPermission(String permission) {
Permissions.backendWriter.removeSelfPermission(name, type, permission, null, null); removeSelfPermission(permission, null, null);
} }
public void removeSelfPermission(String permission, String server) { public void removeSelfPermission(String permission, String server) {
Permissions.backendWriter.removeSelfPermission(name, type, permission, server, null); removeSelfPermission(permission, server, null);
} }
public void removeSelfPermission(String permission, String server, String world) { public void removeSelfPermission(String permission, String server, String world) {
@ -152,11 +157,11 @@ public abstract class PermEntity {
} }
public List<String> getSelfPermissions() { public List<String> getSelfPermissions() {
return getBackendEntity().getSelfPermissions(null, null); return getSelfPermissions(null, null);
} }
public List<String> getSelfPermissions(String server) { public List<String> getSelfPermissions(String server) {
return getBackendEntity().getSelfPermissions(server, null); return getSelfPermissions(server, null);
} }
public List<String> getSelfPermissions(String server, String world) { public List<String> getSelfPermissions(String server, String world) {

View File

@ -106,9 +106,10 @@ public class PermissionsResolver {
DataResolutionNode resolutionResult = resolveData(entity, dataType); DataResolutionNode resolutionResult = resolveData(entity, dataType);
if (resolutionResult.conflict) { if (resolutionResult.conflict) {
Log.warning("For data " + dataType + ":"); Log.warning("For data " + dataType + ":\n"
for (Chat cmp : ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true)) + ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true).stream()
Log.warning(cmp.getLegacyText()); .map(cmp -> cmp.getLegacyText())
.collect(Collectors.joining(ChatColor.RESET + "\n")));
} }
return resolutionResult.result != null ? resolutionResult.result : ""; return resolutionResult.result != null ? resolutionResult.result : "";
@ -309,9 +310,10 @@ public class PermissionsResolver {
PermResolutionNode resolutionResult = resolvePermission(entity, permission, server, world, true); PermResolutionNode resolutionResult = resolvePermission(entity, permission, server, world, true);
if (resolutionResult.conflict) { if (resolutionResult.conflict) {
Log.warning("For permission " + permission + ":"); Log.warning("For permission " + permission + ":\n"
for (Chat cmp : ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true)) + ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true).stream()
Log.warning(cmp.getLegacyText()); .map(cmp -> cmp.getLegacyText())
.collect(Collectors.joining(ChatColor.RESET + "\n")));
} }
return resolutionResult.result; return resolutionResult.result;

View File

@ -9,11 +9,11 @@ public class Log {
private static Logger logger; private static Logger logger;
private static AtomicBoolean logDebug = new AtomicBoolean(false); private static AtomicBoolean logDebug = new AtomicBoolean(false);
public static void setDebugState(boolean newVal) { public static void setDebug(boolean newVal) {
logDebug.set(newVal); logDebug.set(newVal);
} }
public static boolean getDebugState() { public static boolean isDebugEnabled() {
return logDebug.get(); return logDebug.get();
} }