您好,登錄后才能下訂單哦!
這篇文章主要講解了“Shiro核心類有哪些”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Shiro核心類有哪些”吧!
一:SessionManager
1.簡(jiǎn)介
Shiro提供了完整的會(huì)話管理功能,不依賴底層容器,JavaSE應(yīng)用和JavaEE應(yīng)用都可以使用。
SessionManager管理著應(yīng)用中所有Subject的會(huì)話,包括會(huì)話的創(chuàng)建,維護(hù),刪除,失效,驗(yàn)證等工作。
2.SessionManager接口
Session start(SessionContext context); 基于指定的上下文初始化數(shù)據(jù)啟動(dòng)新會(huì)話
Session getSession(SessionKey key) throws SessionException;
根據(jù)指定的SessionKey檢索會(huì)話,如果找不到則返回null。如果找到了會(huì)話,但會(huì)話但無(wú)效(已停止或已過(guò)期)則拋出SessionException異常。
3.AbstractSessionManager implements SessionManager
public void setGlobalSessionTimeout(long globalSessionTimeout)
設(shè)置全局Session的超時(shí)時(shí)間,默認(rèn)為30分鐘。設(shè)置為負(fù)數(shù)表示永遠(yuǎn)都不超時(shí)。
4.AbstractValidatingSessionManager extends AbstractNativeSessionManager
protected boolean sessionValidationSchedulerEnabled;
是否進(jìn)行Session驗(yàn)證
protected long sessionValidationInterval;
Session驗(yàn)證的時(shí)間間隔,默認(rèn)為一小時(shí)
5.public class DefaultSessionManager extends AbstractValidatingSessionManager
private boolean deleteInvalidSessions;
是否刪除無(wú)效的Session
6.public class DefaultWebSessionManager extends DefaultSessionManager
private boolean sessionIdCookieEnabled;
是否從Cookie中獲取sessionId
private boolean sessionIdUrlRewritingEnabled;
二:AuthenticationToken
AuthenticationToken 用于收集用戶提交的身份(如用戶名)及憑據(jù)(如密碼)。Shiro會(huì)調(diào)用CredentialsMatcher對(duì)象的
doCredentialsMatch方法對(duì)AuthenticationInfo對(duì)象和AuthenticationToken進(jìn)行匹配。匹配成功則表示主體(Subject)認(rèn)證成功,否則表示認(rèn)證失敗。
一般情況下UsernamePasswordToken已經(jīng)可以滿足我們的大我數(shù)需求。當(dāng)我們遇到需要聲明自己的Token類時(shí),可以根據(jù)需求來(lái)實(shí)現(xiàn)AuthenticationToken,
HostAuthenticationToken或RememberMeAuthenticationToken。
三:Realm
Realm是安全驗(yàn)證數(shù)據(jù)的數(shù)據(jù)源。
1.public interface Realm
String getName();
boolean supports(AuthenticationToken token);
AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException;
四:Subject與SubjectFactory
1.public interface Subject
一個(gè)Subject代表著應(yīng)用的一個(gè)用戶。
Object getPrincipal();
Subject的唯一標(biāo)識(shí),比如用戶名,用戶ID,手機(jī)號(hào)等
PrincipalCollection getPrincipals();
boolean isPermitted(String permission);
boolean isPermitted(Permission permission);
boolean[] isPermitted(String... permissions);
boolean[] isPermitted(List<Permission> permissions);
void checkPermission(String permission) throws AuthorizationException;
void checkRole(String roleIdentifier) throws AuthorizationException;
void login(AuthenticationToken token) throws AuthenticationException;
boolean isAuthenticated();
boolean isRemembered();
2.public interface WebSubject extends Subject, RequestPairSource
ServletRequest getServletRequest();
ServletResponse getServletResponse();
3.public class DelegatingSubject implements Subject
protected PrincipalCollection principals;
protected boolean authenticated;
protected String host;
protected Session session;
protected boolean sessionCreationEnabled;
protected transient SecurityManager securityManager;
4.public class WebDelegatingSubject extends DelegatingSubject implements WebSubject
5.public interface SubjectContext extends Map<String, Object>
SubjectContext 將構(gòu)建Subject的所有屬性都組織到一起,然后傳遞給一個(gè)SubjectFactory,用于構(gòu)成一個(gè)Subject.
6.public interface SubjectFactory
Subject createSubject(SubjectContext context);
創(chuàng)建Subject
7.public class DefaultSubjectFactory implements SubjectFactory
8.public class DefaultWebSubjectFactory extends DefaultSubjectFactory
五:SecurityManager
1.public interface SecurityManager extends Authenticator, Authorizer, SessionManager
Subject login(Subject subject, AuthenticationToken authenticationToken) throws AuthenticationException;
登錄
void logout(Subject subject);
登出
Subject createSubject(SubjectContext context);
2.public abstract class CachingSecurityManager implements SecurityManager, Destroyable, CacheManagerAware, EventBusAware
private CacheManager cacheManager;
private EventBus eventBus;
3.public abstract class RealmSecurityManager extends CachingSecurityManager
private Collection<Realm> realms;
權(quán)限集合realms
4.public abstract class AuthenticatingSecurityManager extends RealmSecurityManager
private Authenticator authenticator;
SecurityManager用于身份驗(yàn)證操作的具體實(shí)例
5.public abstract class AuthorizingSecurityManager extends AuthenticatingSecurityManager
private Authorizer authorizer;
SecurityManager用于授權(quán)操作的具體實(shí)例
6.public abstract class SessionsSecurityManager extends AuthorizingSecurityManager
private SessionManager sessionManager;
SecurityManager用于管理所有Session的具體實(shí)例。
7.public class DefaultSecurityManager extends SessionsSecurityManager
protected RememberMeManager rememberMeManager;
記著引用中與當(dāng)前Subject關(guān)聯(lián)的Seeion,免重新登錄
protected SubjectDAO subjectDAO;
Subject的持久化存儲(chǔ)
protected SubjectFactory subjectFactory;
創(chuàng)建應(yīng)用Subject的工廠
8.public class DefaultWebSecurityManager extends DefaultSecurityManager implements WebSecurityManager
boolean isHttpSessionMode();
是否使用Servlet 容器的HttpSession
感謝各位的閱讀,以上就是“Shiro核心類有哪些”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Shiro核心類有哪些這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。