}
usersByName.modify2E(new PrincipalDbModify2E<Account, PermissionDeniedException, EXistException>(){
@Override
public void execute(Map<String, Account> principalDb) throws PermissionDeniedException, EXistException {
final AbstractAccount remove_account = (AbstractAccount)principalDb.get(account.getName());
if(remove_account == null){
throw new IllegalArgumentException("No such account exists!");
}
DBBroker broker = null;
try {
broker = getDatabase().get(null);
final Account user = broker.getSubject();
if(!(account.getName().equals(user.getName()) || user.hasDbaRole()) ) {
throw new PermissionDeniedException("You are not allowed to delete '" +account.getName() + "' user");
}
remove_account.setRemoved(true);
remove_account.setCollection(broker, collectionRemovedAccounts, XmldbURI.create(UUIDGenerator.getUUID()+".xml"));
final TransactionManager transaction = getDatabase().getTransactionManager();
Txn txn = null;
try {
txn = transaction.beginTransaction();
collectionAccounts.removeXMLResource(txn, broker, XmldbURI.create( remove_account.getName() + ".xml"));
transaction.commit(txn);
} catch(final Exception e) {
transaction.abort(txn);
e.printStackTrace();
LOG.debug("loading configuration failed: " + e.getMessage());
} finally {
transaction.close(txn);
}
getSecurityManager().addUser(remove_account.getId(), remove_account);
principalDb.remove(remove_account.getName());
} finally {
getDatabase().release(broker);
}
}
});