Shiro 设置session超时时间
通过api:Shiro的Session接口有一个setTimeout()方法
//登录后,可以用如下方式取得session
SecurityUtils.getSubject().getSession().setTimeout(30000);
查看Shiro的api文档,
setTimeout
void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionExceptionSets the time in milliseconds that the session may remain idle before expiring.A negative value means the session will never expire.A non-negative value (0 or greater) means the session
expiration will occur if idle for that length of time.*Note: if you are used to the HttpSession's getMaxInactiveInterval() method, the scale on this method is different: Shiro Sessions use millisecond values for timeout whereas HttpSession.getMaxInactiveInterval
uses seconds. Always use millisecond values with Shiro sessions.Parameters:maxIdleTimeInMillis - the time in milliseconds that the session may remain idle before expiring.Throws:InvalidSessionException - if the session has been stopped or expired prior to
calling this method.Since:0.2
设置的最大时间,正负都可以,为负数时表示永不超时。开发过程中,设置负数时,遇到点儿问题:
SecurityUtils.getSubject().getSession().setTimeout(-1l);
这样调用后,总是抛出session已经过时的异常,一直找不到原因,后来调试源码才发现,这里设置的时间单位是:ms,但是Shiro会把这个时间转成:s,而且是会舍掉小数部分,这样我设置的是-1ms,转成s后就是0s,马上就过期了,所以后面再对这个会话进行操作时,总会抛异常,正确的设置永不超时的方式应该是:
// timeout:-1000ms 永不超时
SecurityUtils.getSubject().getSession().setTimeout(-1000l);
Shiro 设置session超时时间的更多相关文章
- shiro设置session超时时间
系统默认超时时间是180000毫秒(30分钟) long timeout = SecurityUtils.getSubject().getSession().getTimeout(); System. ...
- WebLogic如何设置session超时时间
1.web.xml 设置WEB应用程序描述符web.xml里的<session-timeout>元素.这个值以分钟为单位,并覆盖weblogic.xml中的TimeoutSecs属性 ...
- shiro设置session超时
通过api:Shiro的Session接口有一个setTimeout()方法 //登录后,可以用如下方式取得session SecurityUtils.getSubject().getSession( ...
- 【python】Django设置SESSION超时时间没有生效?
按手册和网上的方法在settings.py中设置“SESSION_COOKIE_AGE” 和 “SESSION_EXPIRE_AT_BROWSER_CLOSE” 均不生效. 通过查看django的源代 ...
- Springboot设置session超时时间
按优先级高到低说: 第一种: spring boot 启动类里面: package com.mycenter; import org.mybatis.spring.annotation.MapperS ...
- Spring Boot 应用使用spring session+redis启用分布式session后,如何在配置文件里设置应用的cookiename、session超时时间、redis存储的namespace
现状 项目在使用Spring Cloud搭建微服务框架,其中分布式session采用spring session+redis 模式 需求 希望可以在配置文件(application.yml)里设置应用 ...
- springboot设置session超时和session监听
2.0版本以下设置session超时时间 1. springboot 2.0版本以下配置session超时 1.1 application.properties配置文件: spring.sessio ...
- Javaweb设置session过期时间
在Java Web开发中,Session为我们提供了很多方便,Session是由浏览器和服务器之间维护的.Session超时理解为:浏览器和服务器之间创建了一个Session,由于客户端长时间(休眠时 ...
- Spring Boot Session 超时时间
springboot session https://www.jianshu.com/p/523572937db8 springboot2以上版本设置session超时时间 https://blog. ...
随机推荐
- 51Nod 1256 求乘法逆元--扩展欧几里德
#include<stdio.h> int exgcd(int a,int b,int &x,int &y) { ) { x=; y=; return a; } int r ...
- 2017南宁现场赛E The Champion
Bob is attending a chess competition. Now the competition is in the knockout phase. There are 2^r2r ...
- codeforces B. Okabe and Banana Trees 结论题
题目传送门 这道题 枚举一波y就好了 要求x,y整数 所以y最多1000个 然后算一波答案更新就好了 233 #include<cstdio> #include<cstring> ...
- codevs1063 合并果子 优先队列(小根堆)
题目传送门 这道题很容易想到优先把两堆重量最小的合并比较优 然后乱搞一下就可以啦 #include<cstdio> #include<cstring> #include< ...
- [POJ1144][BZOJ2730]tarjan求割点
求割点 一种显然的n^2做法: 枚举每个点,去掉该点连出的边,然后判断整个图是否联通 用tarjan求割点: 分情况讨论 如果是root的话,其为割点当且仅当下方有两棵及以上的子树 其他情况 设当前节 ...
- Linux 工作站安全加固规范
目标受众 这是一套 Linux 基金会为其系统管理员提供的推荐规范. 这个文档用于帮助那些使用 Linux 工作站来访问和管理项目的 IT 设施的系统管理员团队. 如果你的系统管理员是远程员工,你也许 ...
- 转:Android 的一些比较好的开源代码项目
转自:http://blog.csdn.net/zengyangtech/article/details/7019439 Android PDF 阅读器 http://sourceforge.net/ ...
- Hadoop安装过程
1.安装JDK apt-get install openjdk-7-jdk 2.配置环境变量 vim /etc/profile 编辑: export JAVA_HOME=/usr/lib/jvm/ja ...
- Google开源命令行参数解析库gflags
Google开源命令行参数解析库gflags http://blog.csdn.net/lming_08/article/details/25072899 CMDLINE的解析 http://blog ...
- oracle 一行转多行
比如sql: select zyxdm from table where bindid=2265254 查询结果为:1|4|8|9|10 将这个查询结果转成多行,结果如下: ID 1 4 8 9 10 ...