Shiro 源码阅读笔记

> 一 securityManager : 安全管理器 ,shiro 核心接口 ,用于提供安全管理的各种服务

------ > Subject login(Subject var1, AuthenticationToken var2)
------ > void logout(Subject var1);
------ > Subject createSubject(SubjectContext var1);
------ ? ------ 不多分析,名字就看得出来

> 二 WebSecurityManager : 接口 , 继承自SecurityManager

------ > boolean isHttpSessionMode();

> 三 UsernamePasswordToken : 实现 HostAuthenticationToken, RememberMeAuthenticationToken
> 四 SecurityUtils : shiro 工具类

------ > 1 SecurityManager securityManager; === 静态对象
------ > 2 setSecurityManager(SecurityManager securityManager) :=== 返回静态对象
------ > 3 SecurityManager getSecurityManager()
------ > ------ > 3.1 ThreadContext.getSecurityManager(); === 先从 context 中获得securityManager
------ > ------ > 3.2 获得为 null 则 获取静态
------ > ------ > 3.3 静态也为 null 则抛出异常 , 否则返回 securityManager
------ > 4 Subject getSubject() === 获得subject
------ > ------ > 4.1 ThreadContext.getSubject() ===context 中获得 subject
------ > ------ > 4.2 subject = (new Builder()).buildSubject(); === 如果为 null 则 构建新的 subject
------ > ------ > 4.3 ThreadContext.bind(subject); === 写入环境中 ,便于下次直接获取

> 五 Session

------- > Serializable getId(); === 获得 session 唯一ID
------- > Date getStartTimestamp(); === 获得开始时间
------- > Date getLastAccessTime(); === 获得最后许可时间
------- > long getTimeout() throws InvalidSessionException; === 获得过期时间
------- > void setTimeout(long var1) throws InvalidSessionException; === 设置过期时间
------- > String getHost(); === 获得Host
------- > void touch() throws InvalidSessionException; === 更新
------- > void stop() throws InvalidSessionException; === 停止会话
------- > Collection getAttributeKeys() throws InvalidSessionException; === 获得session域数据集合
------- > Object getAttribute(Object var1) throws InvalidSessionException; === 获得某个Session 域数据
------- > void setAttribute(Object var1, Object var2) throws InvalidSessionException; === 设置某个Session 域数据
------- > Object removeAttribute(Object var1) throws InvalidSessionException; === 移除某个Session 域数据

> 六 SimpleSession 继承 ValidatingSession 继承自 Session

------- > 包含上述方法的简单实现 ,以及以下新的方法
------- > isStopped ( ) === 是否关闭
------- > isValid ( ) === 是否有效
------- > isTimedOut ( ) === 是否过期 ( 其中获取的是系统时间戳,对比过期时间和最后时间 )
------- > validate ( ) === 先判断是否停止 ,已停止则直接抛出异常 , 再返回合法的时间段
------- > getAttributesLazy ( ) === 特点在于不存在会创建新的 HashMap 返回
------- > getAttributeKeys ( ) === 获得 keys
------- > getAttribute(Object key) / setAttribute(Object key, Object value) / removeAttribute(Object key)
------- > equals( Object obj ) / onEquals(SimpleSession ss) === 对比不多说
------- > hashCode() / toString() / writeObject(ObjectOutputStream out) === 后面不常用的不说了

> 七 DelegatingSession : 委托实现方式 ,均委托给 SessionManager 接口

------- > NativeSessionManager sessionManager; === 核心属性 , 委托给 NativeSessionManager

> 八 SessionManager :管理 Session ( 创建 ,操作 ,删除 )

------- > Session start(SessionContext var1); === 根据 Context 信息 开始Session
------- > Session getSession(SessionKey var1) throws SessionException; === 通过SessionKey查找Session

> 九 NativeSessionManager :

------- > Date getStartTimestamp(SessionKey var1); === 获得开始时间戳
------- > Date getLastAccessTime(SessionKey var1);
------- > boolean isValid(SessionKey var1); === 判断Session是否有效
------- > void checkValid(SessionKey var1) throws InvalidSessionException; === 检测Session是否有效,如果无效则抛出异常
------- > long getTimeout(SessionKey var1) throws InvalidSessionException; === 获得过期时间,负数不会过期
------- > void setTimeout(SessionKey var1, long var2) throws InvalidSessionException;
------- > void touch(SessionKey var1) throws InvalidSessionException; === 刷新
------- > String getHost(SessionKey var1);
------- > void stop(SessionKey var1) throws InvalidSessionException;
------- > Collection getAttributeKeys(SessionKey var1);
------- > Object getAttribute(SessionKey var1, Object var2) throws InvalidSessionException;
------- > void setAttribute(SessionKey var1, Object var2, Object var3) throws InvalidSessionException;
------- > Object removeAttribute(SessionKey var1, Object var2) throws InvalidSessionException;

> AbstractSessionManager :实现SessionManager ,包含了基础的时间规约

------- > globalSessionTimeout = 1800000L; === 核心

> AbstractNativeSessionManager
> 十 SessionContext : Session创建时的上下文参数

------- > void setHost(String var1); === 设置 Host
------- > String getHost(); === 获取 Host
------- > Serializable getSessionId(); === 获取Session ID
------- > void setSessionId(Serializable var1); === 设置Session ID

> 十一 DefaultSessionContext : 继承自 SessionContext
> 十二 DefaultWebSessionContext : 继承自 SessionContext

//后续完善中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值