|
@@ -2,13 +2,20 @@ package org.jeecg.config.shiro;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
|
|
+import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
|
|
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
|
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
|
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
|
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
|
|
|
+import org.apache.shiro.mgt.RememberMeManager;
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
|
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
|
|
+import org.apache.shiro.web.mgt.CookieRememberMeManager;
|
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
|
|
|
+import org.apache.shiro.web.servlet.Cookie;
|
|
|
|
+import org.apache.shiro.web.servlet.SimpleCookie;
|
|
|
|
+import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
|
|
|
+import org.apache.shiro.web.session.mgt.WebSessionManager;
|
|
import org.crazycake.shiro.IRedisManager;
|
|
import org.crazycake.shiro.IRedisManager;
|
|
import org.crazycake.shiro.RedisCacheManager;
|
|
import org.crazycake.shiro.RedisCacheManager;
|
|
import org.crazycake.shiro.RedisClusterManager;
|
|
import org.crazycake.shiro.RedisClusterManager;
|
|
@@ -50,6 +57,23 @@ public class ShiroConfig {
|
|
@Resource
|
|
@Resource
|
|
private JeecgBaseConfig jeecgBaseConfig;
|
|
private JeecgBaseConfig jeecgBaseConfig;
|
|
|
|
|
|
|
|
+ // 配置 RememberMeManager
|
|
|
|
+ @Bean
|
|
|
|
+ public RememberMeManager rememberMeManager() {
|
|
|
|
+ CookieRememberMeManager rememberMeManager = new CookieRememberMeManager();
|
|
|
|
+ rememberMeManager.setCookie(rememberMeCookie()); // 配置 RememberMeCookie
|
|
|
|
+ return rememberMeManager;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 配置 RememberMeCookie
|
|
|
|
+ @Bean
|
|
|
|
+ public SimpleCookie rememberMeCookie() {
|
|
|
|
+ SimpleCookie rememberMeCookie = new SimpleCookie("rememberMe");
|
|
|
|
+ rememberMeCookie.setMaxAge(30 * 24 * 60 * 60); // 设置最大有效期为 30 天
|
|
|
|
+ rememberMeCookie.setHttpOnly(true); // 设置为 HttpOnly
|
|
|
|
+ return rememberMeCookie;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Filter Chain定义说明
|
|
* Filter Chain定义说明
|
|
*
|
|
*
|
|
@@ -177,6 +201,7 @@ public class ShiroConfig {
|
|
* http://shiro.apache.org/session-management.html#SessionManagement-
|
|
* http://shiro.apache.org/session-management.html#SessionManagement-
|
|
* StatelessApplications%28Sessionless%29
|
|
* StatelessApplications%28Sessionless%29
|
|
*/
|
|
*/
|
|
|
|
+ securityManager.setRememberMeManager(rememberMeManager());
|
|
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
|
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
|
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
|
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
|
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
|
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|