shiro(4)-银行示例

在官方的示例中,有一个aspectj的示例,这个是一个银行的示例,简单的做了一下修改,演示一下其中几个方法的使用过程。

看以下几个类,包括账户信息,转账信息,以及一些异常处理程序,还包括一个业务操作类

Account账户信息类

AccountNotFoundException,账号不存在异常

AccountTransaction,账号转入与转出

BankServerRunner,银行服务运行

 BankService,银行服务接口

BankServiceException,银行服务异常

InactiveAccountException,存入账户异常

NotEnoughFundsException,账户不足异常

SecureBankService,安全银行的服务类,处理各种银行的业务

在配置文件中配置了三组账户

用户 root 密码secret 角色admin

用户 sally 密码1234 角色superviser

用户 dan密码123 角色user

角色信息包括

包括种种操作的权限分配

使用junit测试

加载对应的ini中的信息,在每次运行之前

登录用户的操作方法

给张三创建账户,并且检查账户的情况

看打印出来的信息

创建张三的用户信息并且检查张三的账户的情况。

第二个测试

创建账户李四并且存入250到账户里,用户有创建和操作的权限,所以可以操作

运行后的结果

创建账户王五并且存入多笔款项

一共存入三笔,最后得到的数据的总和为435

看日志打出来的信息

创建账户贾六并且取款,因为账户为空所以会抛出异常

看执行的结果

得到期望的NotEnoughFundsException,运行通过

然后创建账户周七,先存入50,然后取100,结果得到的与面相同,余额不足异常

@Test(expected = NotEnoughFundsException.class)
public void testWithdrawFrom_notEnoughFunds() throws Exception {
    loginAsUser();
    long accountId = createAndValidateAccountFor("周七");
    makeDepositAndValidateAccount(accountId, 50.00d, "周七");
    service.withdrawFrom(accountId, 100.00d);
}

看打印出的日志信息

再测试先存后取,先存入500,后取100,最后得到的结果为400

看打印出的结果

存入一笔取多笔

@Test
public void testWithdrawFrom_manyTxs() throws Exception {
    loginAsUser();
    long accountId = createAndValidateAccountFor("Zoe Smith");
    makeDepositAndValidateAccount(accountId, 500.00d, "Zoe Smith");
    makeWithdrawalAndValidateAccount(accountId, 100.00d, "Zoe Smith");
    makeWithdrawalAndValidateAccount(accountId, 75.00d, "Zoe Smith");
    makeWithdrawalAndValidateAccount(accountId, 125.00d, "Zoe Smith");
    assertAccount("Zoe Smith", true, 200.00d, 4, accountId);
}

查看打印的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]
9 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [users]
11 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]
13 [main] DEBUG org.apache.shiro.config.IniFactorySupport  - Creating instance from Ini [sections=users,roles]
53 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...
57 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...
72 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...
76 [main] INFO SecureBankServiceTest  -
 
#########################
### 开始测试用例 1
 
132 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
132 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
133 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]
133 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
133 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
134 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.
135 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...
143 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 Zoe Smith
205 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 500.0 这个账户 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 500.0
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 100.0 从账户 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 取款后 400.0
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 75.0 从账户 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339]
215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 取款后 325.0
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339]
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 125.0 从账户 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 取款后 200.0
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339]
217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341]
217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
220 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
220 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
221 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312]
221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337]
221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338]
221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339]
221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341]
221 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan
221 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [1ecbe8f2-f2f5-468b-af2b-d82d6b1267fa]
223 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...
223 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

存多少取多少

@Test
    public void testWithdrawFrom_upToZero() throws Exception {
        loginAsUser();
        long accountId = createAndValidateAccountFor("Zoe Smith");
        makeDepositAndValidateAccount(accountId, 500.00d, "Zoe Smith");
        makeWithdrawalAndValidateAccount(accountId, 500.00d, "Zoe Smith");
        assertAccount("Zoe Smith", true, 0.00d, 2, accountId);
    }

查看打印的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]
9 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [users]
11 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]
12 [main] DEBUG org.apache.shiro.config.IniFactorySupport  - Creating instance from Ini [sections=users,roles]
43 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...
45 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...
55 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...
58 [main] INFO SecureBankServiceTest  -
 
#########################
### 开始测试用例 1
 
114 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
114 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
114 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]
115 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
115 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
115 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.
116 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...
125 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
168 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 Zoe Smith
186 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 500.0 这个账户 1
190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804]
192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 500.0
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 500.0 从账户 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806]
193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 取款后 0.0
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804]
193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806]
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783]
194 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804]
194 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806]
194 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan
195 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [12aeb47c-f3c1-46c1-baec-78da03762422]
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

关闭账户余额为0的账户,普通用户没有权限,所以需要转到另外一个角色的账户进行操作

@Test
    public void testCloseAccount_zeroBalance() throws Exception {
        loginAsUser();
        long accountId = createAndValidateAccountFor("Chris Smith");
 
        logoutCurrentSubject();
        loginAsSuperviser();
        double closingBalance = service.closeAccount(accountId);
        Assert.assertEquals(0.00d, closingBalance);
        assertAccount("Chris Smith", false, 0.00d, 1, accountId);
    }

查看打印出来的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]
11 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [users]
13 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]
14 [main] DEBUG org.apache.shiro.config.IniFactorySupport  - Creating instance from Ini [sections=users,roles]
47 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...
50 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...
61 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...
63 [main] INFO SecureBankServiceTest  -
 
#########################
### 开始测试用例 1
 
121 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
121 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
121 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]
122 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
122 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
123 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.
124 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...
133 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 Chris Smith
207 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
210 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan
210 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [c4adc0a6-987c-4c94-ad38-d13f683c7f1d]
211 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
211 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
211 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false].  Returned account [sally]
211 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
211 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
211 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 截止账户 1
211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易  AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:13:04.516]
213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 账户 1 现在是关闭的 0.0 针对这个业主
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496]
214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:13:04.516]
214 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}sally
214 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [f0988257-3441-489a-859c-538043ead6e3]
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...
215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

创建用户并且存入350,然后对这个用户进行关闭操作

查看打印的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]
9 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [users]
11 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]
12 [main] DEBUG org.apache.shiro.config.IniFactorySupport  - Creating instance from Ini [sections=users,roles]
46 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...
48 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...
58 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...
61 [main] INFO SecureBankServiceTest  -
 
#########################
### 开始测试用例 1
 
117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
118 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]
118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
118 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.
119 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...
128 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
173 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 Gerry Smith
190 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 385.0 这个账户 1
193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672]
195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 385.0
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672]
196 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan
196 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [b2e689a3-cd4a-4785-962b-0df77758533b]
197 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
197 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
197 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false].  Returned account [sally]
197 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
197 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
197 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 截止账户 1
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
197 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易  AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-12 21:17:58.674]
197 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 账户 1 现在是关闭的 385.0 针对这个业主
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652]
198 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672]
198 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-12 21:17:58.674]
198 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}sally
198 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [6ffa0d67-7510-4205-9fa8-01b6bb9793f5]
199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...
199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

创建用户并且关闭正活动的账户

@Test(expected = InactiveAccountException.class)
    public void testCloseAccount_alreadyClosed() throws Exception {
        loginAsUser();
        long accountId = createAndValidateAccountFor("Chris Smith");
 
        logoutCurrentSubject();
        loginAsSuperviser();
        double closingBalance = service.closeAccount(accountId);
        Assert.assertEquals(0.00d, closingBalance);
        assertAccount("Chris Smith", false, 0.00d, 1, accountId);
        service.closeAccount(accountId);
    }

查看打印的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]
9 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [users]
12 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]
13 [main] DEBUG org.apache.shiro.config.IniFactorySupport  - Creating instance from Ini [sections=users,roles]
44 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...
47 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...
57 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...
60 [main] INFO SecureBankServiceTest  -
 
#########################
### 开始测试用例 1
 
117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
117 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]
118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
119 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.
120 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...
127 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
178 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 Chris Smith
195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
198 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan
198 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [8ff8f7c8-5d03-4e4f-b47d-0414cd43111d]
198 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]
198 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
199 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false].  Returned account [sally]
199 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
199 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
199 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 截止账户 1
199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易  AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:19:53.777]
201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 账户 1 现在是关闭的 0.0 针对这个业主
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1
201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:19:53.777]
202 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 截止账户 1
202 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755]
202 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}sally
202 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [53286615-5b71-4642-b3e8-916fb77fba60]
203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...
203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

其中判断权限使用的是annocation的方式

@RequiresPermissions("bankAccount:create") 是否有用户创建权限

@RequiresPermissions("bankAccount:read") 读权限

@RequiresPermissions("bankAccount:operate") 操作权限

@RequiresPermissions("bankAccount:close") 关闭权限

根据以上几个标签就可以得到对应的权限信息

 

posted @   skyme  阅读(4060)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示