diff --git a/spring/Apache Shiro/Apache Shiro.md b/spring/Apache Shiro/Apache Shiro.md index 7065b03..a3fb7a8 100644 --- a/spring/Apache Shiro/Apache Shiro.md +++ b/spring/Apache Shiro/Apache Shiro.md @@ -142,6 +142,16 @@ byte[] encrypted = cipherService.encrypt(fileBytes, testKey); ``` ## Shiro框架的Web支持 +### Web Session管理 +对于web应用,shiro默认情况下其session会使用已经存在的servlet容器session。当使用subject.getSession()或者subject.getSession(boolean)获取session实例时,**Shiro将会返回一个基于Servlet容器的HttpSession实例来作为Session实例返回值**。 +> 对于Shiro来说,其业务层代码通过subject.getSession来获取Shiro Session实例,即使当前运行于Servlet容器,业务层代码在与Shiro Session交互时也不知道与其交互的是HttpSession。 +> 故而在使用Shiro Session时,其Session是独立与环境的,Web应用和非Web应用都可以通过相同的Shiro Session API与Shiro Session进行交互,而Shiro Session是否是基于Servlet容器的HttpSession,用户是无感知的。 + +### Shiro Native Session +当启用Shiro Native Session之后,对于Web应用,如果想使用Shiro Session来代替基于Servlet容器的HttpSession,无需修改HttpServletRequest.getSession()和HttpSession API为Shiro Session API。 +Shiro Session完全实现了Servlet Session的标准,以此支持Shiro Session在Web应用中的使用。在使用了Shiro Native Session后,任何对HttpServletRequest和HttpSession API的调用都会被Shiro拦截, + +