Commit fa17e543 authored by xc's avatar xc

shiro限定并发登录人数

parent 349a8611
......@@ -78,10 +78,12 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
logger.info("KickoutSessionControlFilter Not Login begin.......");
Subject subject = getSubject(request, response);
Map<String, Object> map = new HashMap<>();
// 没有登陆或没有设置“记住我”
if (!subject.isAuthenticated() && !subject.isRemembered()) {
logger.info("KickoutSessionControlFilter isAuthenticated and isRemembered return true .......");
return true;
}
Session session = subject.getSession();
......@@ -108,6 +110,7 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
userId = staff.getId();
}
}
logger.info("KickoutSessionControlFilter 如果被踢出了,直接退出,重定向到踢出后的地址-----");
//如果被踢出了,直接退出,重定向到踢出后的地址
if (session.getAttribute("kickout") != null) {
logger.info("------" + "踢出用户" + userId + "登录sessionId=" + sessionId + "------");
......@@ -123,6 +126,7 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
out(response, map);
return false;
}
logger.info("KickoutSessionControlFilter Not Login end.......");
return true;
}
......@@ -142,6 +146,7 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
public void changeSession(int type){
logger.info("KickoutSessionControlFilter changeSession begin.......type : "+type);
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
session.setTimeout(300000);
......@@ -183,6 +188,7 @@ public class KickoutSessionControlFilter extends AccessControlFilter{
}
// 更新redis中的用户登录队列
redisTemplate.opsForValue().set(getRedisKickoutKey(userId), deque, EXPIRE_TIME, TimeUnit.SECONDS);
logger.info("KickoutSessionControlFilter changeSession end.......");
}
String getRedisKickoutKey(Integer userId) {
......
......@@ -15,6 +15,7 @@ import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.crazycake.shiro.IRedisManager;
import org.crazycake.shiro.RedisCacheManager;
import org.crazycake.shiro.RedisManager;
......@@ -45,7 +46,7 @@ public class ShiroConfig {
@Value("${spring.redis.password}")
private String password;
//设置session会话过期时间为两小时
private static final Integer expireTime = 3600 * 2;
private static final Integer expireTime = 3600000 * 2;
/**
......@@ -175,9 +176,18 @@ public class ShiroConfig {
public MySessionManager sessionManager() {
MySessionManager mySessionManager = new MySessionManager();
mySessionManager.setSessionDAO(redisSessionDAO());
mySessionManager.setSessionIdCookie(simpleCookie());
return mySessionManager;
}
@Bean
public SimpleCookie simpleCookie(){
SimpleCookie simpleCookie = new SimpleCookie();
simpleCookie.setPath("/");
simpleCookie.setName("SHIROSESSION");
return simpleCookie;
}
/**
* 配置shiro redisManager
......
......@@ -3,10 +3,13 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.110.165:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
#url: jdbc:mysql://192.168.110.165:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
#url: jdbc:mysql://localhost:3306/volunteer?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
username: root
password: adm4HYservice$
url: jdbc:mysql://rm-bp1i44rtb091fk06coo.mysql.rds.aliyuncs.com:3306/volunteer?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
# username: root
# password: adm4HYservice$
username: alyxcroot
password: alyXCRoot123
initial-size: 10
max-active: 100
min-idle: 10
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment