From fe322ecf16fed4eefead6848b36845278f61ea22 Mon Sep 17 00:00:00 2001 From: Torsten Krause Date: Wed, 1 Jul 2026 16:19:45 +0200 Subject: [PATCH] MCR-3753 add command to delete all permissions --- .../frontend/cli/MCRAccessCommands.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRAccessCommands.java b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRAccessCommands.java index 3f73e4cf16..c01f6b4258 100644 --- a/mycore-base/src/main/java/org/mycore/frontend/cli/MCRAccessCommands.java +++ b/mycore-base/src/main/java/org/mycore/frontend/cli/MCRAccessCommands.java @@ -36,6 +36,9 @@ import org.jdom2.output.XMLOutputter; import org.mycore.access.MCRAccessManager; import org.mycore.access.MCRRuleAccessInterface; +import org.mycore.access.mcrimpl.MCRAccessStore; +import org.mycore.access.mcrimpl.MCRRuleMapping; +import org.mycore.access.mcrimpl.MCRRuleStore; import org.mycore.common.MCRException; import org.mycore.common.config.MCRConfiguration2; import org.mycore.common.xsl.uriresolver.MCRURIResolver; @@ -155,6 +158,42 @@ public static void deleteAllPermissions() { } } + /** + * delete all ACL rule mappings and rules + */ + @MCRCommand(syntax = "delete all acl rules and mappings", + help = "Remove all rule mappings and rules from the Access Control System.", + order = 35) + public static void deleteAllAclRulesAndMappings() { + deleteAllAclMappings(); + MCRRuleStore ruleStore = MCRRuleStore.obtainInstance(); + for (String id : ruleStore.retrieveAllIDs()) { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("deleting rul {}", id); + } + ruleStore.deleteRule(id); + } + } + + /** + * delete all ACL rule mappings + */ + @MCRCommand(syntax = "delete all acl mappings", + help = "Remove all rule mappings from the Access Control System.", + order = 35) + public static void deleteAllAclMappings() { + MCRAccessStore store = MCRAccessStore.obtainInstance(); + for (String id : store.getDistinctStringIDs()) { + for (String pool : store.getPoolsForObject(id)) { + MCRRuleMapping rule = store.getAccessDefinition(pool, id); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("deleting rule mapping {} / {} / {}", id, pool, rule.getRuleId()); + } + store.deleteAccessDefinition(rule); + } + } + } + /** * delete the permission {0} *