读书人

Shiro 权限框架施用总结

发布时间: 2012-08-01 17:53:40 作者: rapoo

Shiro 权限框架使用总结

apache shiro能做什么?

支持认证跨一个或多个数据源(LDAP,JDBC,kerberos身份等)

执行授权,基于角色的细粒度的权限控制。

增强的缓存的支持。

支持web或者非web环境,可以在任何单点登录(SSO)或集群分布式会话中使用。

主要功能是:认证,授权,会话管理和加密。

下载并且使用

1,确保系统内安装JDK1.5+和maven2.2+。

2,到shiro主页下载shiro.

3,解压缩

Quickstart.java

你可以得到http的session信息,也可以在非web环境中使用,得到相对应的会话信息。

如果在web应用程序中部署应用,默认情况下,应用将以HttpSession为基础。在企业级应用中,你在多个应用中可以使用相同的API,无论部署环境。而且使用任何客户端技术你都可以共享会话数据。

接下来判断登录信息

如果正确可以向下执行,如果不正确,就会对不同的业务进行处理。

比如用户名不正确,密码不正确,用户被锁定的异常,当然也可以使用自定义抛出的异常。

如果登录成功,那么下一步可以做什么呢?

提示当前用户:

接着测试是否还有其它角色

最后是使用程序注销:

应用程序调用subject(主题),主题可以是一个用户也可以是与系统交互的另一个系统,主题绑定shiro的权限管理,SecurityManager(安全管理),它控制与有与主题相关的安全操作。Realm(桥梁)它是安全与数据之间的桥,它封装了比如DAO的配置信息,可以指定连接的数据源,也可使用其它的认证方式,如LDAP等。

然后看一下详细的架构图:

Shiro 权限框架施用总结

Subject (org.apache.shiro.subject.Subject)

主题:与系统交互的第三方如(用户,cron服务,第三方应用)等。

SecurityManager (org.apache.shiro.mgt.SecurityManager)

shiro系统的核心,协调主题使用的操作,验证,配置等。

Authenticator (org.apache.shiro.authc.Authenticator)

身份验证组件,对企图登录系统的用户进行身份的验证。其中包含一个Authentication Strategy

?(org.apache.shiro.authc.pam.AuthenticationStrategy)组件。配置验证成功与失败的条件。

Authorizer (org.apache.shiro.authz.Authorizer)

授权组件,指用户访问特定应用程序的机制。

SessionManager (org.apache.shiro.session.mgt.SessionManager)

管理会话如何创建生命周期。其中包括的sessiondao是管理会议数据的持久操作:SessionDAO (org.apache.shiro.session.mgt.eis.SessionDAO),代表执行sessionManager的CRUD操作。

CacheManager (org.apache.shiro.cache.CacheManager)

缓存管理模块。

Cryptography (org.apache.shiro.crypto.*)

加密模块。

Realms (org.apache.shiro.realm.Realm)

多种方式处理的桥梁。

?

多种配置方式:

与spring,jboss,guice等进行配置。

1,编程方式配置

例如:

身份认证分三个步骤

1)提交主题和凭据

2)进行身份认证

3)判断是通过,重新提交还是不通过

验证顺序

Shiro 权限框架施用总结

1)调用subject的login方法,提交主体和凭据。

2)得到对应操作的Security Manager

3)通过Sceurity Manager得到对应的Autherticator实例

4)根据配置策略查找对应的桥信息

5)通过桥信息到对应的配置处理进行身份验证

验证器

如果你想配置一个自定义的验证器

可以在配置文件中使用

控制谁有权限访问应用程序

授权的几个要素:权限,角色和用户。

三种权限的判断方式

1)编程

角色判断

1)应用程序调用主题,判断hasRole,isPermitted得到角色或者用户权限的列表。

2)组成对应的授权方法

3)协调如何授权

4)通过桥进行各种方式的授权

?

web应用

配置web.xml

AccountNotFoundException,账号不存在异常

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

[users]root = secret, adminsally = 1234, superviserdan = 123, user

用户?root 密码secret 角色admin

用户?sally 密码1234 角色superviser

用户?dan密码123 角色user

角色信息包括

[roles]admin = bankAccount:*superviser = bankAccount:create, bankAccount:read bankAccount:closeuser = bankAccount:create, bankAccount:read, bankAccount:operate

包括种种操作的权限分配

使用junit测试

@BeforeClasspublic static void setUpClass() throws Exception {BasicConfigurator.resetConfiguration();BasicConfigurator.configure();logger = Logger.getLogger(SecureBankServiceTest.class.getSimpleName());Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiroBankServiceTest.ini");SecurityManager securityManager = factory.getInstance();SecurityUtils.setSecurityManager(securityManager);service = new SecureBankService();service.start();}

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

登录用户的操作方法

// 作为用户登录,不能关闭账户protected void loginAsUser() {if (_subject == null) {_subject = SecurityUtils.getSubject();}// use dan to run as a normal user (which cannot close an account)_subject.login(new UsernamePasswordToken("dan", "123"));}// 作为超级用户登录,不能操作账户protected void loginAsSuperviser() {if (_subject == null) {_subject = SecurityUtils.getSubject();}// use sally to run as a superviser (which cannot operate an account)_subject.login(new UsernamePasswordToken("sally", "1234"));}

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

@Testpublic void testCreateAccount() throws Exception {loginAsUser();createAndValidateAccountFor("张三");}protected long createAndValidateAccountFor(String anOwner) throws Exception {long createdId = service.createNewAccount(anOwner);assertAccount(anOwner, true, 0.0d, 0, createdId);return createdId;}public static void assertAccount(String eOwnerName, boolean eIsActive,double eBalance, int eTxLogCount, long actualAccountId)throws Exception {Assert.assertEquals(eOwnerName, service.getOwnerOf(actualAccountId));Assert.assertEquals(eIsActive, service.isAccountActive(actualAccountId));Assert.assertEquals(eBalance, service.getBalanceOf(actualAccountId));Assert.assertEquals(eTxLogCount,service.getTxHistoryFor(actualAccountId).length);}

看打印出来的信息

1 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]10 [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]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...59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...62 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1120 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]120 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison121 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]121 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.121 [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.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.123 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...132 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 张三203 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71]203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71]205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71]205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71]205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71]206 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan206 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [66208001-e91d-4625-938f-1b1c08b2645c]208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

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

第二个测试

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

@Testpublic void testDepositInto_singleTx() throws Exception {loginAsUser();long accountId = createAndValidateAccountFor("李四");makeDepositAndValidateAccount(accountId, 250.00d, "李四");}
protected double makeDepositAndValidateAccount(long anAccountId,???double anAmount, String eOwnerName) throws Exception {??double previousBalance = service.getBalanceOf(anAccountId);??int previousTxCount = service.getTxHistoryFor(anAccountId).length;??double newBalance = service.depositInto(anAccountId, anAmount);??Assert.assertEquals(previousBalance + anAmount, newBalance);??assertAccount(eOwnerName, true, newBalance, 1 + previousTxCount,????anAccountId);??return newBalance;?}

运行后的结果

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...46 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...56 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...59 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison115 [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.116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.116 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.117 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...124 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]171 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 李四188 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 250.0 这个账户 1193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991]196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-12 20:44:15.013]196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 250.0196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991]196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991]196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991]196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991]196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-12 20:44:15.013]196 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan197 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [3b53dc16-67d5-4730-ae8a-872d113c7546]198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

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

@Testpublic void testDepositInto_multiTxs() throws Exception {loginAsUser();long accountId = createAndValidateAccountFor("王五");makeDepositAndValidateAccount(accountId, 50.00d, "王五");makeDepositAndValidateAccount(accountId, 300.00d, "王五");makeDepositAndValidateAccount(accountId, 85.00d, "王五");assertAccount("王五", true, 435.00d, 3, accountId);}

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

看日志打出来的信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]10 [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]46 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [roles] section.  Processing...49 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...62 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison119 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]119 [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.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.120 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.121 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...129 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 王五204 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]204 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1204 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 50.0 这个账户 1207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72]210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 50.0210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 300.0 这个账户 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741]211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 350.0211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741]212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741]212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 85.0 这个账户 1212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742]212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 435.0212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741]213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72]214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739]214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741]214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742]214 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan214 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [1d66c2ec-a668-478a-8f30-e3c65f80a16d]216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

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

@Test(expected = NotEnoughFundsException.class)public void testWithdrawFrom_emptyAccount() throws Exception {loginAsUser();long accountId = createAndValidateAccountFor("贾六");service.withdrawFrom(accountId, 100.00d);}

看执行的结果

1 [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]15 [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...50 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...60 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...63 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1126 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]126 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison128 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]128 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.129 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.130 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.132 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...145 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 贾六205 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 100.0 从账户 1208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029]210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 20:56:05.047]210 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan210 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [05f3559d-d0c4-458c-a220-31389550576f]211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

得到期望的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);}

看打印出的日志信息

0 [main] DEBUG org.apache.shiro.io.ResourceUtils  - Opening resource from class path [shiroBankServiceTest.ini]10 [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...48 [main] DEBUG org.apache.shiro.realm.text.IniRealm  - Discovered the [users] section.  Processing...59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务开始...61 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison119 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]119 [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.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.120 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.121 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...131 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager  - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]179 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户给 周七196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 50.0 这个账户 1199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936]200 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建一个新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 21:01:30.955]200 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 50.0200 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936]201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936]201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936]201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936]201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 查过交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 21:01:30.955]201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 100.0 从账户 1201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936]201 [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:01:30.956]202 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan202 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [a85a89c7-a805-4086-bd5b-109a0d54086c]203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

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

@Testpublic void testWithdrawFrom_singleTx() throws Exception {loginAsUser();long accountId = createAndValidateAccountFor("国八");makeDepositAndValidateAccount(accountId, 500.00d, "国八");makeWithdrawalAndValidateAccount(accountId, 100.00d, "国八");assertAccount("国八", true, 400.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]10 [main] DEBUG org.apache.shiro.config.Ini  - Parsing [roles]11 [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  - 银行服务开始...59 [main] INFO SecureBankServiceTest  - ############################ 开始测试用例 1115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String]115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher  - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison116 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator  - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false].  Returned account [dan]116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext  - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.116 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - No sessionValidationScheduler set.  Attempting to create default instance.117 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager  - Enabling session validation scheduler...124 [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  - 创建新的账户给 国八185 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 创建新的账户: Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 存钱到 500.0 这个账户 1188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085]190 [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:03:17.103]190 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 存款后 500.0190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]191 [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:03:17.103]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]191 [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:03:17.103]191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 取款 100.0 从账户 1191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085]192 [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:03:17.104]192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService  - 新的账户余额 1 取款后 400.0192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]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:03:17.103]192 [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:03:17.104]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户的活动状态 1192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 得到账户的余额 1193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获取账户交易 1193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 检查账户 Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085]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:03:17.103]193 [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:03:17.104]193 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager  - Logging out subject with primary principal {}dan193 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager  - Stopping session with id [192dddd6-7090-435c-bb65-b3b64a73d667]195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止...195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 银行服务停止!

存入一笔取多笔

@Testpublic 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  - ############################ 开始测试用例 1132 [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 comparison133 [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 Smith205 [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  - 获得银行账户的所有者 1205 [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  - 获取账户的活动状态 1207 [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  - 得到账户的余额 1207 [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  - 获取账户交易 1208 [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  - 得到账户的余额 1209 [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  - 获取账户交易 1209 [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 这个账户 1209 [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.0212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1212 [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  - 获取账户的活动状态 1212 [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  - 得到账户的余额 1212 [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  - 获取账户交易 1212 [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  - 得到账户的余额 1213 [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  - 获取账户交易 1213 [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 从账户 1213 [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.0213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1213 [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  - 获取账户的活动状态 1213 [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  - 得到账户的余额 1214 [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  - 获取账户交易 1214 [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  - 得到账户的余额 1214 [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  - 获取账户交易 1214 [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 从账户 1214 [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.0215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1215 [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  - 获取账户的活动状态 1215 [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  - 得到账户的余额 1215 [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  - 获取账户交易 1215 [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  - 得到账户的余额 1215 [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  - 获取账户交易 1216 [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 从账户 1216 [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.0216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1216 [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  - 获取账户的活动状态 1216 [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  - 得到账户的余额 1216 [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  - 获取账户交易 1216 [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  - 获得银行账户的所有者 1217 [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  - 获取账户的活动状态 1217 [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  - 得到账户的余额 1220 [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  - 获取账户交易 1221 [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 {}dan221 [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  - 银行服务停止!

存多少取多少

@Testpublic 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  - ############################ 开始测试用例 1114 [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 comparison114 [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 Smith186 [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  - 获得银行账户的所有者 1187 [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  - 获取账户的活动状态 1188 [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  - 得到账户的余额 1188 [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  - 获取账户交易 1188 [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  - 得到账户的余额 1189 [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  - 获取账户交易 1189 [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 这个账户 1190 [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.0192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1192 [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  - 获取账户的活动状态 1192 [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  - 得到账户的余额 1192 [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  - 获取账户交易 1192 [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  - 得到账户的余额 1192 [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  - 获取账户交易 1193 [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 从账户 1193 [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.0193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1193 [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  - 获取账户的活动状态 1193 [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  - 得到账户的余额 1193 [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  - 获取账户交易 1193 [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  - 获得银行账户的所有者 1194 [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  - 获取账户的活动状态 1194 [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  - 得到账户的余额 1194 [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  - 获取账户交易 1194 [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 {}dan195 [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的账户,普通用户没有权限,所以需要转到另外一个角色的账户进行操作

@Testpublic 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  - ############################ 开始测试用例 1121 [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 comparison121 [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 Smith207 [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  - 获得银行账户的所有者 1207 [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  - 获取账户的活动状态 1209 [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  - 得到账户的余额 1209 [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  - 获取账户交易 1209 [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 {}dan210 [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 comparison211 [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  - 截止账户 1211 [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  - 获得银行账户的所有者 1213 [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  - 获取账户的活动状态 1214 [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  - 得到账户的余额 1214 [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  - 获取账户交易 1214 [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 {}sally214 [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,然后对这个用户进行关闭操作

@Testpublic void testCloseAccount_withBalance() throws Exception {loginAsUser();long accountId = createAndValidateAccountFor("Gerry Smith");makeDepositAndValidateAccount(accountId, 385.00d, "Gerry Smith");logoutCurrentSubject();loginAsSuperviser();double closingBalance = service.closeAccount(accountId);Assert.assertEquals(385.00d, closingBalance);assertAccount("Gerry Smith", false, 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]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  - ############################ 开始测试用例 1117 [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 comparison118 [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 Smith190 [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  - 获得银行账户的所有者 1190 [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  - 获取账户的活动状态 1191 [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  - 得到账户的余额 1192 [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  - 获取账户交易 1192 [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  - 得到账户的余额 1193 [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  - 获取账户交易 1193 [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 这个账户 1193 [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.0195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService  - 获得银行账户的所有者 1195 [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  - 获取账户的活动状态 1195 [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  - 得到账户的余额 1196 [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  - 获取账户交易 1196 [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 {}dan196 [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 comparison197 [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  - 截止账户 1197 [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  - 获得银行账户的所有者 1197 [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  - 获取账户的活动状态 1197 [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  - 得到账户的余额 1198 [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  - 获取账户交易 1198 [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 {}sally198 [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  - ############################ 开始测试用例 1117 [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 comparison117 [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 Smith195 [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  - 获得银行账户的所有者 1195 [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  - 获取账户的活动状态 1196 [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  - 得到账户的余额 1196 [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  - 获取账户交易 1197 [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 {}dan198 [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 comparison199 [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  - 截止账户 1199 [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  - 获得银行账户的所有者 1201 [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  - 获取账户的活动状态 1201 [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  - 得到账户的余额 1201 [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  - 获取账户交易 1201 [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  - 截止账户 1202 [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 {}sally202 [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") 关闭权限

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