Skip to content

Commit f84becc

Browse files
committed
MCR-3753 add command to delete all permissions
1 parent c7b9e3b commit f84becc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

mycore-base/src/main/java/org/mycore/frontend/cli/MCRAccessCommands.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import org.jdom2.output.XMLOutputter;
3737
import org.mycore.access.MCRAccessManager;
3838
import org.mycore.access.MCRRuleAccessInterface;
39+
import org.mycore.access.mcrimpl.MCRAccessStore;
40+
import org.mycore.access.mcrimpl.MCRRuleMapping;
41+
import org.mycore.access.mcrimpl.MCRRuleStore;
3942
import org.mycore.common.MCRException;
4043
import org.mycore.common.config.MCRConfiguration2;
4144
import org.mycore.common.xsl.uriresolver.MCRURIResolver;
@@ -155,6 +158,34 @@ public static void deleteAllPermissions() {
155158
}
156159
}
157160

161+
/**
162+
* delete all permissions and rules
163+
* {@link #permissionUpdateForID(String, String, String)} and
164+
* {@link #permissionFileUpdateForID(String, String, String)}
165+
*/
166+
@MCRCommand(syntax = "delete all acl rules and mappings",
167+
help = "Remove all permission and rule entries from the Access Control System.",
168+
order = 35)
169+
public static void deleteAllAclRulesAndMappings() {
170+
MCRAccessStore accessStore = MCRAccessStore.obtainInstance();
171+
Collection<String> accessIds = accessStore.getDistinctStringIDs();
172+
for (String accessId : accessIds) {
173+
Collection<String> pools = accessStore.getPoolsForObject(accessId);
174+
for (String pool : pools) {
175+
MCRRuleMapping rule = accessStore.getAccessDefinition(pool, accessId);
176+
if (LOGGER.isInfoEnabled()) {
177+
LOGGER.info("deleting {} / {} / {}", accessId, pool, rule.getRuleId());
178+
}
179+
accessStore.deleteAccessDefinition(rule);
180+
}
181+
}
182+
MCRRuleStore ruleStore = MCRRuleStore.obtainInstance();
183+
Collection<String> ruleIds = ruleStore.retrieveAllIDs();
184+
for (String ruleId : ruleIds) {
185+
ruleStore.deleteRule(ruleId);
186+
}
187+
}
188+
158189
/**
159190
* delete the permission {0}
160191
*

0 commit comments

Comments
 (0)