咱們首先了解下什麼是shiro ,Shiro 是 JAVA 世界中新近出現的權限框架,較之 JAAS 和 Spring Security,Shiro 在保持強大功能的同時,還在簡單性和靈活性方面擁有巨大優點html
Shiro 是一個強大而靈活的開源安全框架,可以很是清晰的處理認證、受權、管理會話以及密碼加密。以下是它所具備的特色:java
典型的 Facade,Shiro 經過它對外提供安全管理的各類服務。web
對「Who are you ?」進行覈實。一般涉及用戶名和密碼。spring
這 個組件負責收集 principals 和 credentials,並將它們提交給應用系統。若是提交的 credentials 跟應用系統中提供的 credentials 吻合,就可以繼續訪問,不然須要從新提交 principals 和 credentials,或者直接終止訪問。sql
身 份份驗證經過後,由這個組件對登陸人員進行訪問控制的篩查,好比「who can do what」, 或者「who can do which actions」。Shiro 採用「基於 Realm」的方法,即用戶(又稱 Subject)、用戶組、角色和 permission 的聚合體。數據庫
這個組件保證了異構客戶端的訪問,配置簡單。它是基於 POJO/J2SE 的,不跟任何的客戶端或者協議綁定。apache
Shiro 的認證和籤權能夠經過 JDBC、LDAP 或者 Active Directory 來訪問數據庫、目錄服務器或者 Active Directory 中的人員以及認證 / 籤權信息。SessionManager 經過會話 DAO 能夠將會話保存在 cache 中,或者固化到數據庫或文件系統中。編程
簡介api
apache shiro 是一個功能強大和易於使用的Java安全框架,爲開發人員提供一個直觀而全面的的解決方案的認證,受權,加密,會話管理。緩存
在實際應用中,它實現了應用程序的安全管理的各個方面。
shiro的功能
apache shiro能作什麼?
支持認證跨一個或多個數據源(LDAP,JDBC,kerberos身份等)
執行受權,基於角色的細粒度的權限控制。
加強的緩存的支持。
支持web或者非web環境,能夠在任何單點登陸(SSO)或集羣分佈式會話中使用。
主要功能是:認證,受權,會話管理和加密。
下載而且使用
1,確保系統內安裝JDK1.5+和maven2.2+。
2,到shiro主頁下載shiro.
3,解壓縮
unzip shiro-root-1.1.0-source-release.zip
4,進入到quickstart目錄
cd shiro-root-1.1.0/samples/quickstart
5,運行quickstart
mvn compile exec:java
執行完成以下圖:
// get the currently executing user: Subject currentUser = SecurityUtils.getSubject();
使用SecurityUtils.getSubject(),咱們能夠獲得當前正在執行的主題。
獲得主題以後,你能夠獲得他對應的會話信息
// Do some stuff with a Session (no need for a web or EJB container!!!) Session session = currentUser.getSession(); session.setAttribute("someKey", "aValue"); String value = (String) session.getAttribute("someKey"); if (value.equals("aValue")) { log.info("Retrieved the correct value! [" + value + "]"); }
你能夠獲得http的session信息,也能夠在非web環境中使用,獲得相對應的會話信息。
若是在web應用程序中部署應用,默認狀況下,應用將以HttpSession爲基礎。在企業級應用中,你在多個應用中可使用相同的API,不管部署環境。並且使用任何客戶端技術你均可以共享會話數據。
接下來判斷登陸信息
// let's login the current user so we can check against roles and permissions: if (!currentUser.isAuthenticated()) { UsernamePasswordToken token = new UsernamePasswordToken("lonestarr", "vespa"); token.setRememberMe(true); try { currentUser.login(token); } catch (UnknownAccountException uae) { log.info("There is no user with username of " + token.getPrincipal()); } catch (IncorrectCredentialsException ice) { log.info("Password for account " + token.getPrincipal() + " was incorrect!"); } catch (LockedAccountException lae) { log.info("The account for username " + token.getPrincipal() + " is locked. " + "Please contact your administrator to unlock it."); } // ... catch more exceptions here (maybe custom ones specific to your application? catch (AuthenticationException ae) { //unexpected condition? error? } }
若是正確能夠向下執行,若是不正確,就會對不一樣的業務進行處理。
好比用戶名不正確,密碼不正確,用戶被鎖定的異常,固然也可使用自定義拋出的異常。
若是登陸成功,那麼下一步能夠作什麼呢?
提示當前用戶:
//say who they are: //print their identifying principal (in this case, a username): log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");
接着測試是否還有其它角色
//test a role: if (currentUser.hasRole("schwartz")) { log.info("May the Schwartz be with you!"); } else { log.info("Hello, mere mortal."); }
接着測試是否有特定的權限
//test a typed permission (not instance-level) if (currentUser.isPermitted("lightsaber:weild")) { log.info("You may use a lightsaber ring. Use it wisely."); } else { log.info("Sorry, lightsaber rings are for schwartz masters only."); }
接着驗證一個很是強大的實例級權限
//a (very powerful) Instance Level permission: if (currentUser.isPermitted("winnebago:drive:eagle5")) { log.info("You are permitted to 'drive' the winnebago with license plate (id) 'eagle5'. " + "Here are the keys - have fun!"); } else { log.info("Sorry, you aren't allowed to drive the 'eagle5' winnebago!"); }
最後是使用程序註銷:
//all done - log out! currentUser.logout();
認證就是用戶確認身份的過程,確認登陸的用戶身份可以操做的內容。
使用shiro認證分爲如下幾個步驟:
1,獲得主體的認證和憑據。
// let's login the current user so we can check against roles and permissions: |
if (!currentUser.isAuthenticated()) { |
UsernamePasswordToken token = new UsernamePasswordToken( "lonestarr" , "vespa" ); |
token.setRememberMe( true ); |
2,提交認證和憑據給身份驗證系統。
Subject currentUser = SecurityUtils.getSubject(); |
currentUser.login(token); |
3,判斷是否容許訪問,重試認證或者阻止訪問。
try { |
currentUser.login(token); |
} catch (UnknownAccountException uae) { |
log.info( "There is no user with username of " + token.getPrincipal()); |
} catch (IncorrectCredentialsException ice) { |
log.info( "Password for account " + token.getPrincipal() + " was incorrect!" ); |
} catch (LockedAccountException lae) { |
log.info( "The account for username " + token.getPrincipal() + " is locked. " + |
"Please contact your administrator to unlock it." ); |
} |
// ... catch more exceptions here (maybe custom ones specific to your application? |
catch (AuthenticationException ae) { |
//unexpected condition? error? |
} |
其中Remember Me的功能包括兩個方法,一個是
boolean isRemembered()
非匿名登陸的用戶能夠記住上次使用的主題的信息。
boolean isAuthenticated()
在此期間須要使用有效的憑據登陸系統,不然值爲false.
受權操做
受權的例子就是是否能夠訪問某個頁面,能夠操做某個按鈕,是否能夠編緝對應的數據等。
如何在shiro中使用受權
1,使用編程方式
判斷是否有管理員角色
if (currentUser.hasRole( "admin" )) { |
判斷用戶是否有打印的權限
Permission printPermission = new PrinterPermission(「laserjet3000n」,「print」); |
If (currentUser.isPermitted(printPermission)) {
//do one thing (show the print button?) } else { //don’t show the button? }
也可使用字符串的方式驗證
String perm = 「printer:print:laserjet4400n」; |
|
if (currentUser.isPermitted(perm)){ |
//show the print button? |
} else { |
//don’t show the button? |
} |
2,使用註釋方式
判斷用戶是否有 建立帳戶權限
//Will throw an AuthorizationException if none |
//of the caller’s roles imply the Account |
//'create' permission\u000B |
@RequiresPermissions (「account:create」) |
public void openAccount( Account acct ) { |
//create the account |
} |
判斷用戶角色,若是符合角色,可使用對應方法
//Throws an AuthorizationException if the caller |
//doesn’t have the ‘teller’ role: |
|
@RequiresRoles ( 「teller」 ) |
public void openAccount( Account acct ) { |
//do something in here that only a teller |
//should do |
} |
3,使用jsp taglib
判斷用戶是否有管理權限
<%@ taglib prefix=「shiro」 uri=http: //shiro.apache.org/tags %> |
<html> |
<body> |
<shiro:hasPermission name=「users:manage」> |
<a href=「manageUsers.jsp」> |
Click here to manage users |
</a> |
</shiro:hasPermission> |
<shiro:lacksPermission name=「users:manage」> |
No user management for you! |
</shiro:lacksPermission> |
</body> |
</html> |
從高的級別來看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)
身份驗證組件,對企圖登陸系統的用戶進行身份的驗證。其中包含一個Authentication Strategy
(org.apache.shiro.authc.pam.AuthenticationStrategy)組件。配置驗證成功與失敗的條件。
Authorizer (org.apache.shiro.authz.Authorizer)
受權組件,指用戶訪問特定應用程序的機制。
SessionManager (org.apache.shiro.session.mgt.SessionManager)
管理會話如何建立生命週期。其中包括的sessiondao是管理會議數據的持久操做:SessionDAO (org.apache.shiro.session.mgt.eis.SessionDAO),表明執行sessionManager的CRUD操做。
CacheManager (org.apache.shiro.cache.CacheManager)
緩存管理模塊。
Cryptography (org.apache.shiro.crypto.*)
加密模塊。
Realms (org.apache.shiro.realm.Realm)
多種方式處理的橋樑。
多種配置方式:
與spring,jboss,guice等進行配置。
1,編程方式配置
例如:
Realm realm = //instantiate or acquire a Realm instance. We'll discuss Realms later. |
|
SecurityManager securityManager = new DefaultSecurityManager(realm); |
//Make the SecurityManager instance available to the entire application via static memory: |
SecurityUtils.setSecurityManager(securityManager); |
2,sessionManager對象圖
若是你想使用sessionManager配置自定義的sessionDao信息,進行自定義會話管理
... |
|
DefaultSecurityManager securityManager = new DefaultSecurityManager(realm); |
SessionDAO sessionDAO = new CustomSessionDAO(); |
|
((DefaultSessionManager)securityManager.getSessionManager()).setSessionDAO(sessionDAO); |
... |
3,INI配置
1) 建立一個INI從SecurityManager
能夠從多種方式讀取INI配置文件的信息,如文件系統,類路徑等
import org.apache.shiro.SecurityUtils; |
import org.apache.shiro.util.Factory; |
import org.apache.shiro.mgt.SecurityManager; |
import org.apache.shiro.config.IniSecurityManagerFactory; |
... |
|
Factory<SecurityManager> factory = new IniSecurityManagerFactory( "classpath:shiro.ini" ); |
SecurityManager securityManager = factory.getInstance(); |
SecurityUtils.setSecurityManager(securityManager); |
2) 經過Ini實例讀取
相似於Properties的方式
import org.apache.shiro.SecurityUtils; |
import org.apache.shiro.util.Factory; |
import org.apache.shiro.mgt.SecurityManager; |
import org.apache.shiro.config.Ini; |
import org.apache.shiro.config.IniSecurityManagerFactory; |
... |
|
Ini ini = new Ini(); |
//populate the Ini instance as necessary |
... |
Factory<SecurityManager> factory = new IniSecurityManagerFactory(ini); |
SecurityManager securityManager = factory.getInstance(); |
SecurityUtils.setSecurityManager(securityManager); |
加載以後就能夠操做INI的配置了。
4,INI配置
每個節點都是單獨的,不能夠重複,註釋可使用#或者;
配置示例
# ======================= |
# Shiro INI configuration |
# ======================= |
[main] |
# Objects and their properties are defined here, |
# Such as the securityManager, Realms and anything |
# else needed to build the SecurityManager |
|
[users] |
# The 'users' section is for simple deployments |
# when you only need a small number of statically-defined |
# set of User accounts. |
|
[roles] |
# The 'roles' section is for simple deployments |
# when you only need a small number of statically-defined |
# roles. |
|
[urls] |
# The 'urls' section is used for url-based security |
# in web applications. We'll discuss this section in the |
# Web documentation |
1) [main]
配置sessionManager的實例和它的依賴。
配置示例
[main] |
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher |
|
myRealm = com.company.security.shiro.DatabaseRealm |
myRealm.connectionTimeout = 30000 |
myRealm.username = jsmith |
myRealm.password = secret |
myRealm.credentialsMatcher = $sha256Matcher |
securityManager.sessionManager.globalSessionTimeout = 1800000 |
定義一個對象
[main] |
myRealm = com.company.shiro.realm.MyRealm |
... |
簡單的屬性設置
... |
myRealm.connectionTimeout = 30000 |
myRealm.username = jsmith |
... |
配置信息將轉入到對應的set方法中
... |
myRealm.setConnectionTimeout( 30000 ); |
myRealm.setUsername( "jsmith" ); |
... |
參考值
你可使用$符號引用先前定義的一個對象的實例
... |
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher |
... |
myRealm.credentialsMatcher = $sha256Matcher |
... |
嵌套屬性
... |
securityManager.sessionManager.globalSessionTimeout = 1800000 |
... |
將被注入到下面的程序中
securityManager.getSessionManager().setGlobalSessionTimeout( 1800000 ); |
引用其它的屬性
sessionListener1 = com.company.my.SessionListenerImplementation |
... |
sessionListener2 = com.company.my.other.SessionListenerImplementation |
... |
securityManager.sessionManager.sessionListeners = $sessionListener1, $sessionListener2 |
以鍵值的配置方式
object1 = com.company.some.Class |
object2 = com.company.another.Class |
... |
anObject = some. class .with.a.Map.property |
|
anObject.mapProperty = key1:$object1, key2:$object2 |
2) [users]
在用戶比較少的狀況下這種配置信息是有效的
[users] |
admin = secret |
lonestarr = vespa, goodguy, schwartz |
darkhelmet = ludicrousspeed, badguy, schwartz |
3) [roles]
若是角色信息比較少的狀況下可使用這項配置
[roles] |
# 'admin' role has all permissions, indicated by the wildcard '*' |
admin = * |
# The 'schwartz' role can do anything (*) with any lightsaber: |
schwartz = lightsaber:* |
# The 'goodguy' role is allowed to 'drive' (action) the winnebago (type) with |
# license plate 'eagle5' (instance specific id) |
goodguy = winnebago:drive:eagle5 |
4) [urls]
配置url等可訪問的資源信息。
身份認證
身份認證分三個步驟
1)提交主題和憑據
2)進行身份認證
3)判斷是經過,從新提交仍是不經過
驗證順序
1)調用subject的login方法,提交主體和憑據。
2)獲得對應操做的Security Manager
3)經過Sceurity Manager獲得對應的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)編程
角色判斷
Subject currentUser = SecurityUtils.getSubject(); if (currentUser.hasRole("administrator")) { //show the admin button } else { //don't show the button? Grey it out? }
hasRole(String roleName) 主題是否已分配給指定的角色
hasRoles(List<String> roleNames) 是否包含指定的角色
hasAllRoles(Collection<String> roleNames) 是否包含指定的全部角色
角色斷言
Subject currentUser = SecurityUtils.getSubject(); //guarantee that the current user is a bank teller and //therefore allowed to open the account: currentUser.checkRole("bankTeller"); openBankAccount();
checkRole(String roleName) 斷言是不是指定角色
checkRoles(Collection<String> roleNames) 斷言是否包含如下角色
checkRoles(String... roleNames) 斷言是否包含全部角色
若是判斷指定用戶是否有權限訪問指定名稱的打印機
那麼就會用到下列幾個方法
Permission printPermission = new PrinterPermission("laserjet4400n", "print"); Subject currentUser = SecurityUtils.getSubject(); if (currentUser.isPermitted(printPermission)) { //show the Print button } else { //don't show the button? Grey it out? }
isPermitted(Permission p) 判斷主題是否容許執行一個動做
isPermitted(List<Permission> perms) 是否容許執行一組動做
isPermittedAll(Collection<Permission> perms) 是否容許執行全部動做
基於字符串的權限檢查
Subject currentUser = SecurityUtils.getSubject(); if (currentUser.isPermitted("printer:print:laserjet4400n")) { //show the Print button } else { //don't show the button? Grey it out? }
也能夠以下使用
Subject currentUser = SecurityUtils.getSubject(); Permission p = new WildcardPermission("printer:print:laserjet4400n"); if (currentUser.isPermitted(p) { //show the Print button } else { //don't show the button? Grey it out? }
權限斷言相似於角色斷言。
2)annocation方式
@RequiresAuthentication public void updateAccount(Account userAccount) { //this method will only be invoked by a //Subject that is guaranteed authenticated ... }
等同於下述代碼
public void updateAccount(Account userAccount) { if (!SecurityUtils.getSubject().isAuthenticated()) { throw new AuthorizationException(...); } //Subject is guaranteed authenticated here ... }
@RequiresGuest public void signUp(User newUser) { //this method will only be invoked by a //Subject that is unknown/anonymous ... }
等同於
public void signUp(User newUser) { Subject currentUser = SecurityUtils.getSubject(); PrincipalCollection principals = currentUser.getPrincipals(); if (principals != null && !principals.isEmpty()) { //known identity - not a guest: throw new AuthorizationException(...); } //Subject is guaranteed to be a 'guest' here ... }
@RequiresPermissions("account:create") public void createAccount(Account account) { //this method will only be invoked by a Subject //that is permitted to create an account ... }
等同於
public void createAccount(Account account) { Subject currentUser = SecurityUtils.getSubject(); if (!subject.isPermitted("account:create")) { throw new AuthorizationException(...); } //Subject is guaranteed to be permitted here ... }
@RequiresRoles("administrator") public void deleteUser(User user) { //this method will only be invoked by an administrator ... }
等同於
public void deleteUser(User user) { Subject currentUser = SecurityUtils.getSubject(); if (!subject.hasRole("administrator")) { throw new AuthorizationException(...); } //Subject is guaranteed to be an 'administrator' here ... }
@RequiresUser public void updateAccount(Account account) { //this method will only be invoked by a 'user' //i.e. a Subject with a known identity ... }
等同於
public void updateAccount(Account account) { Subject currentUser = SecurityUtils.getSubject(); PrincipalCollection principals = currentUser.getPrincipals(); if (principals == null || principals.isEmpty()) { //no identity - they're anonymous, not allowed: throw new AuthorizationException(...); } //Subject is guaranteed to have a known identity here ... }
受權順序
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帳戶信息類
import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; import java.util.List; public class Account { private static long _SEQUENCE; private long _id; private String _ownerName; private volatile boolean _isActive; private double _balance; private final List<AccountTransaction> _transactions; private String _createdBy; private Date _creationDate; public Account(String anOwnerName) { _id = ++_SEQUENCE; _ownerName = anOwnerName; _isActive = true; _balance = 0.0d; _transactions = new ArrayList<AccountTransaction>(); _createdBy = "unknown"; _creationDate = new Date(); } /** * Returns the id attribute. * * @return The id value. */ public long getId() { return _id; } /** * Returns the ownerName attribute. * * @return The ownerName value. */ public String getOwnerName() { return _ownerName; } /** * Returns the isActive attribute. * * @return The isActive value. */ public boolean isActive() { return _isActive; } /** * Changes the value of the attributes isActive. * * @param aIsActive The new value of the isActive attribute. */ public void setActive(boolean aIsActive) { _isActive = aIsActive; } /** * Changes the value of the attributes ownerName. * * @param aOwnerName The new value of the ownerName attribute. */ public void setOwnerName(String aOwnerName) { _ownerName = aOwnerName; } /** * Returns the balance attribute. * * @return The balance value. */ public double getBalance() { return _balance; } /** * Returns the transactions attribute. * * @return The transactions value. */ public List<AccountTransaction> getTransactions() { return _transactions; } protected void applyTransaction(AccountTransaction aTransaction) throws NotEnoughFundsException, InactiveAccountException { if (!_isActive) { throw new InactiveAccountException("Unable to apply " + aTransaction.getType() + " of amount " + aTransaction.getAmount() + " to account " + _id); } synchronized (_transactions) { if (AccountTransaction.TransactionType.DEPOSIT == aTransaction.getType()) { _transactions.add(aTransaction); _balance += aTransaction.getAmount(); } else if (AccountTransaction.TransactionType.WITHDRAWAL == aTransaction.getType()) { if (_balance < aTransaction.getAmount()) { throw new NotEnoughFundsException("Unable to withdraw " + aTransaction.getAmount() + "$ from account " + _id + " - current balance is " + _balance); } _transactions.add(aTransaction); _balance -= aTransaction.getAmount(); } else { throw new IllegalArgumentException("The transaction passed in has an invalid type: " + aTransaction.getType()); } } } /** * Changes the value of the attributes createdBy. * * @param aCreatedBy The new value of the createdBy attribute. */ protected void setCreatedBy(String aCreatedBy) { _createdBy = aCreatedBy; } /** * Returns the createdBy attribute. * * @return The createdBy value. */ public String getCreatedBy() { return _createdBy; } /** * Returns the creationDate attribute. * * @return The creationDate value. */ public Date getCreationDate() { return _creationDate; } /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return new ToStringBuilder(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", new Timestamp(_creationDate.getTime())). toString(); } }
AccountNotFoundException,帳號不存在異常
package org.apache.shiro.samples.aspectj.bank; public class AccountNotFoundException extends BankServiceException { public AccountNotFoundException(String aMessage) { super(aMessage); } }
AccountTransaction,帳號轉入與轉出
package org.apache.shiro.samples.aspectj.bank; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import java.sql.Timestamp; import java.util.Date; public class AccountTransaction { private static long _SEQUENCE; public enum TransactionType { DEPOSIT, WITHDRAWAL } private long _id; private TransactionType _type; private long _accountId; private double _amount; private String _createdBy; private Date _creationDate; public static AccountTransaction createDepositTx(long anAccountId, double anAmount) { return new AccountTransaction(TransactionType.DEPOSIT, anAccountId, anAmount); } public static AccountTransaction createWithdrawalTx(long anAccountId, double anAmount) { return new AccountTransaction(TransactionType.WITHDRAWAL, anAccountId, anAmount); } private AccountTransaction(TransactionType aType, long anAccountId, double anAmount) { _id = ++_SEQUENCE; _type = aType; _accountId = anAccountId; _amount = anAmount; _createdBy = "unknown"; _creationDate = new Date(); } /** * Returns the id attribute. * * @return The id value. */ public long getId() { return _id; } /** * Returns the type attribute. * * @return The type value. */ public TransactionType getType() { return _type; } /** * Returns the accountId attribute. * * @return The accountId value. */ public long getAccountId() { return _accountId; } /** * Returns the amount attribute. * * @return The amount value. */ public double getAmount() { return _amount; } /** * Changes the value of the attributes createdBy. * * @param aCreatedBy The new value of the createdBy attribute. */ protected void setCreatedBy(String aCreatedBy) { _createdBy = aCreatedBy; } /** * Returns the createdBy attribute. * * @return The createdBy value. */ public String getCreatedBy() { return _createdBy; } /** * Returns the creationDate attribute. * * @return The creationDate value. */ public Date getCreationDate() { return _creationDate; } /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE). append("id", _id). append("type", _type). append("accountId", _accountId). append("amount", _amount). append("createdBy", _createdBy). append("creationDate", new Timestamp(_creationDate.getTime())). toString(); } }
BankServerRunner,銀行服務運行
package org.apache.shiro.samples.aspectj.bank; public class BankServerRunner { private SecureBankService _bankService; public synchronized void start() throws Exception { if (_bankService == null) { _bankService = new SecureBankService(); _bankService.start(); } } public synchronized void stop() { if (_bankService != null) { try { _bankService.dispose(); } finally { _bankService = null; } } } public BankService getBankService() { return _bankService; } public static void main(String[] args) { try { BankServerRunner server = new BankServerRunner(); server.start(); server.stop(); } catch (Exception e) { e.printStackTrace(); } } }
BankService,銀行服務接口
package org.apache.shiro.samples.aspectj.bank; import java.util.Date; public interface BankService { public long[] searchAccountIdsByOwner(String anOwnerName); public long createNewAccount(String anOwnerName); public double getBalanceOf(long anAccountId) throws AccountNotFoundException; public String getOwnerOf(long anAccountId) throws AccountNotFoundException; public double depositInto(long anAccountId, double anAmount) throws AccountNotFoundException, InactiveAccountException; public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException; public TxLog[] getTxHistoryFor(long anAccountId) throws AccountNotFoundException; public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException; public boolean isAccountActive(long anAccountId) throws AccountNotFoundException; public static class TxLog { private Date _creationDate; private double _amount; private String _madeBy; public TxLog(Date aCreationDate, double aAmount, String aMadeBy) { super(); _creationDate = aCreationDate; _amount = aAmount; _madeBy = aMadeBy; } /** * Returns the creationDate attribute. * * @return The creationDate value. */ public Date getCreationDate() { return _creationDate; } /** * Returns the amount attribute. * * @return The amount value. */ public double getAmount() { return _amount; } /** * Returns the madeBy attribute. * * @return The madeBy value. */ public String getMadeBy() { return _madeBy; } } }
BankServiceException,銀行服務異常
package org.apache.shiro.samples.aspectj.bank; public class BankServiceException extends Exception { public BankServiceException(String aMessage) { super(aMessage); } public BankServiceException(String aMessage, Throwable aCause) { super(aMessage, aCause); } }
InactiveAccountException,存入帳戶異常
package org.apache.shiro.samples.aspectj.bank; public class InactiveAccountException extends BankServiceException { public InactiveAccountException(String aMessage) { super(aMessage); } }
NotEnoughFundsException,帳戶不足異常
package org.apache.shiro.samples.aspectj.bank; public class NotEnoughFundsException extends BankServiceException { public NotEnoughFundsException(String aMessage) { super(aMessage); } }
SecureBankService,安全銀行的服務類,處理各類銀行的業務
package org.apache.shiro.samples.aspectj.bank; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.samples.aspectj.bank.AccountTransaction.TransactionType; import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class SecureBankService implements BankService { private static final Logger log = LoggerFactory.getLogger(SecureBankService.class); private volatile boolean _isRunning; private final List<Account> _accounts; private Map<Long, Account> _accountsById; /** * Creates a new {@link SecureBankService} instance. */ public SecureBankService() { _accounts = new ArrayList<Account>(); _accountsById = new HashMap<Long, Account>(); } /** * Starts this service */ public void start() throws Exception { _isRunning = true; log.info("銀行服務開始..."); } /** * Stop this service */ public void dispose() { log.info("銀行服務中止..."); _isRunning = false; synchronized (_accounts) { _accountsById.clear(); _accounts.clear(); } log.info("銀行服務中止!"); } /** * Internal utility method that validate the internal state of this service. */ protected void assertServiceState() { if (!_isRunning) { throw new IllegalStateException("銀行的服務沒有開始"); } } public int getAccountCount() { return _accounts.size(); } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#createNewAccount(java.lang.String) */ @RequiresPermissions("bankAccount:create") public long createNewAccount(String anOwnerName) { assertServiceState(); log.info("建立新的帳戶給 " + anOwnerName); synchronized (_accounts) { Account account = new Account(anOwnerName); account.setCreatedBy(getCurrentUsername()); _accounts.add(account); _accountsById.put(account.getId(), account); log.debug("建立新的帳戶: " + account); return account.getId(); } } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#searchAccountIdsByOwner(java.lang.String) */ public long[] searchAccountIdsByOwner(String anOwnerName) { assertServiceState(); log.info("查找已經存在的銀行帳戶爲 " + anOwnerName); ArrayList<Account> matchAccounts = new ArrayList<Account>(); synchronized (_accounts) { for (Account a : _accounts) { if (a.getOwnerName().toLowerCase().contains(anOwnerName.toLowerCase())) { matchAccounts.add(a); } } } long[] accountIds = new long[matchAccounts.size()]; int index = 0; for (Account a : matchAccounts) { accountIds[index++] = a.getId(); } log.debug("找到 " + accountIds.length + " 相匹配的帳戶的名稱 " + anOwnerName); return accountIds; } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#getOwnerOf(long) */ @RequiresPermissions("bankAccount:read") public String getOwnerOf(long anAccountId) throws AccountNotFoundException { assertServiceState(); log.info("得到銀行帳戶的全部者 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); return a.getOwnerName(); } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#getBalanceOf(long) */ @RequiresPermissions("bankAccount:read") public double getBalanceOf(long anAccountId) throws AccountNotFoundException { assertServiceState(); log.info("獲得帳戶的餘額 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); return a.getBalance(); } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#depositInto(long, double) */ @RequiresPermissions("bankAccount:operate") public double depositInto(long anAccountId, double anAmount) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("存錢到 " + anAmount + " 這個帳戶 " + anAccountId); try { Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createDepositTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("建立一個新的交易 " + tx); a.applyTransaction(tx); log.debug("新的帳戶餘額 " + a.getId() + " 存款後 " + a.getBalance()); return a.getBalance(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("應該從未發生過", nefe); } } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#withdrawFrom(long, double) */ @RequiresPermissions("bankAccount:operate") public double withdrawFrom(long anAccountId, double anAmount) throws AccountNotFoundException, NotEnoughFundsException, InactiveAccountException { assertServiceState(); log.info("取款 " + anAmount + " 從帳戶 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); AccountTransaction tx = AccountTransaction.createWithdrawalTx(anAccountId, anAmount); tx.setCreatedBy(getCurrentUsername()); log.debug("建立一個新的交易 " + tx); a.applyTransaction(tx); log.debug("新的帳戶餘額 " + a.getId() + " 取款後 " + a.getBalance()); return a.getBalance(); } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#getTxHistoryFor(long) */ @RequiresPermissions("bankAccount:read") public TxLog[] getTxHistoryFor(long anAccountId) throws AccountNotFoundException { assertServiceState(); log.info("獲取帳戶交易 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); TxLog[] txs = new TxLog[a.getTransactions().size()]; int index = 0; for (AccountTransaction tx : a.getTransactions()) { log.debug("查過交易 " + tx); if (TransactionType.DEPOSIT == tx.getType()) { txs[index++] = new TxLog(tx.getCreationDate(), tx.getAmount(), tx.getCreatedBy()); } else { txs[index++] = new TxLog(tx.getCreationDate(), -1.0d * tx.getAmount(), tx.getCreatedBy()); } } return txs; } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#closeAccount(long) */ @RequiresPermissions("bankAccount:close") public double closeAccount(long anAccountId) throws AccountNotFoundException, InactiveAccountException { assertServiceState(); log.info("截止帳戶 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); if (!a.isActive()) { throw new InactiveAccountException("這個帳戶 " + anAccountId + " 已經關閉"); } try { AccountTransaction tx = AccountTransaction.createWithdrawalTx(a.getId(), a.getBalance()); tx.setCreatedBy(getCurrentUsername()); log.debug("建立一個新的交易 " + tx); a.applyTransaction(tx); a.setActive(false); log.debug("帳戶 " + a.getId() + " 如今是關閉的 " + tx.getAmount() + " 針對這個業主"); return tx.getAmount(); } catch (NotEnoughFundsException nefe) { throw new IllegalStateException("應該歷來不發生", nefe); } } /* (non-Javadoc) * @see com.connectif.trilogy.root.security.BankService#isAccountActive(long) */ @RequiresPermissions("bankAccount:read") public boolean isAccountActive(long anAccountId) throws AccountNotFoundException { assertServiceState(); log.info("獲取帳戶的活動狀態 " + anAccountId); Account a = safellyRetrieveAccountForId(anAccountId); return a.isActive(); } /** * Internal method that safelly (concurrency-wise) retrieves an account from the id passed in. * * @param anAccountId The identifier of the account to retrieve. * @return The account instance retrieved. * @throws AccountNotFoundException If no account is found for the provided identifier. */ protected Account safellyRetrieveAccountForId(long anAccountId) throws AccountNotFoundException { Account account = null; synchronized (_accounts) { account = _accountsById.get(anAccountId); } if (account == null) { throw new AccountNotFoundException("沒有找到ID爲 " + anAccountId + " 的帳戶"); } log.info("檢查帳戶 " + account); return account; } /** * Internal utility method to retrieve the username of the current authenticated user. * * @return The name. */ protected String getCurrentUsername() { Subject subject = SecurityUtils.getSubject(); if (subject == null || subject.getPrincipal() == null || !subject.isAuthenticated()) { throw new IllegalStateException("沒法檢索當前驗證的主題"); } return SecurityUtils.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:read bankAccount:close user = bankAccount:create, bankAccount:read, bankAccount:operate
包括種種操做的權限分配
使用junit測試
@BeforeClass public static void setUpClass() throws Exception { BasicConfigurator.resetConfiguration(); BasicConfigurator.configure(); logger = Logger.getLogger(SecureBankServiceTest.class.getSimpleName()); Factory<SecurityManager> factory = new IniSecurityManagerFactory( "classpath:shiroBankServiceTest.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); service = new SecureBankService(); service.start(); }
加載對應的ini中的信息,在每次運行以前
登陸用戶的操做方法
// 做爲用戶登陸,不能關閉帳戶 protected void loginAsUser() { if (_subject == null) { _subject = SecurityUtils.getSubject(); } // use dan to run as a normal user (which cannot close an account) _subject.login(new UsernamePasswordToken("dan", "123")); } // 做爲超級用戶登陸,不能操做帳戶 protected void loginAsSuperviser() { if (_subject == null) { _subject = SecurityUtils.getSubject(); } // use sally to run as a superviser (which cannot operate an account) _subject.login(new UsernamePasswordToken("sally", "1234")); }
給張三建立帳戶,而且檢查帳戶的狀況
@Test public void testCreateAccount() throws Exception { loginAsUser(); createAndValidateAccountFor("張三"); } protected long createAndValidateAccountFor(String anOwner) throws Exception { long createdId = service.createNewAccount(anOwner); assertAccount(anOwner, true, 0.0d, 0, createdId); return createdId; } public static void assertAccount(String eOwnerName, boolean eIsActive, double eBalance, int eTxLogCount, long actualAccountId) throws Exception { Assert.assertEquals(eOwnerName, service.getOwnerOf(actualAccountId)); Assert.assertEquals(eIsActive, service.isAccountActive(actualAccountId)); Assert.assertEquals(eBalance, service.getBalanceOf(actualAccountId)); Assert.assertEquals(eTxLogCount, service.getTxHistoryFor(actualAccountId).length); }
看打印出來的信息
1 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 10 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 12 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 46 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 48 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 62 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 120 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 120 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 121 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 121 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 121 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 122 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 123 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 132 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 張三 203 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=張三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71] 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=張三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=張三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=張三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=張三,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:40:26.71] 206 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 206 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [66208001-e91d-4625-938f-1b1c08b2645c] 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
建立張三的用戶信息而且檢查張三的帳戶的狀況。
第二個測試
建立帳戶李四而且存入250到帳戶裏,用戶有建立和操做的權限,因此能夠操做
@Test public void testDepositInto_singleTx() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("李四"); makeDepositAndValidateAccount(accountId, 250.00d, "李四"); }
protected double makeDepositAndValidateAccount(long anAccountId, double anAmount, String eOwnerName) throws Exception { double previousBalance = service.getBalanceOf(anAccountId); int previousTxCount = service.getTxHistoryFor(anAccountId).length; double newBalance = service.depositInto(anAccountId, anAmount); Assert.assertEquals(previousBalance + anAmount, newBalance); assertAccount(eOwnerName, true, newBalance, 1 + previousTxCount, anAccountId); return newBalance; }
運行後的結果
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 12 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 44 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 46 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 56 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 59 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 115 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 115 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 116 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 117 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 124 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 171 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 李四 188 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 250.0 這個帳戶 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-12 20:44:15.013] 196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 250.0 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=李四,isActive=true,balance=250.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:44:14.991] 196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=250.0,createdBy=dan,creationDate=2011-09-12 20:44:15.013] 196 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 197 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [3b53dc16-67d5-4730-ae8a-872d113c7546] 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
建立帳戶王五而且存入多筆款項
@Test public void testDepositInto_multiTxs() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("王五"); makeDepositAndValidateAccount(accountId, 50.00d, "王五"); makeDepositAndValidateAccount(accountId, 300.00d, "王五"); makeDepositAndValidateAccount(accountId, 85.00d, "王五"); assertAccount("王五", true, 435.00d, 3, accountId); }
一共存入三筆,最後獲得的數據的總和爲435
看日誌打出來的信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 10 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 12 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 46 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 49 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 62 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 119 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 119 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 119 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 120 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 121 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 129 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 王五 204 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 204 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 204 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 50.0 這個帳戶 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 50.0 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 210 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 300.0 這個帳戶 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741] 211 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 350.0 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 85.0 這個帳戶 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=350.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 435.0 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=王五,isActive=true,balance=435.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 20:52:54.72] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 20:52:54.739] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=DEPOSIT,accountId=1,amount=300.0,createdBy=dan,creationDate=2011-09-12 20:52:54.741] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=DEPOSIT,accountId=1,amount=85.0,createdBy=dan,creationDate=2011-09-12 20:52:54.742] 214 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 214 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [1d66c2ec-a668-478a-8f30-e3c65f80a16d] 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
建立帳戶賈六而且取款,由於帳戶爲空因此會拋出異常
@Test(expected = NotEnoughFundsException.class) public void testWithdrawFrom_emptyAccount() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("賈六"); service.withdrawFrom(accountId, 100.00d); }
看執行的結果
1 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 11 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 13 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 15 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 46 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 50 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 60 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 63 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 126 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 126 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 128 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 128 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 129 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 130 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 132 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 145 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 賈六 205 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 206 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 100.0 從帳戶 1 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=賈六,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 20:56:05.029] 210 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 20:56:05.047] 210 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 210 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [05f3559d-d0c4-458c-a220-31389550576f] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
獲得指望的NotEnoughFundsException,運行經過
而後建立帳戶周七,先存入50,而後取100,結果獲得的與面相同,餘額不足異常
@Test(expected = NotEnoughFundsException.class) public void testWithdrawFrom_notEnoughFunds() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("周七"); makeDepositAndValidateAccount(accountId, 50.00d, "周七"); service.withdrawFrom(accountId, 100.00d); }
看打印出的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 10 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 12 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 44 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 48 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 59 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 61 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 118 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 119 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 119 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 119 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 120 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 121 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 131 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 179 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 周七 196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 50.0 這個帳戶 1 199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 200 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 21:01:30.955] 200 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 50.0 200 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=50.0,createdBy=dan,creationDate=2011-09-12 21:01:30.955] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 100.0 從帳戶 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=周七,isActive=true,balance=50.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:01:30.936] 201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:01:30.956] 202 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 202 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [a85a89c7-a805-4086-bd5b-109a0d54086c] 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
再測試先存後取,先存入500,後取100,最後獲得的結果爲400
@Test public void testWithdrawFrom_singleTx() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("國八"); makeDepositAndValidateAccount(accountId, 500.00d, "國八"); makeWithdrawalAndValidateAccount(accountId, 100.00d, "國八"); assertAccount("國八", true, 400.00d, 2, accountId); }
看打印出的結果
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 10 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 11 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 43 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 45 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 55 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 59 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 115 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 116 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 116 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 116 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 117 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 124 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 168 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 國八 185 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 500.0 這個帳戶 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 190 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:03:17.103] 190 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 500.0 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 191 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:03:17.103] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 191 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:03:17.103] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 100.0 從帳戶 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:03:17.104] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 取款後 400.0 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:03:17.103] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:03:17.104] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=國八,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:03:17.085] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:03:17.103] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:03:17.104] 193 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 193 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [192dddd6-7090-435c-bb65-b3b64a73d667] 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
存入一筆取多筆
@Test public void testWithdrawFrom_manyTxs() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Zoe Smith"); makeDepositAndValidateAccount(accountId, 500.00d, "Zoe Smith"); makeWithdrawalAndValidateAccount(accountId, 100.00d, "Zoe Smith"); makeWithdrawalAndValidateAccount(accountId, 75.00d, "Zoe Smith"); makeWithdrawalAndValidateAccount(accountId, 125.00d, "Zoe Smith"); assertAccount("Zoe Smith", true, 200.00d, 4, accountId); }
查看打印的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 11 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 53 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 57 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 72 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 76 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 132 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 132 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 133 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 133 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 133 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 134 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 135 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 143 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 Zoe Smith 205 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 205 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 500.0 這個帳戶 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 212 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 500.0 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 212 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 100.0 從帳戶 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 取款後 400.0 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 75.0 從帳戶 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=400.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339] 215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 取款後 325.0 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 215 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339] 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 125.0 從帳戶 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=325.0,tx.count=3,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 取款後 200.0 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 216 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 216 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339] 217 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341] 217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 217 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 220 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 220 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 221 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=200.0,tx.count=4,createdBy=dan,creationDate=2011-09-12 21:04:28.312] 221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:04:28.337] 221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=100.0,createdBy=dan,creationDate=2011-09-12 21:04:28.338] 221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=3,type=WITHDRAWAL,accountId=1,amount=75.0,createdBy=dan,creationDate=2011-09-12 21:04:28.339] 221 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=4,type=WITHDRAWAL,accountId=1,amount=125.0,createdBy=dan,creationDate=2011-09-12 21:04:28.341] 221 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 221 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [1ecbe8f2-f2f5-468b-af2b-d82d6b1267fa] 223 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 223 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
存多少取多少
@Test public void testWithdrawFrom_upToZero() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Zoe Smith"); makeDepositAndValidateAccount(accountId, 500.00d, "Zoe Smith"); makeWithdrawalAndValidateAccount(accountId, 500.00d, "Zoe Smith"); assertAccount("Zoe Smith", true, 0.00d, 2, accountId); }
查看打印的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 11 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 12 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 43 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 45 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 55 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 58 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 114 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 114 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 114 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 115 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 115 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 115 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 116 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 125 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 168 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 Zoe Smith 186 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 186 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 187 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 188 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 189 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 500.0 這個帳戶 1 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 500.0 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 取款 500.0 從帳戶 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=500.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 取款後 0.0 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804] 193 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806] 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 194 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Zoe Smith,isActive=true,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:05:23.783] 194 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.804] 194 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=500.0,createdBy=dan,creationDate=2011-09-12 21:05:23.806] 194 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 195 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [12aeb47c-f3c1-46c1-baec-78da03762422] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
關閉帳戶餘額爲0的帳戶,普通用戶沒有權限,因此須要轉到另一個角色的帳戶進行操做
@Test public void testCloseAccount_zeroBalance() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Chris Smith"); logoutCurrentSubject(); loginAsSuperviser(); double closingBalance = service.closeAccount(accountId); Assert.assertEquals(0.00d, closingBalance); assertAccount("Chris Smith", false, 0.00d, 1, accountId); }
查看打印出來的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 11 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 13 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 14 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 47 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 50 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 61 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 63 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 121 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 121 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 121 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 122 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 122 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 123 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 124 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 133 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 Chris Smith 207 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 207 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 208 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 209 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 210 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 210 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [c4adc0a6-987c-4c94-ad38-d13f683c7f1d] 211 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 211 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 211 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false]. Returned account [sally] 211 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 211 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 211 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 截止帳戶 1 211 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:13:04.516] 213 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 帳戶 1 如今是關閉的 0.0 針對這個業主 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 213 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 214 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:13:04.496] 214 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:13:04.516] 214 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}sally 214 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [f0988257-3441-489a-859c-538043ead6e3] 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 215 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
建立用戶而且存入350,而後對這個用戶進行關閉操做
@Test public void testCloseAccount_withBalance() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Gerry Smith"); makeDepositAndValidateAccount(accountId, 385.00d, "Gerry Smith"); logoutCurrentSubject(); loginAsSuperviser(); double closingBalance = service.closeAccount(accountId); Assert.assertEquals(385.00d, closingBalance); assertAccount("Gerry Smith", false, 0.00d, 2, accountId); }
查看打印的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 11 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 12 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 46 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 48 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 58 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 61 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 118 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 118 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 119 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 128 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 173 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 Gerry Smith 190 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 190 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 191 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 192 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 存錢到 385.0 這個帳戶 1 193 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672] 195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 新的帳戶餘額 1 存款後 385.0 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 196 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672] 196 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 196 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [b2e689a3-cd4a-4785-962b-0df77758533b] 197 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 197 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 197 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false]. Returned account [sally] 197 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 197 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 197 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 截止帳戶 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=true,balance=385.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 197 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-12 21:17:58.674] 197 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 帳戶 1 如今是關閉的 385.0 針對這個業主 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 198 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Gerry Smith,isActive=false,balance=0.0,tx.count=2,createdBy=dan,creationDate=2011-09-12 21:17:58.652] 198 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=DEPOSIT,accountId=1,amount=385.0,createdBy=dan,creationDate=2011-09-12 21:17:58.672] 198 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=2,type=WITHDRAWAL,accountId=1,amount=385.0,createdBy=sally,creationDate=2011-09-12 21:17:58.674] 198 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}sally 198 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [6ffa0d67-7510-4205-9fa8-01b6bb9793f5] 199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
建立用戶而且關閉正活動的帳戶
@Test(expected = InactiveAccountException.class) public void testCloseAccount_alreadyClosed() throws Exception { loginAsUser(); long accountId = createAndValidateAccountFor("Chris Smith"); logoutCurrentSubject(); loginAsSuperviser(); double closingBalance = service.closeAccount(accountId); Assert.assertEquals(0.00d, closingBalance); assertAccount("Chris Smith", false, 0.00d, 1, accountId); service.closeAccount(accountId); }
查看打印的日誌信息
0 [main] DEBUG org.apache.shiro.io.ResourceUtils - Opening resource from class path [shiroBankServiceTest.ini] 9 [main] DEBUG org.apache.shiro.config.Ini - Parsing [users] 12 [main] DEBUG org.apache.shiro.config.Ini - Parsing [roles] 13 [main] DEBUG org.apache.shiro.config.IniFactorySupport - Creating instance from Ini [sections=users,roles] 44 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [roles] section. Processing... 47 [main] DEBUG org.apache.shiro.realm.text.IniRealm - Discovered the [users] section. Processing... 57 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務開始... 60 [main] INFO SecureBankServiceTest - ######################### ### 開始測試用例 1 117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 117 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 117 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - dan, rememberMe=false]. Returned account [dan] 118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 118 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 119 [main] DEBUG org.apache.shiro.session.mgt.AbstractValidatingSessionManager - No sessionValidationScheduler set. Attempting to create default instance. 120 [main] INFO org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler... 127 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 178 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶給 Chris Smith 195 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立新的帳戶: Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 195 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 196 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 197 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 198 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}dan 198 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [8ff8f7c8-5d03-4e4f-b47d-0414cd43111d] 198 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Performing credentials equality check for tokenCredentials of type [[C and accountCredentials of type [java.lang.String] 198 [main] DEBUG org.apache.shiro.authc.credential.SimpleCredentialsMatcher - Both credentials arguments can be easily converted to byte arrays. Performing array equals comparison 199 [main] DEBUG org.apache.shiro.authc.AbstractAuthenticator - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - sally, rememberMe=false]. Returned account [sally] 199 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 199 [main] DEBUG org.apache.shiro.subject.support.DefaultSubjectContext - No SecurityManager available in subject context map. Falling back to SecurityUtils.getSecurityManager() lookup. 199 [main] DEBUG org.apache.shiro.session.mgt.DefaultSessionManager - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null] 199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 截止帳戶 1 199 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=true,balance=0.0,tx.count=0,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 建立一個新的交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:19:53.777] 201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 帳戶 1 如今是關閉的 0.0 針對這個業主 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 得到銀行帳戶的全部者 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶的活動狀態 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲得帳戶的餘額 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 獲取帳戶交易 1 201 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 201 [main] DEBUG org.apache.shiro.samples.aspectj.bank.SecureBankService - 查過交易 AccountTransaction[id=1,type=WITHDRAWAL,accountId=1,amount=0.0,createdBy=sally,creationDate=2011-09-12 21:19:53.777] 202 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 截止帳戶 1 202 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 檢查帳戶 Account[id=1,ownerName=Chris Smith,isActive=false,balance=0.0,tx.count=1,createdBy=dan,creationDate=2011-09-12 21:19:53.755] 202 [main] DEBUG org.apache.shiro.mgt.DefaultSecurityManager - Logging out subject with primary principal {}sally 202 [main] DEBUG org.apache.shiro.session.mgt.AbstractSessionManager - Stopping session with id [53286615-5b71-4642-b3e8-916fb77fba60] 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止... 203 [main] INFO org.apache.shiro.samples.aspectj.bank.SecureBankService - 銀行服務中止!
其中判斷權限使用的是annocation的方式
@RequiresPermissions("bankAccount:create") 是否有用戶建立權限
@RequiresPermissions("bankAccount:read") 讀權限
@RequiresPermissions("bankAccount:operate") 操做權限
@RequiresPermissions("bankAccount:close") 關閉權限
根據以上幾個標籤就能夠獲得對應的權限信息