use of org.exist.security.AbstractPrincipal in project exist by eXist-db.
the class RealmImpl method deleteGroup.
@Override
public boolean deleteGroup(final Group group) throws PermissionDeniedException, EXistException {
if (group == null) {
return false;
}
groupsByName.<PermissionDeniedException, EXistException>write2E(principalDb -> {
final AbstractPrincipal remove_group = (AbstractPrincipal) principalDb.get(group.getName());
if (remove_group == null) {
throw new IllegalArgumentException("Group does '" + group.getName() + "' not exist!");
}
if (SecurityManager.DBA_GROUP.equals(group.getName()) || SecurityManager.GUEST_GROUP.equals(group.getName()) || SecurityManager.UNKNOWN_GROUP.equals(group.getName())) {
throw new PermissionDeniedException("The '" + group.getName() + "' group is required by the system for correct operation, you cannot delete it!");
}
final DBBroker broker = getDatabase().getActiveBroker();
final Subject subject = broker.getCurrentSubject();
((Group) remove_group).assertCanModifyGroup(subject);
// check that this is not an active primary group
final Optional<String> isPrimaryGroupOf = usersByName.read(usersDb -> {
for (final Account account : usersDb.values()) {
final Group accountPrimaryGroup = account.getDefaultGroup();
if (accountPrimaryGroup != null && accountPrimaryGroup.getId() == remove_group.getId()) {
return Optional.of(account.getName());
}
}
return Optional.empty();
});
if (isPrimaryGroupOf.isPresent()) {
throw new PermissionDeniedException("Account '" + isPrimaryGroupOf.get() + "' still has '" + group.getName() + "' as their primary group!");
}
remove_group.setRemoved(true);
remove_group.setCollection(broker, collectionRemovedGroups, XmldbURI.create(UUIDGenerator.getUUID() + ".xml"));
try (final Txn txn = broker.continueOrBeginTransaction()) {
collectionGroups.removeXMLResource(txn, broker, XmldbURI.create(remove_group.getName() + ".xml"));
txn.commit();
} catch (final Exception e) {
LOG.warn(e.getMessage(), e);
}
getSecurityManager().registerGroup((Group) remove_group);
principalDb.remove(remove_group.getName());
});
return true;
}
Aggregations