From 28e6e75599173205673627f48e59d3d9cc8d5d13 Mon Sep 17 00:00:00 2001 From: wu xiangkai Date: Thu, 20 Oct 2022 18:15:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring/Apache Shiro/Apache Shiro.md | 10 ++++++++++ 1 file changed, 10 insertions(+) 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拦截, + +