1、Session的介绍

关于Session

会话:从启动一个Session到关闭这个Session作为一个会话,是对客户端和服务器端交互的一种封装,带有时效性

会话的产生:
  一般从容器中产生
    Web container:Web容器,如Tomcat,这些容器对Session进行了实现,可以产生Session
    EJB Stateful Session Beans:比较少用

会话的应用:
  Mobile
  Web
  分布式集群

Shiro Session

  基于POJO
  可以自定义Session存储的方式,保存到内存、文件、数据库都可以
  容器无关的集群
  客户端访问多样化
  事件监听
  主机地址记忆,可以知道由哪台主机创建
  Web使用透明化,不需要关心Session怎么创建,只需要知道如何使用
  支持SSO,单点登录

使用Session

Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession(true);
session.setAttribute("someKey", somValue);

  subject.getSession(flag)

    如果subject存在session,直接返回session
    如果subject不存在session,flag=true,则创建一个新的Ssssion并返回
    如果subject不存在session,flag=false,则返回null

  类似servlet中的Session

  支持所有应用,适合但不限于Web应用

2、SessionManager

DefaultSessionManager:默认实现

Session Timeout:Session的有效期

Session Listeners:面向事件、实现SessionListener接口

Session Storage:Session的保存形式

  SessionDAO接口抽象

  in-memory-only:默认,使用内存保存Session

  EHCache SessionDAO:使用磁盘保存Session的实现

  EhCache SessionDAO的使用

    配置ehcache.xml

    Session Cache Name

Session IDs

  SessionIdGenerator组件:用于生成SessionID

  JavaUuidSessionIdGenerator:默认实现,使用Java的uuid

  自定义

Session Validation

  判断Session是否过期

  Lazy Validation:使用的时候才判断

  Session孤儿(orphan):使用Lazy时,某些Session过期了,仍长期存在。

SessionValidationScheduler

  定期删除Session孤儿

  ExecutorServiceSessionValidationScheduler:默认实现

  自定义SessionValidationScheduler

  关闭Session Validation

  关闭Session删除功能

3、Session集群

用于实现Session的集群

Shiro支持分布式缓存

  Web容器环境

  Native环境

基于POJO多层架构

  支持集群的SessionDAO

  透明的SessionManager

支持集成多种分布式缓存服务器

EnterpriseCacheSessionDAO

  activeSessionsCache

第三方集成

  Ehcache+Terracotta

  Zookeeper

4、Session和用户状态

有状态的应用

  Shiro默认使用Session保存认证状态

  通过SessionId获取用户状态

无状态的应用

自定义混合方案

  SessionStorageEvaluator

【Shiro】六、Apache Shiro Session管理的更多相关文章

  1. 【Shiro】Apache Shiro架构之集成web

    Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shi ...

  2. 【Shiro】Apache Shiro架构之身份认证(Authentication)

    Shiro系列文章: [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shiro ...

  3. 【Shiro】Apache Shiro架构之自定义realm

    [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之权限认证(Authorization) [Shiro]Apache S ...

  4. 【Shiro】Apache Shiro架构之权限认证(Authorization)

    Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shir ...

  5. [转载] 【Shiro】Apache Shiro架构之实际运用(整合到Spring中)

    写在前面:前面陆陆续续对Shiro的使用做了一些总结,如题,这篇博文主要是总结一下如何将Shiro运用到实际项目中,也就是将Shiro整到Spring中进行开发.后来想想既然要整,就索性把Spring ...

  6. 细说shiro之六:session管理

    官网:https://shiro.apache.org/ 我们先来看一下shiro中关于Session和Session Manager的类图. 如上图所示,shiro自己定义了一个新的Session接 ...

  7. 让Apache Shiro保护你的应用

    在尝试保护你的应用时,你是否有过挫败感?是否觉得现有的Java安全解决方案难以使用,只会让你更糊涂?本文介绍的Apache Shiro,是一个不同寻常的Java安全框架,为保护应用提供了简单而强大的方 ...

  8. Apache Shiro 手册

    (一)Shiro架构介绍 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户"登录 ...

  9. Apache Shiro 使用手册---转载

    原文地址:http://www.360doc.com/content/12/0104/13/834950_177177202.shtml (一)Shiro架构介绍 一.什么是Shiro Apache ...

  10. Apache Shiro 使用手册

    http://kdboy.iteye.com/blog/1154644 (一)Shiro架构介绍 一.什么是Shiro  Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加 ...

随机推荐

  1. bzoj 2242: [SDOI2011]计算器 & BSGS算法笔记

    这题的主要难点在于第三问该如何解决 于是就要知道BSGS是怎样的一种方法了 首先BSGS是meet in the middle的一种(戳下面看) http://m.blog.csdn.net/blog ...

  2. 术语-Portal:Portal(Web站点)

    ylbtech-术语-Portal:Portal(Web站点) Portal作为网关服务于因特网的一种WEB站点.Portal是链路.内容和为用户可能找到的感兴趣的信息(如新闻.天气.娱乐.商业站点. ...

  3. javascript: 禁用右键、文本选择功能、复制按键

    <script type="text/javascript"> //禁用右键.文本选择功能.复制按键 //http://www.jinyuanbao.cn $(docu ...

  4. 13. Jmeter-定时器

    Jmeter-定时器介绍与使用 固定定时器 Uniform Random Timer Precise Throughput Timer Constant Throughput Timer 高斯随机定时 ...

  5. MSF——基本使用和Exploit模块(一)

    MSF系列: MSF——基本使用和Exploit模块(一) MSF——Payload模块(二) MSF——Meterpreter(三) MSF——信息收集(四) MSF——Metasploit Fra ...

  6. 好用的打包工具webpack

    <什么是webpack> webpack是一个模块打包器,任何静态资源(js.css.图片等)都可以视作模块,然后模块之间也可以相互依赖,通过webpack对模块进行处理后,可以打包成我们 ...

  7. k8s之ingress-nginx部署一直提示健康检查10254端口不通过问题就处理

    之前部署了一套k8s集群,但是到部署ingress-nginx的时候,一直提示10254端口拒绝不通:如下图. 这是因为我之前装的是docker1.17.默认的驱动是systemd.因为systemd ...

  8. cmd 编码格式

    相当于编辑器的声明为gbk格式编码,输出格式也是gbka = '中文' 就会以gbk编码为str,也只能以gbk解码. reload sys修改默认编码 在不指定编码的时候充当默认解码或者编码格式

  9. Python 读书

    第一章 %d %s %f 数字和表达式 加减乘取模都可以直接输入 除需注意: 1/2=0.5 1/2.0=0.5 --有浮点按浮点计算 1//2=0 --整除 1.0/2.0=0.5 1.0//2.0 ...

  10. 关于清除浮动的n中方式

    我们在对页面进行布局的时候经常会用到浮动布局,浮动布局能够很好的实现我们想要的布局效果,同时兼容方面也是很好的,但是当我们在用左右浮动进行页面布局的时候,由于元素浮动脱了了文档流导致浮动元素的父级高度 ...