資源簡介
Shiro入門實例 Shiro入門教程 Shiro框架學習demo http://www.xttblog.com/?p=669 權限管理教程。Shiro是一個強大易用的Java安全框架,提供了認證、授權、加密和會話管理等功能。
Shiro可以在任何環境下運行,小到最簡單的命令行應用,大到大型的企業應用以及集群應用。但是我們準備在快速指南中使用最最簡單的main方法的方式,讓你對Shiro的API有個感官的認識。

代碼片段和文件信息
package?com.taoge.shiro.authenticator.strategy;
import?java.util.Collection;
import?org.apache.shiro.authc.AuthenticationException;
import?org.apache.shiro.authc.AuthenticationInfo;
import?org.apache.shiro.authc.AuthenticationToken;
import?org.apache.shiro.authc.SimpleAuthenticationInfo;
import?org.apache.shiro.authc.pam.AbstractAuthenticationStrategy;
import?org.apache.shiro.realm.Realm;
import?org.apache.shiro.util.CollectionUtils;
/**
?*?Shiro框架學習demo
?*?業余草:www.xttblog.com
?*?QQ1群:135430763(已滿)
?*?QQ2群:454796847
?*?@author?濤哥
?*?@date?2016年8月8日14:46:10
?*/
public?class?AtLeastTwoAuthenticatorStrategy?extends?AbstractAuthenticationStrategy?{
????@Override
????public?AuthenticationInfo?beforeAllAttempts(Collection?extends?Realm>?realms?AuthenticationToken?token)?throws?AuthenticationException?{
????????return?new?SimpleAuthenticationInfo();//返回一個權限的認證信息
????}
????@Override
????public?AuthenticationInfo?beforeAttempt(Realm?realm?AuthenticationToken?token?AuthenticationInfo?aggregate)?throws?AuthenticationException?{
????????return?aggregate;//返回之前合并的
????}
????@Override
????public?AuthenticationInfo?afterAttempt(Realm?realm?AuthenticationToken?token?AuthenticationInfo?singleRealmInfo?AuthenticationInfo?aggregateInfo?Throwable?t)?throws?AuthenticationException?{
????????AuthenticationInfo?info;
????????if?(singleRealmInfo?==?null)?{
????????????info?=?aggregateInfo;
????????}?else?{
????????????if?(aggregateInfo?==?null)?{
????????????????info?=?singleRealmInfo;
????????????}?else?{
????????????????info?=?merge(singleRealmInfo?aggregateInfo);
????????????}
????????}
????????return?info;
????}
????@Override
????public?AuthenticationInfo?afterAllAttempts(AuthenticationToken?token?AuthenticationInfo?aggregate)?throws?AuthenticationException?{
????????if?(aggregate?==?null?||?CollectionUtils.isEmpty(aggregate.getPrincipals())?||?aggregate.getPrincipals().getRealmNames().size()?2)?{
????????????throw?new?AuthenticationException(“Authentication?token?of?type?[“?+?token.getClass()?+?“]?“?+
????????????????????“could?not?be?authenticated?by?any?configured?realms.??Please?ensure?that?at?least?two?realm?can?“?+
????????????????????“authenticate?these?tokens.“);
????????}
????????return?aggregate;
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-08-08?14:41??shiro-demo1\
?????文件????????1431??2016-08-08?14:13??shiro-demo1\.classpath
?????文件?????????563??2016-08-08?14:13??shiro-demo1\.project
?????目錄???????????0??2016-08-08?14:13??shiro-demo1\.settings\
?????文件??????????57??2016-08-08?14:13??shiro-demo1\.settings\org.eclipse.core.resources.prefs
?????文件?????????243??2016-08-08?14:13??shiro-demo1\.settings\org.eclipse.jdt.core.prefs
?????文件??????????90??2016-08-08?14:12??shiro-demo1\.settings\org.eclipse.m2e.core.prefs
?????目錄???????????0??2016-08-08?14:41??shiro-demo1\doc\
?????目錄???????????0??2016-08-08?14:43??shiro-demo1\doc\sql\
?????文件????????1980??2016-08-08?14:43??shiro-demo1\doc\sql\shiro.sql
?????文件????????1331??2016-08-08?17:14??shiro-demo1\pom.xm
?????目錄???????????0??2016-08-08?14:12??shiro-demo1\src\
?????目錄???????????0??2016-08-08?14:12??shiro-demo1\src\main\
?????目錄???????????0??2016-08-08?14:39??shiro-demo1\src\main\java\
?????目錄???????????0??2016-08-08?17:14??shiro-demo1\src\main\java\com\
?????目錄???????????0??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\
?????目錄???????????0??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\shiro\
?????目錄???????????0??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\shiro\authenticator\
?????目錄???????????0??2016-08-08?14:39??shiro-demo1\src\main\java\com\taoge\shiro\authenticator\strategy\
?????文件????????2333??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\shiro\authenticator\strategy\AtLeastTwoAuthenticatorStrategy.java
?????文件????????2317??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\shiro\authenticator\strategy\OnlyOneAuthenticatorStrategy.java
?????目錄???????????0??2016-08-08?14:52??shiro-demo1\src\main\java\com\taoge\shiro\realm\
?????文件????????2133??2016-08-08?17:14??shiro-demo1\src\main\java\com\taoge\shiro\realm\MyRealm.java
?????目錄???????????0??2016-08-08?15:23??shiro-demo1\src\main\resources\
?????文件?????????447??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-authenticator-all-fail.ini
?????文件?????????447??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-authenticator-all-success.ini
?????文件?????????500??2016-08-08?15:26??shiro-demo1\src\main\resources\shiro-authenticator-atLeastOne-success.ini
?????文件?????????472??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-authenticator-atLeastTwo-success.ini
?????文件?????????449??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-authenticator-first-success.ini
?????文件?????????523??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-authenticator-onlyone-success.ini
?????文件?????????319??2016-08-08?15:23??shiro-demo1\src\main\resources\shiro-jdbc-realm.ini
............此處省略53個文件信息
評論
共有 條評論