@RequiresPermissions("bankAccount:close")
    public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException {
        assertServiceState();
        LOGGER.info("Closing account " + anAccountId);

        Account a = safelyRetrieveAccountForId(anAccountId);
        if (!a.isActive()) {
            throw new InactiveAccountException("The account " + anAccountId + " is already closed");
        }

        try {
            AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance());
            tx.setCreatedBy(getCurrentUsername());
            LOGGER.debug("Created a new transaction " + tx);
            a.applyTransaction(tx);
            a.setActive(false);

            LOGGER.debug("Account " + a.getId() + " is now closed and an amount of " + tx.getAmount() + " is given to the owner");
            return tx.getAmount();

        } catch (NotEnoughFundsException nefe) {
            throw new IllegalStateException("Should never happen", nefe);
        }
    }
Internal utility method that validate the internal state of this service.
samples/aspectj/src/main/java/org/apache/shiro/samples/aspectj/bank/SecureBankService.java