Shiro 权限框架使用总结
2017-03-15 00:00
411 查看
我们首先了解下什么是shiro,Shiro是JAVA世界中新近出现的权限框架,较之JAAS和SpringSecurity,Shiro在保持强大功能的同时,还在简单性和灵活性方面拥有巨大优势
Shiro是一个强大而灵活的开源安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密。如下是它所具有的特点:
易于理解的JavaSecurityAPI;
简单的身份认证(登录),支持多种数据源(LDAP,JDBC,Kerberos,ActiveDirectory等);
对角色的简单的签权(访问控制),支持细粒度的签权;
支持一级缓存,以提升应用程序的性能;
内置的基于POJO企业会话管理,适用于Web以及非Web的环境;
异构客户端会话访问;
非常简单的加密API;
不跟任何的框架或者容器捆绑,可以独立运行。
Authenticator对“Whoareyou?”进行核实。通常涉及用户名和密码。
这个组件负责收集principals和credentials,并将它们提交给应用系统。如果提交的credentials跟应用系统中提供的credentials吻合,就能够继续访问,否则需要重新提交principals和credentials,或者直接终止访问。
Authorizer身份份验证通过后,由这个组件对登录人员进行访问控制的筛查,比如“whocandowhat”,或者“whocandowhichactions”。Shiro采用“基于Realm”的方法,即用户(又称Subject)、用户组、角色和permission的聚合体。
SessionManager这个组件保证了异构客户端的访问,配置简单。它是基于POJO/J2SE的,不跟任何的客户端或者协议绑定。
Shiro的认证和签权可以通过JDBC、LDAP或者ActiveDirectory来访问数据库、目录服务器或者ActiveDirectory中的人员以及认证/签权信息。SessionManager通过会话DAO可以将会话保存在cache中,或者固化到数据库或文件系统中。
简介
apacheshiro是一个功能强大和易于使用的Java安全框架,为开发人员提供一个直观而全面的的解决方案的认证,授权,加密,会话管理。
在实际应用中,它实现了应用程序的安全管理的各个方面。
shiro的功能
apacheshiro能做什么?
支持认证跨一个或多个数据源(LDAP,JDBC,kerberos身份等)
执行授权,基于角色的细粒度的权限控制。
增强的缓存的支持。
支持web或者非web环境,可以在任何单点登录(SSO)或集群分布式会话中使用。
主要功能是:认证,授权,会话管理和加密。
下载并且使用
1,确保系统内安装JDK1.5+和maven2.2+。
2,到shiro主页下载shiro.
3,解压缩
unzipshiro-root-1.1.0-source-release.zip
4,进入到quickstart目录
cdshiro-root-1.1.0/samples/quickstart
5,运行quickstart
mvncompileexec:java
执行完成如下图:
//getthecurrentlyexecutinguser:
SubjectcurrentUser=SecurityUtils.getSubject();
使用SecurityUtils.getSubject(),我们可以得到当前正在执行的主题。
得到主题之后,你可以得到他对应的会话信息
//DosomestuffwithaSession(noneedforaweborEJBcontainer!!!)
Sessionsession=currentUser.getSession();
session.setAttribute("someKey","aValue");
Stringvalue=(String)session.getAttribute("someKey");
if(value.equals("aValue")){
log.info("Retrievedthecorrectvalue!["+value+"]");
}
你可以得到http的session信息,也可以在非web环境中使用,得到相对应的会话信息。
如果在web应用程序中部署应用,默认情况下,应用将以HttpSession为基础。在企业级应用中,你在多个应用中可以使用相同的API,无论部署环境。而且使用任何客户端技术你都可以共享会话数据。
接下来判断登录信息
//let'sloginthecurrentusersowecancheckagainstrolesandpermissions:
if(!currentUser.isAuthenticated()){
UsernamePasswordTokentoken=newUsernamePasswordToken("lonestarr","vespa");
token.setRememberMe(true);
try{
currentUser.login(token);
}catch(UnknownAccountExceptionuae){
log.info("Thereisnouserwithusernameof"+token.getPrincipal());
}catch(IncorrectCredentialsExceptionice){
log.info("Passwordforaccount"+token.getPrincipal()+"wasincorrect!");
}catch(LockedAccountExceptionlae){
log.info("Theaccountforusername"+token.getPrincipal()+"islocked."+
"Pleasecontactyouradministratortounlockit.");
}
//...catchmoreexceptionshere(maybecustomonesspecifictoyourapplication?
catch(AuthenticationExceptionae){
//unexpectedcondition?error?
}
}
如果正确可以向下执行,如果不正确,就会对不同的业务进行处理。
比如用户名不正确,密码不正确,用户被锁定的异常,当然也可以使用自定义抛出的异常。
如果登录成功,那么下一步可以做什么呢?
提示当前用户:
//saywhotheyare:
//printtheiridentifyingprincipal(inthiscase,ausername):
log.info("User["+currentUser.getPrincipal()+"]loggedinsuccessfully.");
接着测试是否还有其它角色
//testarole:
if(currentUser.hasRole("schwartz")){
log.info("MaytheSchwartzbewithyou!");
}else{
log.info("Hello,meremortal.");
}
接着测试是否有特定的权限
//testatypedpermission(notinstance-level)
if(currentUser.isPermitted("lightsaber:weild")){
log.info("Youmayusealightsaberring.Useitwisely.");
}else{
log.info("Sorry,lightsaberringsareforschwartzmastersonly.");
}
接着验证一个非常强大的实例级权限
//a(verypowerful)InstanceLevelpermission:
if(currentUser.isPermitted("winnebago:drive:eagle5")){
log.info("Youarepermittedto'drive'thewinnebagowithlicenseplate(id)'eagle5'."+
"Herearethekeys-havefun!");
}else{
log.info("Sorry,youaren'tallowedtodrivethe'eagle5'winnebago!");
}
最后是使用程序注销:
//alldone-logout!
currentUser.logout();
认证就是用户确认身份的过程,确认登录的用户身份能够操作的内容。
使用shiro认证分为以下几个步骤:
1,得到主体的认证和凭据。
viewsourceprint?
2,提交认证和凭据给身份验证系统。
viewsourceprint?
3,判断是否允许访问,重试认证或者阻止访问。
viewsourceprint?
其中RememberMe的功能包括两个方法,一个是
booleanisRemembered()
非匿名登录的用户可以记住上次使用的主题的信息。
booleanisAuthenticated()
在此期间需要使用有效的凭据登录系统,否则值为false.
授权操作
授权的例子就是是否可以访问某个页面,可以操作某个按钮,是否可以编缉对应的数据等。
如何在shiro中使用授权
1,使用编程方式
判断是否有管理员角色
viewsourceprint?
判断用户是否有打印的权限
viewsourceprint?
If(currentUser.isPermitted(printPermission)){
//doonething(showtheprintbutton?)
}else{
//don’tshowthebutton?
}
也可以使用字符串的方式验证
viewsourceprint?
2,使用注释方式
判断用户是否有创建账户权限
viewsourceprint?
判断用户角色,如果符合角色,可以使用对应方法
viewsourceprint?
3,使用jsptaglib
判断用户是否有管理权限
viewsourceprint?
从高的级别来看shiro:
看一下官方的图
应用程序调用subject(主题),主题可以是一个用户也可以是与系统交互的另一个系统,主题绑定shiro的权限管理,SecurityManager(安全管理),它控制与有与主题相关的安全操作。Realm(桥梁)它是安全与数据之间的桥,它封装了比如DAO的配置信息,可以指定连接的数据源,也可使用其它的认证方式,如LDAP等。
然后看一下详细的架构图:
Subject(org.apache.shiro.subject.Subject)
主题:与系统交互的第三方如(用户,cron服务,第三方应用)等。
SecurityManager(org.apache.shiro.mgt.SecurityManager)
shiro系统的核心,协调主题使用的操作,验证,配置等。
Authenticator(org.apache.shiro.authc.Authenticator)
身份验证组件,对企图登录系统的用户进行身份的验证。其中包含一个AuthenticationStrategy
(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,编程方式配置
例如:
viewsourceprint?
2,sessionManager对象图
如果你想使用sessionManager配置自定义的sessionDao信息,进行自定义会话管理
viewsourceprint?
3,INI配置
1)创建一个INI从SecurityManager
可以从多种方式读取INI配置文件的信息,如文件系统,类路径等
viewsourceprint?
2)通过Ini实例读取
类似于Properties的方式
viewsourceprint?
加载之后就可以操作INI的配置了。
4,INI配置
每一个节点都是单独的,不可以重复,注释可以使用#或者;
配置示例
viewsourceprint?
1)[main]
配置sessionManager的实例和它的依赖。
配置示例
viewsourceprint?
定义一个对象
viewsourceprint?
简单的属性设置
viewsourceprint?
配置信息将转入到对应的set方法中
viewsourceprint?
参考值
你可以使用$符号引用先前定义的一个对象的实例
viewsourceprint?
嵌套属性
viewsourceprint?
将被注入到下面的程序中
viewsourceprint?
引用其它的属性
viewsourceprint?
以键值的配置方式
viewsourceprint?
2)[users]
在用户比较少的情况下这种配置信息是有效的
viewsourceprint?
3)[roles]
如果角色信息比较少的情况下可以使用这项配置
viewsourceprint?
4)[urls]
配置url等可访问的资源信息。
身份认证分三个步骤
1)提交主题和凭据
2)进行身份认证
3)判断是通过,重新提交还是不通过
验证顺序
1)调用subject的login方法,提交主体和凭据。
2)得到对应操作的SecurityManager
3)通过SceurityManager得到对应的Autherticator实例
4)根据配置策略查找对应的桥信息
5)通过桥信息到对应的配置处理进行身份验证
验证器
如果你想配置一个自定义的验证器
可以在配置文件中使用
[main]
...
authenticator=com.foo.bar.CustomAuthenticator
securityManager.authenticator=$authenticator
配置策略信息
AtLeastOneSuccessfulStrategy如果一个验证成功,则验证结果为成功
FirstSuccessfulStrategy只有第一个成功,才算成功
AllSuccessfulStrategy所有的都必须成功
对应的在配置文件中的策略使用如下
shiro.ini
[main]
...
authcStrategy=org.apache.shiro.authc.pam.FirstSuccessfulStrategy
securityManager.authenticator.authenticationStrategy=$authcStrategy
...
执行顺序
1)隐式顺序
blahRealm=com.company.blah.Realm
...
fooRealm=com.company.foo.Realm
...
barRealm=com.company.another.Realm
按上下顺序执行
2)指定顺序
blahRealm=com.company.blah.Realm
...
fooRealm=com.company.foo.Realm
...
barRealm=com.company.another.Realm
securityManager.realms=$fooRealm,$barRealm,$blahRealm
...
按指定的顺序执行
授权
控制谁有权限访问应用程序
授权的几个要素:权限,角色和用户。
三种权限的判断方式
1)编程
角色判断
SubjectcurrentUser=SecurityUtils.getSubject();
if(currentUser.hasRole("administrator")){
//showtheadminbutton
}else{
//don'tshowthebutton?Greyitout?
}
hasRole(StringroleName)主题是否已分配给指定的角色
hasRoles(List<String>roleNames)是否包含指定的角色
hasAllRoles(Collection<String>roleNames)是否包含指定的所有角色
角色断言
SubjectcurrentUser=SecurityUtils.getSubject();
//guaranteethatthecurrentuserisabanktellerand
//thereforeallowedtoopentheaccount:
currentUser.checkRole("bankTeller");
openBankAccount();
checkRole(StringroleName)断言是否是指定角色
checkRoles(Collection<String>roleNames)断言是否包含以下角色
checkRoles(String...roleNames)断言是否包含所有角色
如果判断指定用户是否有权限访问指定名称的打印机
那么就会用到下列几个方法
PermissionprintPermission=newPrinterPermission("laserjet4400n","print");
SubjectcurrentUser=SecurityUtils.getSubject();
if(currentUser.isPermitted(printPermission)){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
isPermitted(Permissionp)判断主题是否允许执行一个动作
isPermitted(List<Permission>perms)是否允许执行一组动作
isPermittedAll(Collection<Permission>perms)是否允许执行所有动作
基于字符串的权限检查
SubjectcurrentUser=SecurityUtils.getSubject();
if(currentUser.isPermitted("printer:print:laserjet4400n")){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
也可以如下使用
SubjectcurrentUser=SecurityUtils.getSubject();
Permissionp=newWildcardPermission("printer:print:laserjet4400n");
if(currentUser.isPermitted(p){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
权限断言类似于角色断言。
2)annocation方式
@RequiresAuthentication
publicvoidupdateAccount(AccountuserAccount){
//thismethodwillonlybeinvokedbya
//Subjectthatisguaranteedauthenticated
...
}
等同于下述代码
publicvoidupdateAccount(AccountuserAccount){
if(!SecurityUtils.getSubject().isAuthenticated()){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedauthenticatedhere
...
}
@RequiresGuest
publicvoidsignUp(UsernewUser){
//thismethodwillonlybeinvokedbya
//Subjectthatisunknown/anonymous
...
}
等同于
publicvoidsignUp(UsernewUser){
SubjectcurrentUser=SecurityUtils.getSubject();
PrincipalCollectionprincipals=currentUser.getPrincipals();
if(principals!=null&&!principals.isEmpty()){
//knownidentity-notaguest:
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobea'guest'here
...
}
@RequiresPermissions("account:create")
publicvoidcreateAccount(Accountaccount){
//thismethodwillonlybeinvokedbyaSubject
//thatispermittedtocreateanaccount
...
}
等同于
publicvoidcreateAccount(Accountaccount){
SubjectcurrentUser=SecurityUtils.getSubject();
if(!subject.isPermitted("account:create")){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobepermittedhere
...
}
@RequiresRoles("administrator")
publicvoiddeleteUser(Useruser){
//thismethodwillonlybeinvokedbyanadministrator
...
}
等同于
publicvoiddeleteUser(Useruser){
SubjectcurrentUser=SecurityUtils.getSubject();
if(!subject.hasRole("administrator")){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobean'administrator'here
...
}
@RequiresUser
publicvoidupdateAccount(Accountaccount){
//thismethodwillonlybeinvokedbya'user'
//i.e.aSubjectwithaknownidentity
...
}
等同于
publicvoidupdateAccount(Accountaccount){
SubjectcurrentUser=SecurityUtils.getSubject();
PrincipalCollectionprincipals=currentUser.getPrincipals();
if(principals==null||principals.isEmpty()){
//noidentity-they'reanonymous,notallowed:
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtohaveaknownidentityhere
...
}
授权顺序
1)应用程序调用主题,判断hasRole,isPermitted得到角色或者用户权限的列表。
2)组成对应的授权方法
3)协调如何授权
4)通过桥进行各种方式的授权
web应用
配置web.xml
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
...
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
如果你愿意你可以自定义一个web应用
<context-param>
<param-name>shiroEnvironmentClass</param-name>
<param-value>com.foo.bar.shiro.MyWebEnvironment</param-value>
</context-param>
如果你想改变shiro.ini的位置,那么你可以指定
<context-param>
<param-name>shiroConfigLocations</param-name>
<param-value>YOUR_RESOURCE_LOCATION_HERE</param-value>
</context-param>
shiro.ini中的[urls]配置
例如:
...
[urls]
/index.html=anon
/user/create=anon
/user/**=authc
/admin/**=authc,roles[administrator]
/rest/**=authc,rest
/remoting/rpc/**=authc,perms["remote:invoke"]
假如你有如下设置
/account/**=ssl,authc
/account下的任何应用程序都将触动ssl和authc链
在官方的示例中,有一个aspectj的示例,这个是一个银行的示例,简单的做了一下修改,演示一下其中几个方法的使用过程。
看以下几个类,包括账户信息,转账信息,以及一些异常处理程序,还包括一个业务操作类
Account账户信息类
importorg.apache.commons.lang.builder.ToStringBuilder;
importorg.apache.commons.lang.builder.ToStringStyle;
importjava.sql.Timestamp;
importjava.util.ArrayList;
importjava.util.Date;
importjava.util.List;
publicclassAccount{
privatestaticlong_SEQUENCE;
privatelong_id;
privateString_ownerName;
privatevolatileboolean_isActive;
privatedouble_balance;
privatefinalList<AccountTransaction>_transactions;
privateString_createdBy;
privateDate_creationDate;
publicAccount(StringanOwnerName){
_id=++_SEQUENCE;
_ownerName=anOwnerName;
_isActive=true;
_balance=0.0d;
_transactions=newArrayList<AccountTransaction>();
_createdBy="unknown";
_creationDate=newDate();
}
/**
*Returnstheidattribute.
*
*@returnTheidvalue.
*/
publiclonggetId(){
return_id;
}
/**
*ReturnstheownerNameattribute.
*
*@returnTheownerNamevalue.
*/
publicStringgetOwnerName(){
return_ownerName;
}
/**
*ReturnstheisActiveattribute.
*
*@returnTheisActivevalue.
*/
publicbooleanisActive(){
return_isActive;
}
/**
*ChangesthevalueoftheattributesisActive.
*
*@paramaIsActiveThenewvalueoftheisActiveattribute.
*/
publicvoidsetActive(booleanaIsActive){
_isActive=aIsActive;
}
/**
*ChangesthevalueoftheattributesownerName.
*
*@paramaOwnerNameThenewvalueoftheownerNameattribute.
*/
publicvoidsetOwnerName(StringaOwnerName){
_ownerName=aOwnerName;
}
/**
*Returnsthebalanceattribute.
*
*@returnThebalancevalue.
*/
publicdoublegetBalance(){
return_balance;
}
/**
*Returnsthetransactionsattribute.
*
*@returnThetransactionsvalue.
*/
publicList<AccountTransaction>getTransactions(){
return_transactions;
}
protectedvoidapplyTransaction(AccountTransactionaTransaction)throwsNotEnoughFundsException,InactiveAccountException{
if(!_isActive){
thrownewInactiveAccountException("Unabletoapply"+aTransaction.getType()+"ofamount"+aTransaction.getAmount()+"toaccount"+_id);
}
synchronized(_transactions){
if(AccountTransaction.TransactionType.DEPOSIT==aTransaction.getType()){
_transactions.add(aTransaction);
_balance+=aTransaction.getAmount();
}elseif(AccountTransaction.TransactionType.WITHDRAWAL==aTransaction.getType()){
if(_balance<aTransaction.getAmount()){
thrownewNotEnoughFundsException("Unabletowithdraw"+aTransaction.getAmount()+"$fromaccount"+_id+"-currentbalanceis"+_balance);
}
_transactions.add(aTransaction);
_balance-=aTransaction.getAmount();
}else{
thrownewIllegalArgumentException("Thetransactionpassedinhasaninvalidtype:"+aTransaction.getType());
}
}
}
/**
*ChangesthevalueoftheattributescreatedBy.
*
*@paramaCreatedByThenewvalueofthecreatedByattribute.
*/
protectedvoidsetCreatedBy(StringaCreatedBy){
_createdBy=aCreatedBy;
}
/**
*ReturnsthecreatedByattribute.
*
*@returnThecreatedByvalue.
*/
publicStringgetCreatedBy(){
return_createdBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/*(non-Javadoc)
*@seejava.lang.Object#toString()
*/
publicStringtoString(){
returnnewToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE).
append("id",_id).
append("ownerName",_ownerName).
append("isActive",_isActive).
append("balance",_balance).
append("tx.count",_transactions.size()).
append("createdBy",_createdBy).
append("creationDate",newTimestamp(_creationDate.getTime())).
toString();
}
}
AccountNotFoundException,账号不存在异常
packageorg.apache.shiro.samples.aspectj.bank;
publicclassAccountNotFoundExceptionextendsBankServiceException{
publicAccountNotFoundException(StringaMessage){
super(aMessage);
}
}
AccountTransaction,账号转入与转出
packageorg.apache.shiro.samples.aspectj.bank;
importorg.apache.commons.lang.builder.ToStringBuilder;
importorg.apache.commons.lang.builder.ToStringStyle;
importjava.sql.Timestamp;
importjava.util.Date;
publicclassAccountTransaction{
privatestaticlong_SEQUENCE;
publicenumTransactionType{
DEPOSIT,
WITHDRAWAL
}
privatelong_id;
privateTransactionType_type;
privatelong_accountId;
privatedouble_amount;
privateString_createdBy;
privateDate_creationDate;
publicstaticAccountTransactioncreateDepositTx(longanAccountId,doubleanAmount){
returnnewAccountTransaction(TransactionType.DEPOSIT,anAccountId,anAmount);
}
publicstaticAccountTransactioncreateWithdrawalTx(longanAccountId,doubleanAmount){
returnnewAccountTransaction(TransactionType.WITHDRAWAL,anAccountId,anAmount);
}
privateAccountTransaction(TransactionTypeaType,longanAccountId,doubleanAmount){
_id=++_SEQUENCE;
_type=aType;
_accountId=anAccountId;
_amount=anAmount;
_createdBy="unknown";
_creationDate=newDate();
}
/**
*Returnstheidattribute.
*
*@returnTheidvalue.
*/
publiclonggetId(){
return_id;
}
/**
*Returnsthetypeattribute.
*
*@returnThetypevalue.
*/
publicTransactionTypegetType(){
return_type;
}
/**
*ReturnstheaccountIdattribute.
*
*@returnTheaccountIdvalue.
*/
publiclonggetAccountId(){
return_accountId;
}
/**
*Returnstheamountattribute.
*
*@returnTheamountvalue.
*/
publicdoublegetAmount(){
return_amount;
}
/**
*ChangesthevalueoftheattributescreatedBy.
*
*@paramaCreatedByThenewvalueofthecreatedByattribute.
*/
protectedvoidsetCreatedBy(StringaCreatedBy){
_createdBy=aCreatedBy;
}
/**
*ReturnsthecreatedByattribute.
*
*@returnThecreatedByvalue.
*/
publicStringgetCreatedBy(){
return_createdBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/*(non-Javadoc)
*@seejava.lang.Object#toString()
*/
publicStringtoString(){
returnnewToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE).
append("id",_id).
append("type",_type).
append("accountId",_accountId).
append("amount",_amount).
append("createdBy",_createdBy).
append("creationDate",newTimestamp(_creationDate.getTime())).
toString();
}
}
BankServerRunner,银行服务运行
packageorg.apache.shiro.samples.aspectj.bank;
publicclassBankServerRunner{
privateSecureBankService_bankService;
publicsynchronizedvoidstart()throwsException{
if(_bankService==null){
_bankService=newSecureBankService();
_bankService.start();
}
}
publicsynchronizedvoidstop(){
if(_bankService!=null){
try{
_bankService.dispose();
}finally{
_bankService=null;
}
}
}
publicBankServicegetBankService(){
return_bankService;
}
publicstaticvoidmain(String[]args){
try{
BankServerRunnerserver=newBankServerRunner();
server.start();
server.stop();
}catch(Exceptione){
e.printStackTrace();
}
}
}
BankService,银行服务接口
packageorg.apache.shiro.samples.aspectj.bank;
importjava.util.Date;
publicinterfaceBankService{
publiclong[]searchAccountIdsByOwner(StringanOwnerName);
publiclongcreateNewAccount(StringanOwnerName);
publicdoublegetBalanceOf(longanAccountId)throwsAccountNotFoundException;
publicStringgetOwnerOf(longanAccountId)throwsAccountNotFoundException;
publicdoubledepositInto(longanAccountId,doubleanAmount)throwsAccountNotFoundException,InactiveAccountException;
publicdoublewithdrawFrom(longanAccountId,doubleanAmount)throwsAccountNotFoundException,NotEnoughFundsException,InactiveAccountException;
publicTxLog[]getTxHistoryFor(longanAccountId)throwsAccountNotFoundException;
publicdoublecloseAccount(longanAccountId)throwsAccountNotFoundException,InactiveAccountException;
publicbooleanisAccountActive(longanAccountId)throwsAccountNotFoundException;
publicstaticclassTxLog{
privateDate_creationDate;
privatedouble_amount;
privateString_madeBy;
publicTxLog(DateaCreationDate,doubleaAmount,StringaMadeBy){
super();
_creationDate=aCreationDate;
_amount=aAmount;
_madeBy=aMadeBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/**
*Returnstheamountattribute.
*
*@returnTheamountvalue.
*/
publicdoublegetAmount(){
return_amount;
}
/**
*ReturnsthemadeByattribute.
*
*@returnThemadeByvalue.
*/
publicStringgetMadeBy(){
return_madeBy;
}
}
}
BankServiceException,银行服务异常
packageorg.apache.shiro.samples.aspectj.bank;
publicclassBankServiceExceptionextendsException{
publicBankServiceException(StringaMessage){
super(aMessage);
}
publicBankServiceException(StringaMessage,ThrowableaCause){
super(aMessage,aCause);
}
}
InactiveAccountException,存入账户异常
packageorg.apache.shiro.samples.aspectj.bank;
publicclassInactiveAccountExceptionextendsBankServiceException{
publicInactiveAccountException(StringaMessage){
super(aMessage);
}
}
NotEnoughFundsException,账户不足异常
packageorg.apache.shiro.samples.aspectj.bank;
publicclassNotEnoughFundsExceptionextendsBankServiceException{
publicNotEnoughFundsException(StringaMessage){
super(aMessage);
}
}
SecureBankService,安全银行的服务类,处理各种银行的业务
packageorg.apache.shiro.samples.aspectj.bank;
importorg.apache.shiro.SecurityUtils;
importorg.apache.shiro.authz.annotation.RequiresPermissions;
importorg.apache.shiro.samples.aspectj.bank.AccountTransaction.TransactionType;
importorg.apache.shiro.subject.Subject;
importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclassSecureBankServiceimplementsBankService{
privatestaticfinalLoggerlog=LoggerFactory.getLogger(SecureBankService.class);
privatevolatileboolean_isRunning;
privatefinalList<Account>_accounts;
privateMap<Long,Account>_accountsById;
/**
*Createsanew{@linkSecureBankService}instance.
*/
publicSecureBankService(){
_accounts=newArrayList<Account>();
_accountsById=newHashMap<Long,Account>();
}
/**
*Startsthisservice
*/
publicvoidstart()throwsException{
_isRunning=true;
log.info("银行服务开始...");
}
/**
*Stopthisservice
*/
publicvoiddispose(){
log.info("银行服务停止...");
_isRunning=false;
synchronized(_accounts){
_accountsById.clear();
_accounts.clear();
}
log.info("银行服务停止!");
}
/**
*Internalutilitymethodthatvalidatetheinternalstateofthisservice.
*/
protectedvoidassertServiceState(){
if(!_isRunning){
thrownewIllegalStateException("银行的服务没有开始");
}
}
publicintgetAccountCount(){
return_accounts.size();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#createNewAccount(java.lang.String)
*/
@RequiresPermissions("bankAccount:create")
publiclongcreateNewAccount(StringanOwnerName){
assertServiceState();
log.info("创建新的账户给"+anOwnerName);
synchronized(_accounts){
Accountaccount=newAccount(anOwnerName);
account.setCreatedBy(getCurrentUsername());
_accounts.add(account);
_accountsById.put(account.getId(),account);
log.debug("创建新的账户:"+account);
returnaccount.getId();
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#searchAccountIdsByOwner(java.lang.String)
*/
publiclong[]searchAccountIdsByOwner(StringanOwnerName){
assertServiceState();
log.info("查找已经存在的银行账户为"+anOwnerName);
ArrayList<Account>matchAccounts=newArrayList<Account>();
synchronized(_accounts){
for(Accounta:_accounts){
if(a.getOwnerName().toLowerCase().contains(anOwnerName.toLowerCase())){
matchAccounts.add(a);
}
}
}
long[]accountIds=newlong[matchAccounts.size()];
intindex=0;
for(Accounta:matchAccounts){
accountIds[index++]=a.getId();
}
log.debug("找到"+accountIds.length+"相匹配的账户的名称"+anOwnerName);
returnaccountIds;
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getOwnerOf(long)
*/
@RequiresPermissions("bankAccount:read")
publicStringgetOwnerOf(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获得银行账户的所有者"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.getOwnerName();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getBalanceOf(long)
*/
@RequiresPermissions("bankAccount:read")
publicdoublegetBalanceOf(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("得到账户的余额"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.getBalance();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#depositInto(long,double)
*/
@RequiresPermissions("bankAccount:operate")
publicdoubledepositInto(longanAccountId,doubleanAmount)throwsAccountNotFoundException,InactiveAccountException{
assertServiceState();
log.info("存钱到"+anAmount+"这个账户"+anAccountId);
try{
Accounta=safellyRetrieveAccountForId(anAccountId);
AccountTransactiontx=AccountTransaction.createDepositTx(anAccountId,anAmount);
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
log.debug("新的账户余额"+a.getId()+"存款后"+a.getBalance());
returna.getBalance();
}catch(NotEnoughFundsExceptionnefe){
thrownewIllegalStateException("应该从未发生过",nefe);
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#withdrawFrom(long,double)
*/
@RequiresPermissions("bankAccount:operate")
publicdoublewithdrawFrom(longanAccountId,doubleanAmount)throwsAccountNotFoundException,NotEnoughFundsException,InactiveAccountException{
assertServiceState();
log.info("取款"+anAmount+"从账户"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
AccountTransactiontx=AccountTransaction.createWithdrawalTx(anAccountId,anAmount);
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
log.debug("新的账户余额"+a.getId()+"取款后"+a.getBalance());
returna.getBalance();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getTxHistoryFor(long)
*/
@RequiresPermissions("bankAccount:read")
publicTxLog[]getTxHistoryFor(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获取账户交易"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
TxLog[]txs=newTxLog[a.getTransactions().size()];
intindex=0;
for(AccountTransactiontx:a.getTransactions()){
log.debug("查过交易"+tx);
if(TransactionType.DEPOSIT==tx.getType()){
txs[index++]=newTxLog(tx.getCreationDate(),tx.getAmount(),tx.getCreatedBy());
}else{
txs[index++]=newTxLog(tx.getCreationDate(),-1.0d*tx.getAmount(),tx.getCreatedBy());
}
}
returntxs;
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#closeAccount(long)
*/
@RequiresPermissions("bankAccount:close")
publicdoublecloseAccount(longanAccountId)throwsAccountNotFoundException,InactiveAccountException{
assertServiceState();
log.info("截止账户"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
if(!a.isActive()){
thrownewInactiveAccountException("这个账户"+anAccountId+"已经关闭");
}
try{
AccountTransactiontx=AccountTransaction.createWithdrawalTx(a.getId(),a.getBalance());
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
a.setActive(false);
log.debug("账户"+a.getId()+"现在是关闭的"+tx.getAmount()+"针对这个业主");
returntx.getAmount();
}catch(NotEnoughFundsExceptionnefe){
thrownewIllegalStateException("应该从来不发生",nefe);
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#isAccountActive(long)
*/
@RequiresPermissions("bankAccount:read")
publicbooleanisAccountActive(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获取账户的活动状态"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.isActive();
}
/**
*Internalmethodthatsafelly(concurrency-wise)retrievesanaccountfromtheidpassedin.
*
*@paramanAccountIdTheidentifieroftheaccounttoretrieve.
*@returnTheaccountinstanceretrieved.
*@throwsAccountNotFoundExceptionIfnoaccountisfoundfortheprovidedidentifier.
*/
protectedAccountsafellyRetrieveAccountForId(longanAccountId)throwsAccountNotFoundException{
Accountaccount=null;
synchronized(_accounts){
account=_accountsById.get(anAccountId);
}
if(account==null){
thrownewAccountNotFoundException("没有找到ID为"+anAccountId+"的账户");
}
log.info("检查账户"+account);
returnaccount;
}
/**
*Internalutilitymethodtoretrievetheusernameofthecurrentauthenticateduser.
*
*@returnThename.
*/
protectedStringgetCurrentUsername(){
Subjectsubject=SecurityUtils.getSubject();
if(subject==null||subject.getPrincipal()==null||!subject.isAuthenticated()){
thrownewIllegalStateException("无法检索当前验证的主题");
}
returnSecurityUtils.getSubject().getPrincipal().toString();
}
}
在配置文件中配置了三组账户
[users]
root=secret,admin
sally=1234,superviser
dan=123,user
用户root密码secret角色admin
用户sally密码1234角色superviser
用户dan密码123角色user
角色信息包括
[roles]
admin=bankAccount:*
superviser=bankAccount:create,bankAccount:readbankAccount:close
user=bankAccount:create,bankAccount:read,bankAccount:operate
包括种种操作的权限分配
使用junit测试
@BeforeClass
publicstaticvoidsetUpClass()throwsException{
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
logger=Logger.getLogger(SecureBankServiceTest.class.getSimpleName());
Factory<SecurityManager>factory=newIniSecurityManagerFactory(
"classpath:shiroBankServiceTest.ini");
SecurityManagersecurityManager=factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
service=newSecureBankService();
service.start();
}
加载对应的ini中的信息,在每次运行之前
登录用户的操作方法
//作为用户登录,不能关闭账户
protectedvoidloginAsUser(){
if(_subject==null){
_subject=SecurityUtils.getSubject();
}
//usedantorunasanormaluser(whichcannotcloseanaccount)
_subject.login(newUsernamePasswordToken("dan","123"));
}
//作为超级用户登录,不能操作账户
protectedvoidloginAsSuperviser(){
if(_subject==null){
_subject=SecurityUtils.getSubject();
}
//usesallytorunasasuperviser(whichcannotoperateanaccount)
_subject.login(newUsernamePasswordToken("sally","1234"));
}
给张三创建账户,并且检查账户的情况
@Test
publicvoidtestCreateAccount()throwsException{
loginAsUser();
createAndValidateAccountFor("张三");
}
protectedlongcreateAndValidateAccountFor(StringanOwner)throwsException{
longcreatedId=service.createNewAccount(anOwner);
assertAccount(anOwner,true,0.0d,0,createdId);
returncreatedId;
}
publicstaticvoidassertAccount(StringeOwnerName,booleaneIsActive,
doubleeBalance,inteTxLogCount,longactualAccountId)
throwsException{
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]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
62[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
120[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
120[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
121[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
121[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
121[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
122[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
123[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
132[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给张三
203[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
206[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
206[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[66208001-e91d-4625-938f-1b1c08b2645c]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建张三的用户信息并且检查张三的账户的情况。
第二个测试
创建账户李四并且存入250到账户里,用户有创建和操作的权限,所以可以操作
@Test
publicvoidtestDepositInto_singleTx()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("李四");
makeDepositAndValidateAccount(accountId,250.00d,"李四");
}
protecteddoublemakeDepositAndValidateAccount(longanAccountId,
doubleanAmount,StringeOwnerName)throwsException{
doublepreviousBalance=service.getBalanceOf(anAccountId);
intpreviousTxCount=service.getTxHistoryFor(anAccountId).length;
doublenewBalance=service.depositInto(anAccountId,anAmount);
Assert.assertEquals(previousBalance+anAmount,newBalance);
assertAccount(eOwnerName,true,newBalance,1+previousTxCount,
anAccountId);
returnnewBalance;
}
运行后的结果
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
56[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
59[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
115[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
117[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
124[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
171[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给李四
188[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到250.0这个账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-1220:44:15.013]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后250.0
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-1220:44:15.013]
196[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
197[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[3b53dc16-67d5-4730-ae8a-872d113c7546]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建账户王五并且存入多笔款项
@Test
publicvoidtestDepositInto_multiTxs()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("王五");
makeDepositAndValidateAccount(accountId,50.00d,"王五");
makeDepositAndValidateAccount(accountId,300.00d,"王五");
makeDepositAndValidateAccount(accountId,85.00d,"王五");
assertAccount("王五",true,435.00d,3,accountId);
}
一共存入三笔,最后得到的数据的总和为435
看日志打出来的信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
49[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
62[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
119[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
120[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
121[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
129[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给王五
204[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
204[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
204[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到50.0这个账户1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后50.0
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到300.0这个账户1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后350.0
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到85.0这个账户1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后435.0
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
214[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
214[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[1d66c2ec-a668-478a-8f30-e3c65f80a16d]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建账户贾六并且取款,因为账户为空所以会抛出异常
@Test(expected=NotEnoughFundsException.class)
publicvoidtestWithdrawFrom_emptyAccount()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("贾六");
service.withdrawFrom(accountId,100.00d);
}
看执行的结果
1[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
13[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
15[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
50[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
60[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
63[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
126[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
126[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
128[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
128[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
129[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
130[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
132[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
145[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给贾六
205[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1220:56:05.047]
210[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
210[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[05f3559d-d0c4-458c-a220-31389550576f]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
得到期望的NotEnoughFundsException,运行通过
然后创建账户周七,先存入50,然后取100,结果得到的与面相同,余额不足异常
@Test(expected=NotEnoughFundsException.class)
publicvoidtestWithdrawFrom_notEnoughFunds()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("周七");
makeDepositAndValidateAccount(accountId,50.00d,"周七");
service.withdrawFrom(accountId,100.00d);
}
看打印出的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
61[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
119[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
120[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
121[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
131[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
179[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给周七
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到50.0这个账户1
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
200[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1221:01:30.955]
200[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后50.0
200[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1221:01:30.955]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:01:30.956]
202[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
202[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[a85a89c7-a805-4086-bd5b-109a0d54086c]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
再测试先存后取,先存入500,后取100,最后得到的结果为400
@Test
publicvoidtestWithdrawFrom_singleTx()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("国八");
makeDepositAndValidateAccount(accountId,500.00d,"国八");
makeWithdrawalAndValidateAccount(accountId,100.00d,"国八");
assertAccount("国八",true,400.00d,2,accountId);
}
看打印出的结果
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
11[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
43[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
45[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
55[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
59[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
116[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
117[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
124[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
168[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给国八
185[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后400.0
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
193[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
193[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[192dddd6-7090-435c-bb65-b3b64a73d667]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
存入一笔取多笔
@Test
publicvoidtestWithdrawFrom_manyTxs()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ZoeSmith");
makeDepositAndValidateAccount(accountId,500.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,100.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,75.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,125.00d,"ZoeSmith");
assertAccount("ZoeSmith",true,200.00d,4,accountId);
}
查看打印的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
53[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
57[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
72[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
76[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
132[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
132[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
133[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
133[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
133[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
134[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
135[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
143[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ZoeSmith
205[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后400.0
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款75.0从账户1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后325.0
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款125.0从账户1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后200.0
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
220[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
220[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
221[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
221[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
221[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[1ecbe8f2-f2f5-468b-af2b-d82d6b1267fa]
223[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
223[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
存多少取多少
@Test
publicvoidtestWithdrawFrom_upToZero()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ZoeSmith");
makeDepositAndValidateAccount(accountId,500.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,500.00d,"ZoeSmith");
assertAccount("ZoeSmith",true,0.00d,2,accountId);
}
查看打印的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
12[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
43[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
45[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
55[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
58[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
114[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
114[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
114[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
115[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
116[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
125[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
168[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ZoeSmith
186[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款500.0从账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后0.0
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
194[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
194[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
195[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[12aeb47c-f3c1-46c1-baec-78da03762422]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
关闭账户余额为0的账户,普通用户没有权限,所以需要转到另外一个角色的账户进行操作
@Test
publicvoidtestCloseAccount_zeroBalance()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ChrisSmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(0.00d,closingBalance);
assertAccount("ChrisSmith",false,0.00d,1,accountId);
}
查看打印出来的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
13[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
14[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
47[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
50[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
61[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
63[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
121[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
121[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
121[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
122[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
122[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
123[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
124[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
133[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ChrisSmith
207[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
210[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
210[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[c4adc0a6-987c-4c94-ad38-d13f683c7f1d]
211[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
211[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
211[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
211[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
211[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
211[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:13:04.516]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的0.0针对这个业主
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:13:04.516]
214[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
214[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[f0988257-3441-489a-859c-538043ead6e3]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建用户并且存入350,然后对这个用户进行关闭操作
@Test
publicvoidtestCloseAccount_withBalance()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("GerrySmith");
makeDepositAndValidateAccount(accountId,385.00d,"GerrySmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(385.00d,closingBalance);
assertAccount("GerrySmith",false,0.00d,2,accountId);
}
查看打印的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
12[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
58[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
61[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
118[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
119[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
128[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
173[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给GerrySmith
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到385.0这个账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后385.0
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
196[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
196[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[b2e689a3-cd4a-4785-962b-0df77758533b]
197[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
197[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
197[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
197[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
197[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
197[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-1221:17:58.674]
197[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的385.0针对这个业主
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
198[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
198[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-1221:17:58.674]
198[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
198[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[6ffa0d67-7510-4205-9fa8-01b6bb9793f5]
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建用户并且关闭正活动的账户
@Test(expected=InactiveAccountException.class)
publicvoidtestCloseAccount_alreadyClosed()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ChrisSmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(0.00d,closingBalance);
assertAccount("ChrisSmith",false,0.00d,1,accountId);
service.closeAccount(accountId);
}
查看打印的日志信息
0[main]DEBUGorg.apache.shiro.io.ResourceUtils-Openingresourcefromclasspath[shiroBankServiceTest.ini]
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
47[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
57[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
60[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
117[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
120[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
127[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
178[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ChrisSmith
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
198[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
198[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[8ff8f7c8-5d03-4e4f-b47d-0414cd43111d]
198[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
198[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
199[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
199[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
199[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
199[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:19:53.777]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的0.0针对这个业主
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:19:53.777]
202[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
202[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
202[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
202[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[53286615-5b71-4642-b3e8-916fb77fba60]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
其中判断权限使用的是annocation的方式
@RequiresPermissions("bankAccount:create")是否有用户创建权限
@RequiresPermissions("bankAccount:read")读权限
@RequiresPermissions("bankAccount:operate")操作权限
@RequiresPermissions("bankAccount:close")关闭权限
根据以上几个标签就可以得到对应的权限信息
Shiro是一个强大而灵活的开源安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密。如下是它所具有的特点:
易于理解的JavaSecurityAPI;
简单的身份认证(登录),支持多种数据源(LDAP,JDBC,Kerberos,ActiveDirectory等);
对角色的简单的签权(访问控制),支持细粒度的签权;
支持一级缓存,以提升应用程序的性能;
内置的基于POJO企业会话管理,适用于Web以及非Web的环境;
异构客户端会话访问;
非常简单的加密API;
不跟任何的框架或者容器捆绑,可以独立运行。
Shiro主要有四个组件
SecurityManager典型的Facade,Shiro通过它对外提供安全管理的各种服务。Authenticator对“Whoareyou?”进行核实。通常涉及用户名和密码。
这个组件负责收集principals和credentials,并将它们提交给应用系统。如果提交的credentials跟应用系统中提供的credentials吻合,就能够继续访问,否则需要重新提交principals和credentials,或者直接终止访问。
Authorizer身份份验证通过后,由这个组件对登录人员进行访问控制的筛查,比如“whocandowhat”,或者“whocandowhichactions”。Shiro采用“基于Realm”的方法,即用户(又称Subject)、用户组、角色和permission的聚合体。
SessionManager这个组件保证了异构客户端的访问,配置简单。它是基于POJO/J2SE的,不跟任何的客户端或者协议绑定。
Shiro的认证和签权可以通过JDBC、LDAP或者ActiveDirectory来访问数据库、目录服务器或者ActiveDirectory中的人员以及认证/签权信息。SessionManager通过会话DAO可以将会话保存在cache中,或者固化到数据库或文件系统中。
简介
apacheshiro是一个功能强大和易于使用的Java安全框架,为开发人员提供一个直观而全面的的解决方案的认证,授权,加密,会话管理。
在实际应用中,它实现了应用程序的安全管理的各个方面。
shiro的功能
apacheshiro能做什么?
支持认证跨一个或多个数据源(LDAP,JDBC,kerberos身份等)
执行授权,基于角色的细粒度的权限控制。
增强的缓存的支持。
支持web或者非web环境,可以在任何单点登录(SSO)或集群分布式会话中使用。
主要功能是:认证,授权,会话管理和加密。
下载并且使用
1,确保系统内安装JDK1.5+和maven2.2+。
2,到shiro主页下载shiro.
3,解压缩
4,进入到quickstart目录
5,运行quickstart
执行完成如下图:
Quickstart.java
使用SecurityUtils.getSubject(),我们可以得到当前正在执行的主题。
得到主题之后,你可以得到他对应的会话信息
你可以得到http的session信息,也可以在非web环境中使用,得到相对应的会话信息。
如果在web应用程序中部署应用,默认情况下,应用将以HttpSession为基础。在企业级应用中,你在多个应用中可以使用相同的API,无论部署环境。而且使用任何客户端技术你都可以共享会话数据。
接下来判断登录信息
如果正确可以向下执行,如果不正确,就会对不同的业务进行处理。
比如用户名不正确,密码不正确,用户被锁定的异常,当然也可以使用自定义抛出的异常。
如果登录成功,那么下一步可以做什么呢?
提示当前用户:
接着测试是否还有其它角色
接着测试是否有特定的权限
接着验证一个非常强大的实例级权限
最后是使用程序注销:
认证就是用户确认身份的过程,确认登录的用户身份能够操作的内容。
使用shiro认证分为以下几个步骤:
1,得到主体的认证和凭据。
isRemembered
isAuthenticated
//doonething(showtheprintbutton?)
}else{
//don’tshowthebutton?
}
也可以使用字符串的方式验证
应用程序调用subject(主题),主题可以是一个用户也可以是与系统交互的另一个系统,主题绑定shiro的权限管理,SecurityManager(安全管理),它控制与有与主题相关的安全操作。Realm(桥梁)它是安全与数据之间的桥,它封装了比如DAO的配置信息,可以指定连接的数据源,也可使用其它的认证方式,如LDAP等。
然后看一下详细的架构图:
Subject(org.apache.shiro.subject.Subject)
主题:与系统交互的第三方如(用户,cron服务,第三方应用)等。
SecurityManager(org.apache.shiro.mgt.SecurityManager)
shiro系统的核心,协调主题使用的操作,验证,配置等。
Authenticator(org.apache.shiro.authc.Authenticator)
身份验证组件,对企图登录系统的用户进行身份的验证。其中包含一个AuthenticationStrategy
(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,编程方式配置
例如:
如果你想使用sessionManager配置自定义的sessionDao信息,进行自定义会话管理
1)创建一个INI从SecurityManager
可以从多种方式读取INI配置文件的信息,如文件系统,类路径等
类似于Properties的方式
4,INI配置
每一个节点都是单独的,不可以重复,注释可以使用#或者;
配置示例
配置sessionManager的实例和它的依赖。
配置示例
你可以使用$符号引用先前定义的一个对象的实例
在用户比较少的情况下这种配置信息是有效的
如果角色信息比较少的情况下可以使用这项配置
配置url等可访问的资源信息。
shiro(3)-shiro核心
身份认证身份认证分三个步骤
1)提交主题和凭据
2)进行身份认证
3)判断是通过,重新提交还是不通过
验证顺序
1)调用subject的login方法,提交主体和凭据。
2)得到对应操作的SecurityManager
3)通过SceurityManager得到对应的Autherticator实例
4)根据配置策略查找对应的桥信息
5)通过桥信息到对应的配置处理进行身份验证
验证器
如果你想配置一个自定义的验证器
可以在配置文件中使用
...
authenticator=com.foo.bar.CustomAuthenticator
securityManager.authenticator=$authenticator
配置策略信息
对应的在配置文件中的策略使用如下
[main]
...
authcStrategy=org.apache.shiro.authc.pam.FirstSuccessfulStrategy
securityManager.authenticator.authenticationStrategy=$authcStrategy
...
执行顺序
1)隐式顺序
...
fooRealm=com.company.foo.Realm
...
barRealm=com.company.another.Realm
按上下顺序执行
2)指定顺序
...
fooRealm=com.company.foo.Realm
...
barRealm=com.company.another.Realm
securityManager.realms=$fooRealm,$barRealm,$blahRealm
...
按指定的顺序执行
授权
控制谁有权限访问应用程序
授权的几个要素:权限,角色和用户。
三种权限的判断方式
1)编程
角色判断
if(currentUser.hasRole("administrator")){
//showtheadminbutton
}else{
//don'tshowthebutton?Greyitout?
}
角色断言
//guaranteethatthecurrentuserisabanktellerand
//thereforeallowedtoopentheaccount:
currentUser.checkRole("bankTeller");
openBankAccount();
如果判断指定用户是否有权限访问指定名称的打印机
那么就会用到下列几个方法
SubjectcurrentUser=SecurityUtils.getSubject();
if(currentUser.isPermitted(printPermission)){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
基于字符串的权限检查
if(currentUser.isPermitted("printer:print:laserjet4400n")){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
也可以如下使用
Permissionp=newWildcardPermission("printer:print:laserjet4400n");
if(currentUser.isPermitted(p){
//showthePrintbutton
}else{
//don'tshowthebutton?Greyitout?
}
权限断言类似于角色断言。
2)annocation方式
TheRequiresAuthenticationannotation
publicvoidupdateAccount(AccountuserAccount){
//thismethodwillonlybeinvokedbya
//Subjectthatisguaranteedauthenticated
...
}
等同于下述代码
if(!SecurityUtils.getSubject().isAuthenticated()){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedauthenticatedhere
...
}
TheRequiresGuestannotation
publicvoidsignUp(UsernewUser){
//thismethodwillonlybeinvokedbya
//Subjectthatisunknown/anonymous
...
}
等同于
SubjectcurrentUser=SecurityUtils.getSubject();
PrincipalCollectionprincipals=currentUser.getPrincipals();
if(principals!=null&&!principals.isEmpty()){
//knownidentity-notaguest:
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobea'guest'here
...
}
TheRequiresPermissionsannotation
publicvoidcreateAccount(Accountaccount){
//thismethodwillonlybeinvokedbyaSubject
//thatispermittedtocreateanaccount
...
}
等同于
SubjectcurrentUser=SecurityUtils.getSubject();
if(!subject.isPermitted("account:create")){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobepermittedhere
...
}
TheRequiresRolespermission
publicvoiddeleteUser(Useruser){
//thismethodwillonlybeinvokedbyanadministrator
...
}
等同于
SubjectcurrentUser=SecurityUtils.getSubject();
if(!subject.hasRole("administrator")){
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtobean'administrator'here
...
}
TheRequiresUserannotation
publicvoidupdateAccount(Accountaccount){
//thismethodwillonlybeinvokedbya'user'
//i.e.aSubjectwithaknownidentity
...
}
等同于
SubjectcurrentUser=SecurityUtils.getSubject();
PrincipalCollectionprincipals=currentUser.getPrincipals();
if(principals==null||principals.isEmpty()){
//noidentity-they'reanonymous,notallowed:
thrownewAuthorizationException(...);
}
//Subjectisguaranteedtohaveaknownidentityhere
...
}
授权顺序
1)应用程序调用主题,判断hasRole,isPermitted得到角色或者用户权限的列表。
2)组成对应的授权方法
3)协调如何授权
4)通过桥进行各种方式的授权
web应用
配置web.xml
如果你愿意你可以自定义一个web应用
如果你想改变shiro.ini的位置,那么你可以指定
shiro.ini中的[urls]配置
例如:
[urls]
/index.html=anon
/user/create=anon
/user/**=authc
/admin/**=authc,roles[administrator]
/rest/**=authc,rest
/remoting/rpc/**=authc,perms["remote:invoke"]
假如你有如下设置
/account下的任何应用程序都将触动ssl和authc链
在官方的示例中,有一个aspectj的示例,这个是一个银行的示例,简单的做了一下修改,演示一下其中几个方法的使用过程。
看以下几个类,包括账户信息,转账信息,以及一些异常处理程序,还包括一个业务操作类
Account账户信息类
importorg.apache.commons.lang.builder.ToStringStyle;
importjava.sql.Timestamp;
importjava.util.ArrayList;
importjava.util.Date;
importjava.util.List;
publicclassAccount{
privatestaticlong_SEQUENCE;
privatelong_id;
privateString_ownerName;
privatevolatileboolean_isActive;
privatedouble_balance;
privatefinalList<AccountTransaction>_transactions;
privateString_createdBy;
privateDate_creationDate;
publicAccount(StringanOwnerName){
_id=++_SEQUENCE;
_ownerName=anOwnerName;
_isActive=true;
_balance=0.0d;
_transactions=newArrayList<AccountTransaction>();
_createdBy="unknown";
_creationDate=newDate();
}
/**
*Returnstheidattribute.
*
*@returnTheidvalue.
*/
publiclonggetId(){
return_id;
}
/**
*ReturnstheownerNameattribute.
*
*@returnTheownerNamevalue.
*/
publicStringgetOwnerName(){
return_ownerName;
}
/**
*ReturnstheisActiveattribute.
*
*@returnTheisActivevalue.
*/
publicbooleanisActive(){
return_isActive;
}
/**
*ChangesthevalueoftheattributesisActive.
*
*@paramaIsActiveThenewvalueoftheisActiveattribute.
*/
publicvoidsetActive(booleanaIsActive){
_isActive=aIsActive;
}
/**
*ChangesthevalueoftheattributesownerName.
*
*@paramaOwnerNameThenewvalueoftheownerNameattribute.
*/
publicvoidsetOwnerName(StringaOwnerName){
_ownerName=aOwnerName;
}
/**
*Returnsthebalanceattribute.
*
*@returnThebalancevalue.
*/
publicdoublegetBalance(){
return_balance;
}
/**
*Returnsthetransactionsattribute.
*
*@returnThetransactionsvalue.
*/
publicList<AccountTransaction>getTransactions(){
return_transactions;
}
protectedvoidapplyTransaction(AccountTransactionaTransaction)throwsNotEnoughFundsException,InactiveAccountException{
if(!_isActive){
thrownewInactiveAccountException("Unabletoapply"+aTransaction.getType()+"ofamount"+aTransaction.getAmount()+"toaccount"+_id);
}
synchronized(_transactions){
if(AccountTransaction.TransactionType.DEPOSIT==aTransaction.getType()){
_transactions.add(aTransaction);
_balance+=aTransaction.getAmount();
}elseif(AccountTransaction.TransactionType.WITHDRAWAL==aTransaction.getType()){
if(_balance<aTransaction.getAmount()){
thrownewNotEnoughFundsException("Unabletowithdraw"+aTransaction.getAmount()+"$fromaccount"+_id+"-currentbalanceis"+_balance);
}
_transactions.add(aTransaction);
_balance-=aTransaction.getAmount();
}else{
thrownewIllegalArgumentException("Thetransactionpassedinhasaninvalidtype:"+aTransaction.getType());
}
}
}
/**
*ChangesthevalueoftheattributescreatedBy.
*
*@paramaCreatedByThenewvalueofthecreatedByattribute.
*/
protectedvoidsetCreatedBy(StringaCreatedBy){
_createdBy=aCreatedBy;
}
/**
*ReturnsthecreatedByattribute.
*
*@returnThecreatedByvalue.
*/
publicStringgetCreatedBy(){
return_createdBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/*(non-Javadoc)
*@seejava.lang.Object#toString()
*/
publicStringtoString(){
returnnewToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE).
append("id",_id).
append("ownerName",_ownerName).
append("isActive",_isActive).
append("balance",_balance).
append("tx.count",_transactions.size()).
append("createdBy",_createdBy).
append("creationDate",newTimestamp(_creationDate.getTime())).
toString();
}
}
AccountNotFoundException,账号不存在异常
publicclassAccountNotFoundExceptionextendsBankServiceException{
publicAccountNotFoundException(StringaMessage){
super(aMessage);
}
}
AccountTransaction,账号转入与转出
importorg.apache.commons.lang.builder.ToStringBuilder;
importorg.apache.commons.lang.builder.ToStringStyle;
importjava.sql.Timestamp;
importjava.util.Date;
publicclassAccountTransaction{
privatestaticlong_SEQUENCE;
publicenumTransactionType{
DEPOSIT,
WITHDRAWAL
}
privatelong_id;
privateTransactionType_type;
privatelong_accountId;
privatedouble_amount;
privateString_createdBy;
privateDate_creationDate;
publicstaticAccountTransactioncreateDepositTx(longanAccountId,doubleanAmount){
returnnewAccountTransaction(TransactionType.DEPOSIT,anAccountId,anAmount);
}
publicstaticAccountTransactioncreateWithdrawalTx(longanAccountId,doubleanAmount){
returnnewAccountTransaction(TransactionType.WITHDRAWAL,anAccountId,anAmount);
}
privateAccountTransaction(TransactionTypeaType,longanAccountId,doubleanAmount){
_id=++_SEQUENCE;
_type=aType;
_accountId=anAccountId;
_amount=anAmount;
_createdBy="unknown";
_creationDate=newDate();
}
/**
*Returnstheidattribute.
*
*@returnTheidvalue.
*/
publiclonggetId(){
return_id;
}
/**
*Returnsthetypeattribute.
*
*@returnThetypevalue.
*/
publicTransactionTypegetType(){
return_type;
}
/**
*ReturnstheaccountIdattribute.
*
*@returnTheaccountIdvalue.
*/
publiclonggetAccountId(){
return_accountId;
}
/**
*Returnstheamountattribute.
*
*@returnTheamountvalue.
*/
publicdoublegetAmount(){
return_amount;
}
/**
*ChangesthevalueoftheattributescreatedBy.
*
*@paramaCreatedByThenewvalueofthecreatedByattribute.
*/
protectedvoidsetCreatedBy(StringaCreatedBy){
_createdBy=aCreatedBy;
}
/**
*ReturnsthecreatedByattribute.
*
*@returnThecreatedByvalue.
*/
publicStringgetCreatedBy(){
return_createdBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/*(non-Javadoc)
*@seejava.lang.Object#toString()
*/
publicStringtoString(){
returnnewToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE).
append("id",_id).
append("type",_type).
append("accountId",_accountId).
append("amount",_amount).
append("createdBy",_createdBy).
append("creationDate",newTimestamp(_creationDate.getTime())).
toString();
}
}
BankServerRunner,银行服务运行
publicclassBankServerRunner{
privateSecureBankService_bankService;
publicsynchronizedvoidstart()throwsException{
if(_bankService==null){
_bankService=newSecureBankService();
_bankService.start();
}
}
publicsynchronizedvoidstop(){
if(_bankService!=null){
try{
_bankService.dispose();
}finally{
_bankService=null;
}
}
}
publicBankServicegetBankService(){
return_bankService;
}
publicstaticvoidmain(String[]args){
try{
BankServerRunnerserver=newBankServerRunner();
server.start();
server.stop();
}catch(Exceptione){
e.printStackTrace();
}
}
}
BankService,银行服务接口
importjava.util.Date;
publicinterfaceBankService{
publiclong[]searchAccountIdsByOwner(StringanOwnerName);
publiclongcreateNewAccount(StringanOwnerName);
publicdoublegetBalanceOf(longanAccountId)throwsAccountNotFoundException;
publicStringgetOwnerOf(longanAccountId)throwsAccountNotFoundException;
publicdoubledepositInto(longanAccountId,doubleanAmount)throwsAccountNotFoundException,InactiveAccountException;
publicdoublewithdrawFrom(longanAccountId,doubleanAmount)throwsAccountNotFoundException,NotEnoughFundsException,InactiveAccountException;
publicTxLog[]getTxHistoryFor(longanAccountId)throwsAccountNotFoundException;
publicdoublecloseAccount(longanAccountId)throwsAccountNotFoundException,InactiveAccountException;
publicbooleanisAccountActive(longanAccountId)throwsAccountNotFoundException;
publicstaticclassTxLog{
privateDate_creationDate;
privatedouble_amount;
privateString_madeBy;
publicTxLog(DateaCreationDate,doubleaAmount,StringaMadeBy){
super();
_creationDate=aCreationDate;
_amount=aAmount;
_madeBy=aMadeBy;
}
/**
*ReturnsthecreationDateattribute.
*
*@returnThecreationDatevalue.
*/
publicDategetCreationDate(){
return_creationDate;
}
/**
*Returnstheamountattribute.
*
*@returnTheamountvalue.
*/
publicdoublegetAmount(){
return_amount;
}
/**
*ReturnsthemadeByattribute.
*
*@returnThemadeByvalue.
*/
publicStringgetMadeBy(){
return_madeBy;
}
}
}
BankServiceException,银行服务异常
publicclassBankServiceExceptionextendsException{
publicBankServiceException(StringaMessage){
super(aMessage);
}
publicBankServiceException(StringaMessage,ThrowableaCause){
super(aMessage,aCause);
}
}
InactiveAccountException,存入账户异常
publicclassInactiveAccountExceptionextendsBankServiceException{
publicInactiveAccountException(StringaMessage){
super(aMessage);
}
}
NotEnoughFundsException,账户不足异常
publicclassNotEnoughFundsExceptionextendsBankServiceException{
publicNotEnoughFundsException(StringaMessage){
super(aMessage);
}
}
SecureBankService,安全银行的服务类,处理各种银行的业务
importorg.apache.shiro.SecurityUtils;
importorg.apache.shiro.authz.annotation.RequiresPermissions;
importorg.apache.shiro.samples.aspectj.bank.AccountTransaction.TransactionType;
importorg.apache.shiro.subject.Subject;
importorg.slf4j.Logger;
importorg.slf4j.LoggerFactory;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclassSecureBankServiceimplementsBankService{
privatestaticfinalLoggerlog=LoggerFactory.getLogger(SecureBankService.class);
privatevolatileboolean_isRunning;
privatefinalList<Account>_accounts;
privateMap<Long,Account>_accountsById;
/**
*Createsanew{@linkSecureBankService}instance.
*/
publicSecureBankService(){
_accounts=newArrayList<Account>();
_accountsById=newHashMap<Long,Account>();
}
/**
*Startsthisservice
*/
publicvoidstart()throwsException{
_isRunning=true;
log.info("银行服务开始...");
}
/**
*Stopthisservice
*/
publicvoiddispose(){
log.info("银行服务停止...");
_isRunning=false;
synchronized(_accounts){
_accountsById.clear();
_accounts.clear();
}
log.info("银行服务停止!");
}
/**
*Internalutilitymethodthatvalidatetheinternalstateofthisservice.
*/
protectedvoidassertServiceState(){
if(!_isRunning){
thrownewIllegalStateException("银行的服务没有开始");
}
}
publicintgetAccountCount(){
return_accounts.size();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#createNewAccount(java.lang.String)
*/
@RequiresPermissions("bankAccount:create")
publiclongcreateNewAccount(StringanOwnerName){
assertServiceState();
log.info("创建新的账户给"+anOwnerName);
synchronized(_accounts){
Accountaccount=newAccount(anOwnerName);
account.setCreatedBy(getCurrentUsername());
_accounts.add(account);
_accountsById.put(account.getId(),account);
log.debug("创建新的账户:"+account);
returnaccount.getId();
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#searchAccountIdsByOwner(java.lang.String)
*/
publiclong[]searchAccountIdsByOwner(StringanOwnerName){
assertServiceState();
log.info("查找已经存在的银行账户为"+anOwnerName);
ArrayList<Account>matchAccounts=newArrayList<Account>();
synchronized(_accounts){
for(Accounta:_accounts){
if(a.getOwnerName().toLowerCase().contains(anOwnerName.toLowerCase())){
matchAccounts.add(a);
}
}
}
long[]accountIds=newlong[matchAccounts.size()];
intindex=0;
for(Accounta:matchAccounts){
accountIds[index++]=a.getId();
}
log.debug("找到"+accountIds.length+"相匹配的账户的名称"+anOwnerName);
returnaccountIds;
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getOwnerOf(long)
*/
@RequiresPermissions("bankAccount:read")
publicStringgetOwnerOf(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获得银行账户的所有者"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.getOwnerName();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getBalanceOf(long)
*/
@RequiresPermissions("bankAccount:read")
publicdoublegetBalanceOf(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("得到账户的余额"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.getBalance();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#depositInto(long,double)
*/
@RequiresPermissions("bankAccount:operate")
publicdoubledepositInto(longanAccountId,doubleanAmount)throwsAccountNotFoundException,InactiveAccountException{
assertServiceState();
log.info("存钱到"+anAmount+"这个账户"+anAccountId);
try{
Accounta=safellyRetrieveAccountForId(anAccountId);
AccountTransactiontx=AccountTransaction.createDepositTx(anAccountId,anAmount);
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
log.debug("新的账户余额"+a.getId()+"存款后"+a.getBalance());
returna.getBalance();
}catch(NotEnoughFundsExceptionnefe){
thrownewIllegalStateException("应该从未发生过",nefe);
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#withdrawFrom(long,double)
*/
@RequiresPermissions("bankAccount:operate")
publicdoublewithdrawFrom(longanAccountId,doubleanAmount)throwsAccountNotFoundException,NotEnoughFundsException,InactiveAccountException{
assertServiceState();
log.info("取款"+anAmount+"从账户"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
AccountTransactiontx=AccountTransaction.createWithdrawalTx(anAccountId,anAmount);
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
log.debug("新的账户余额"+a.getId()+"取款后"+a.getBalance());
returna.getBalance();
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#getTxHistoryFor(long)
*/
@RequiresPermissions("bankAccount:read")
publicTxLog[]getTxHistoryFor(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获取账户交易"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
TxLog[]txs=newTxLog[a.getTransactions().size()];
intindex=0;
for(AccountTransactiontx:a.getTransactions()){
log.debug("查过交易"+tx);
if(TransactionType.DEPOSIT==tx.getType()){
txs[index++]=newTxLog(tx.getCreationDate(),tx.getAmount(),tx.getCreatedBy());
}else{
txs[index++]=newTxLog(tx.getCreationDate(),-1.0d*tx.getAmount(),tx.getCreatedBy());
}
}
returntxs;
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#closeAccount(long)
*/
@RequiresPermissions("bankAccount:close")
publicdoublecloseAccount(longanAccountId)throwsAccountNotFoundException,InactiveAccountException{
assertServiceState();
log.info("截止账户"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
if(!a.isActive()){
thrownewInactiveAccountException("这个账户"+anAccountId+"已经关闭");
}
try{
AccountTransactiontx=AccountTransaction.createWithdrawalTx(a.getId(),a.getBalance());
tx.setCreatedBy(getCurrentUsername());
log.debug("创建一个新的交易"+tx);
a.applyTransaction(tx);
a.setActive(false);
log.debug("账户"+a.getId()+"现在是关闭的"+tx.getAmount()+"针对这个业主");
returntx.getAmount();
}catch(NotEnoughFundsExceptionnefe){
thrownewIllegalStateException("应该从来不发生",nefe);
}
}
/*(non-Javadoc)
*@seecom.connectif.trilogy.root.security.BankService#isAccountActive(long)
*/
@RequiresPermissions("bankAccount:read")
publicbooleanisAccountActive(longanAccountId)throwsAccountNotFoundException{
assertServiceState();
log.info("获取账户的活动状态"+anAccountId);
Accounta=safellyRetrieveAccountForId(anAccountId);
returna.isActive();
}
/**
*Internalmethodthatsafelly(concurrency-wise)retrievesanaccountfromtheidpassedin.
*
*@paramanAccountIdTheidentifieroftheaccounttoretrieve.
*@returnTheaccountinstanceretrieved.
*@throwsAccountNotFoundExceptionIfnoaccountisfoundfortheprovidedidentifier.
*/
protectedAccountsafellyRetrieveAccountForId(longanAccountId)throwsAccountNotFoundException{
Accountaccount=null;
synchronized(_accounts){
account=_accountsById.get(anAccountId);
}
if(account==null){
thrownewAccountNotFoundException("没有找到ID为"+anAccountId+"的账户");
}
log.info("检查账户"+account);
returnaccount;
}
/**
*Internalutilitymethodtoretrievetheusernameofthecurrentauthenticateduser.
*
*@returnThename.
*/
protectedStringgetCurrentUsername(){
Subjectsubject=SecurityUtils.getSubject();
if(subject==null||subject.getPrincipal()==null||!subject.isAuthenticated()){
thrownewIllegalStateException("无法检索当前验证的主题");
}
returnSecurityUtils.getSubject().getPrincipal().toString();
}
}
在配置文件中配置了三组账户
root=secret,admin
sally=1234,superviser
dan=123,user
用户root密码secret角色admin
用户sally密码1234角色superviser
用户dan密码123角色user
角色信息包括
admin=bankAccount:*
superviser=bankAccount:create,bankAccount:readbankAccount:close
user=bankAccount:create,bankAccount:read,bankAccount:operate
包括种种操作的权限分配
使用junit测试
publicstaticvoidsetUpClass()throwsException{
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
logger=Logger.getLogger(SecureBankServiceTest.class.getSimpleName());
Factory<SecurityManager>factory=newIniSecurityManagerFactory(
"classpath:shiroBankServiceTest.ini");
SecurityManagersecurityManager=factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
service=newSecureBankService();
service.start();
}
加载对应的ini中的信息,在每次运行之前
登录用户的操作方法
protectedvoidloginAsUser(){
if(_subject==null){
_subject=SecurityUtils.getSubject();
}
//usedantorunasanormaluser(whichcannotcloseanaccount)
_subject.login(newUsernamePasswordToken("dan","123"));
}
//作为超级用户登录,不能操作账户
protectedvoidloginAsSuperviser(){
if(_subject==null){
_subject=SecurityUtils.getSubject();
}
//usesallytorunasasuperviser(whichcannotoperateanaccount)
_subject.login(newUsernamePasswordToken("sally","1234"));
}
给张三创建账户,并且检查账户的情况
publicvoidtestCreateAccount()throwsException{
loginAsUser();
createAndValidateAccountFor("张三");
}
protectedlongcreateAndValidateAccountFor(StringanOwner)throwsException{
longcreatedId=service.createNewAccount(anOwner);
assertAccount(anOwner,true,0.0d,0,createdId);
returncreatedId;
}
publicstaticvoidassertAccount(StringeOwnerName,booleaneIsActive,
doubleeBalance,inteTxLogCount,longactualAccountId)
throwsException{
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);
}
看打印出来的信息
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
62[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
120[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
120[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
121[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
121[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
121[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
122[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
123[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
132[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给张三
203[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=张三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:40:26.71]
206[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
206[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[66208001-e91d-4625-938f-1b1c08b2645c]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建张三的用户信息并且检查张三的账户的情况。
第二个测试
创建账户李四并且存入250到账户里,用户有创建和操作的权限,所以可以操作
publicvoidtestDepositInto_singleTx()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("李四");
makeDepositAndValidateAccount(accountId,250.00d,"李四");
}
doubleanAmount,StringeOwnerName)throwsException{
doublepreviousBalance=service.getBalanceOf(anAccountId);
intpreviousTxCount=service.getTxHistoryFor(anAccountId).length;
doublenewBalance=service.depositInto(anAccountId,anAmount);
Assert.assertEquals(previousBalance+anAmount,newBalance);
assertAccount(eOwnerName,true,newBalance,1+previousTxCount,
anAccountId);
returnnewBalance;
}
运行后的结果
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
56[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
59[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
115[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
117[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
124[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
171[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给李四
188[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到250.0这个账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-1220:44:15.013]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后250.0
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:44:14.991]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-1220:44:15.013]
196[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
197[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[3b53dc16-67d5-4730-ae8a-872d113c7546]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建账户王五并且存入多笔款项
publicvoidtestDepositInto_multiTxs()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("王五");
makeDepositAndValidateAccount(accountId,50.00d,"王五");
makeDepositAndValidateAccount(accountId,300.00d,"王五");
makeDepositAndValidateAccount(accountId,85.00d,"王五");
assertAccount("王五",true,435.00d,3,accountId);
}
一共存入三笔,最后得到的数据的总和为435
看日志打出来的信息
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
49[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
62[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
119[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
120[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
121[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
129[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给王五
204[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
204[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
204[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到50.0这个账户1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后50.0
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
210[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到300.0这个账户1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
211[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后350.0
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到85.0这个账户1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后435.0
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-1220:52:54.72]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1220:52:54.739]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-1220:52:54.741]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-1220:52:54.742]
214[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
214[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[1d66c2ec-a668-478a-8f30-e3c65f80a16d]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建账户贾六并且取款,因为账户为空所以会抛出异常
publicvoidtestWithdrawFrom_emptyAccount()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("贾六");
service.withdrawFrom(accountId,100.00d);
}
看执行的结果
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
13[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
15[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
50[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
60[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
63[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
126[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
126[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
128[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
128[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
129[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
130[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
132[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
145[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给贾六
205[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
206[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=贾六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1220:56:05.029]
210[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1220:56:05.047]
210[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
210[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[05f3559d-d0c4-458c-a220-31389550576f]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
得到期望的NotEnoughFundsException,运行通过
然后创建账户周七,先存入50,然后取100,结果得到的与面相同,余额不足异常
publicvoidtestWithdrawFrom_notEnoughFunds()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("周七");
makeDepositAndValidateAccount(accountId,50.00d,"周七");
service.withdrawFrom(accountId,100.00d);
}
看打印出的日志信息
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
59[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
61[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
118[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
119[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
120[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
121[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
131[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
179[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给周七
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到50.0这个账户1
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:01:30.936]
200[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1221:01:30.955]
200[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后50.0
200[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-1221:01:30.955]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:01:30.936]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:01:30.956]
202[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
202[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[a85a89c7-a805-4086-bd5b-109a0d54086c]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
再测试先存后取,先存入500,后取100,最后得到的结果为400
publicvoidtestWithdrawFrom_singleTx()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("国八");
makeDepositAndValidateAccount(accountId,500.00d,"国八");
makeWithdrawalAndValidateAccount(accountId,100.00d,"国八");
assertAccount("国八",true,400.00d,2,accountId);
}
看打印出的结果
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
10[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
11[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
43[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
45[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
55[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
59[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
115[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
116[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
116[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
117[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
124[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
168[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给国八
185[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:03:17.085]
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
191[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后400.0
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=国八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:03:17.085]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:03:17.103]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:03:17.104]
193[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
193[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[192dddd6-7090-435c-bb65-b3b64a73d667]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
存入一笔取多笔
publicvoidtestWithdrawFrom_manyTxs()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ZoeSmith");
makeDepositAndValidateAccount(accountId,500.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,100.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,75.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,125.00d,"ZoeSmith");
assertAccount("ZoeSmith",true,200.00d,4,accountId);
}
查看打印的日志信息
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
53[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
57[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
72[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
76[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
132[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
132[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
133[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
133[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
133[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
134[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
135[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
143[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ZoeSmith
205[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
205[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
212[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
212[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款100.0从账户1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后400.0
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款75.0从账户1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后325.0
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
215[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款125.0从账户1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后200.0
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
216[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
216[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
217[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
217[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
220[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
220[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
221[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-1221:04:28.312]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:04:28.337]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-1221:04:28.338]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-1221:04:28.339]
221[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-1221:04:28.341]
221[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
221[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[1ecbe8f2-f2f5-468b-af2b-d82d6b1267fa]
223[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
223[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
存多少取多少
publicvoidtestWithdrawFrom_upToZero()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ZoeSmith");
makeDepositAndValidateAccount(accountId,500.00d,"ZoeSmith");
makeWithdrawalAndValidateAccount(accountId,500.00d,"ZoeSmith");
assertAccount("ZoeSmith",true,0.00d,2,accountId);
}
查看打印的日志信息
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
12[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
43[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
45[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
55[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
58[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
114[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
114[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
114[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
115[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
115[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
116[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
125[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
168[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ZoeSmith
186[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
186[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
187[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
188[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
189[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到500.0这个账户1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后500.0
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-取款500.0从账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1取款后0.0
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
193[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
194[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ZoeSmith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:05:23.783]
194[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.804]
194[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-1221:05:23.806]
194[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
195[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[12aeb47c-f3c1-46c1-baec-78da03762422]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
关闭账户余额为0的账户,普通用户没有权限,所以需要转到另外一个角色的账户进行操作
publicvoidtestCloseAccount_zeroBalance()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ChrisSmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(0.00d,closingBalance);
assertAccount("ChrisSmith",false,0.00d,1,accountId);
}
查看打印出来的日志信息
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
13[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
14[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
47[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
50[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
61[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
63[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
121[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
121[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
121[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
122[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
122[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
123[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
124[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
133[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ChrisSmith
207[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
207[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
208[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
209[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
210[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
210[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[c4adc0a6-987c-4c94-ad38-d13f683c7f1d]
211[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
211[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
211[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
211[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
211[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
211[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
211[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:13:04.496]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:13:04.516]
213[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的0.0针对这个业主
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
213[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
214[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:13:04.496]
214[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:13:04.516]
214[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
214[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[f0988257-3441-489a-859c-538043ead6e3]
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
215[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建用户并且存入350,然后对这个用户进行关闭操作
publicvoidtestCloseAccount_withBalance()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("GerrySmith");
makeDepositAndValidateAccount(accountId,385.00d,"GerrySmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(385.00d,closingBalance);
assertAccount("GerrySmith",false,0.00d,2,accountId);
}
查看打印的日志信息
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
11[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
12[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
46[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
48[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
58[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
61[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
118[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
119[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
128[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
173[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给GerrySmith
190[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
190[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
191[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
192[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-存钱到385.0这个账户1
193[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-新的账户余额1存款后385.0
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
196[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
196[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
196[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[b2e689a3-cd4a-4785-962b-0df77758533b]
197[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
197[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
197[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
197[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
197[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
197[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-1221:17:58.674]
197[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的385.0针对这个业主
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
198[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=GerrySmith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-1221:17:58.652]
198[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-1221:17:58.672]
198[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-1221:17:58.674]
198[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
198[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[6ffa0d67-7510-4205-9fa8-01b6bb9793f5]
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
创建用户并且关闭正活动的账户
publicvoidtestCloseAccount_alreadyClosed()throwsException{
loginAsUser();
longaccountId=createAndValidateAccountFor("ChrisSmith");
logoutCurrentSubject();
loginAsSuperviser();
doubleclosingBalance=service.closeAccount(accountId);
Assert.assertEquals(0.00d,closingBalance);
assertAccount("ChrisSmith",false,0.00d,1,accountId);
service.closeAccount(accountId);
}
查看打印的日志信息
9[main]DEBUGorg.apache.shiro.config.Ini-Parsing[users]
12[main]DEBUGorg.apache.shiro.config.Ini-Parsing[roles]
13[main]DEBUGorg.apache.shiro.config.IniFactorySupport-CreatinginstancefromIni[sections=users,roles]
44[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[roles]section.Processing...
47[main]DEBUGorg.apache.shiro.realm.text.IniRealm-Discoveredthe[users]section.Processing...
57[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务开始...
60[main]INFOSecureBankServiceTest-
#########################
###开始测试用例1
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
117[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
117[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-dan,rememberMe=false].Returnedaccount[dan]
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
118[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
119[main]DEBUGorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-NosessionValidationSchedulerset.Attemptingtocreatedefaultinstance.
120[main]INFOorg.apache.shiro.session.mgt.AbstractValidatingSessionManager-Enablingsessionvalidationscheduler...
127[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
178[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户给ChrisSmith
195[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建新的账户:Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
195[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
196[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
197[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
198[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}dan
198[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[8ff8f7c8-5d03-4e4f-b47d-0414cd43111d]
198[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-PerformingcredentialsequalitycheckfortokenCredentialsoftype[[CandaccountCredentialsoftype[java.lang.String]
198[main]DEBUGorg.apache.shiro.authc.credential.SimpleCredentialsMatcher-Bothcredentialsargumentscanbeeasilyconvertedtobytearrays.Performingarrayequalscomparison
199[main]DEBUGorg.apache.shiro.authc.AbstractAuthenticator-Authenticationsuccessfulfortoken[org.apache.shiro.authc.UsernamePasswordToken-sally,rememberMe=false].Returnedaccount[sally]
199[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
199[main]DEBUGorg.apache.shiro.subject.support.DefaultSubjectContext-NoSecurityManageravailableinsubjectcontextmap.FallingbacktoSecurityUtils.getSecurityManager()lookup.
199[main]DEBUGorg.apache.shiro.session.mgt.DefaultSessionManager-CreatingnewEISrecordfornewsessioninstance[org.apache.shiro.session.mgt.SimpleSession,id=null]
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
199[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-创建一个新的交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:19:53.777]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-账户1现在是关闭的0.0针对这个业主
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获得银行账户的所有者1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户的活动状态1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-得到账户的余额1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-获取账户交易1
201[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
201[main]DEBUGorg.apache.shiro.samples.aspectj.bank.SecureBankService-查过交易AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-1221:19:53.777]
202[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-截止账户1
202[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-检查账户Account[id=1,ownerName=ChrisSmith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-1221:19:53.755]
202[main]DEBUGorg.apache.shiro.mgt.DefaultSecurityManager-Loggingoutsubjectwithprimaryprincipal{}sally
202[main]DEBUGorg.apache.shiro.session.mgt.AbstractSessionManager-Stoppingsessionwithid[53286615-5b71-4642-b3e8-916fb77fba60]
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止...
203[main]INFOorg.apache.shiro.samples.aspectj.bank.SecureBankService-银行服务停止!
其中判断权限使用的是annocation的方式
@RequiresPermissions("bankAccount:create")是否有用户创建权限
@RequiresPermissions("bankAccount:read")读权限
@RequiresPermissions("bankAccount:operate")操作权限
@RequiresPermissions("bankAccount:close")关闭权限
根据以上几个标签就可以得到对应的权限信息
相关文章推荐
- Shiro 权限框架使用总结
- Shiro 权限框架使用总结
- Shiro 权限框架使用总结
- Shiro 权限框架使用总结
- Shiro 权限框架使用总结
- 权限控制框架Spring Security 和Shiro 的总结
- [置顶] SpringMVC下的Shiro权限框架的使用
- 权限模块设计 - shiro框架的使用及扩展
- CBoard框架使用总结五--角色权限控制
- 权限控制框架Shiro总结
- SpringMVC下的Shiro权限框架的使用
- 使用Kotlin编写6.0权限检查框架学习总结
- 使用shiro实现权限控制学习总结
- Winform开发框架之权限管理系统改进的经验总结(1)-TreeListLookupEdit控件的使用
- 数据级的权限管理和功能级的权限管理的区别,不使用框架(shiro,springsecurity)做权限设计的思考
- 在前后端分离的项目中,后台使用shiro框架时,怎样使用它的会话管理系统(session),从而实现权限控制
- 使用shiro实现权限控制学习总结
- 权限验证框架Shiro使用详解
- 关于Apache Shiro权限框架的一些使用误区的解释
- 权限设计,以及使用优秀的权限框架shiro整合SpringMVC