|
@@ -1,49 +1,39 @@
|
|
|
package com.xingxi.framework.config;
|
|
package com.xingxi.framework.config;
|
|
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import javax.servlet.Filter;
|
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
|
-import org.apache.shiro.cache.ehcache.EhCacheManager;
|
|
|
|
|
|
|
+import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
|
|
|
|
+import com.xingxi.common.constant.Constants;
|
|
|
|
|
+import com.xingxi.common.utils.StringUtils;
|
|
|
|
|
+import com.xingxi.common.utils.security.CipherUtils;
|
|
|
|
|
+import com.xingxi.framework.shiro.realm.UserRealm;
|
|
|
|
|
+import com.xingxi.framework.shiro.web.CustomShiroFilterFactoryBean;
|
|
|
|
|
+import com.xingxi.framework.shiro.web.filter.LogoutFilter;
|
|
|
|
|
+import com.xingxi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
|
|
|
|
|
+import com.xingxi.framework.shiro.web.filter.kickout.KickoutSessionFilter;
|
|
|
import org.apache.shiro.codec.Base64;
|
|
import org.apache.shiro.codec.Base64;
|
|
|
-import org.apache.shiro.config.ConfigurationException;
|
|
|
|
|
-import org.apache.shiro.io.ResourceUtils;
|
|
|
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
|
|
|
+import org.apache.shiro.session.mgt.SessionManager;
|
|
|
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.SimpleCookie;
|
|
import org.apache.shiro.web.servlet.SimpleCookie;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
|
|
+import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
|
|
|
|
+import org.crazycake.shiro.RedisCacheManager;
|
|
|
|
|
+import org.crazycake.shiro.RedisManager;
|
|
|
|
|
+import org.crazycake.shiro.RedisSessionDAO;
|
|
|
|
|
+import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import com.xingxi.common.constant.Constants;
|
|
|
|
|
-import com.xingxi.common.utils.StringUtils;
|
|
|
|
|
-import com.xingxi.common.utils.security.CipherUtils;
|
|
|
|
|
-import com.xingxi.common.utils.spring.SpringUtils;
|
|
|
|
|
-import com.xingxi.framework.config.properties.PermitAllUrlProperties;
|
|
|
|
|
-import com.xingxi.framework.shiro.realm.UserRealm;
|
|
|
|
|
-import com.xingxi.framework.shiro.rememberMe.CustomCookieRememberMeManager;
|
|
|
|
|
-import com.xingxi.framework.shiro.session.OnlineSessionDAO;
|
|
|
|
|
-import com.xingxi.framework.shiro.session.OnlineSessionFactory;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.CustomShiroFilterFactoryBean;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.filter.LogoutFilter;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.filter.kickout.KickoutSessionFilter;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.filter.online.OnlineSessionFilter;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.session.OnlineWebSessionManager;
|
|
|
|
|
-import com.xingxi.framework.shiro.web.session.SpringSessionValidationScheduler;
|
|
|
|
|
-import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
|
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.Filter;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 权限配置加载
|
|
* 权限配置加载
|
|
|
- *
|
|
|
|
|
- * @author ruoyi
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author biandan
|
|
|
*/
|
|
*/
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class ShiroConfig
|
|
public class ShiroConfig
|
|
@@ -133,105 +123,150 @@ public class ShiroConfig
|
|
|
private boolean rememberMe;
|
|
private boolean rememberMe;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 缓存管理器 使用Ehcache实现
|
|
|
|
|
|
|
+ * redis缓存地址
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${spring.redis.port}")
|
|
|
|
|
+ private String redisPort;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * redis缓存端口
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${spring.redis.host}")
|
|
|
|
|
+ private String redisHost;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * redis数据库索引
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${spring.redis.database}")
|
|
|
|
|
+ private int database;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * redis密码
|
|
|
|
|
+ */
|
|
|
|
|
+ @Value("${spring.redis.password}")
|
|
|
|
|
+ private String password;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Cache Manager (shiro-redis)
|
|
|
*/
|
|
*/
|
|
|
@Bean
|
|
@Bean
|
|
|
- public EhCacheManager getEhCacheManager()
|
|
|
|
|
|
|
+ public RedisCacheManager redisCacheManager()
|
|
|
{
|
|
{
|
|
|
- net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("ruoyi");
|
|
|
|
|
- EhCacheManager em = new EhCacheManager();
|
|
|
|
|
- if (StringUtils.isNull(cacheManager))
|
|
|
|
|
- {
|
|
|
|
|
- em.setCacheManager(new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream()));
|
|
|
|
|
- return em;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- em.setCacheManager(cacheManager);
|
|
|
|
|
- return em;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ RedisCacheManager redisCacheManager = new RedisCacheManager();
|
|
|
|
|
+ redisCacheManager.setRedisManager(redisManager());
|
|
|
|
|
+ redisCacheManager.setPrincipalIdFieldName("userId");
|
|
|
|
|
+ return redisCacheManager;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
|
|
|
|
|
|
|
+ * RedisManager (shiro-redis)
|
|
|
*/
|
|
*/
|
|
|
- protected InputStream getCacheManagerConfigFileInputStream()
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public RedisManager redisManager()
|
|
|
{
|
|
{
|
|
|
- String configFile = "classpath:ehcache/ehcache-shiro.xml";
|
|
|
|
|
- InputStream inputStream = null;
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- inputStream = ResourceUtils.getInputStreamForPath(configFile);
|
|
|
|
|
- byte[] b = IOUtils.toByteArray(inputStream);
|
|
|
|
|
- InputStream in = new ByteArrayInputStream(b);
|
|
|
|
|
- return in;
|
|
|
|
|
- }
|
|
|
|
|
- catch (IOException e)
|
|
|
|
|
- {
|
|
|
|
|
- throw new ConfigurationException(
|
|
|
|
|
- "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
|
|
|
|
|
- }
|
|
|
|
|
- finally
|
|
|
|
|
|
|
+ RedisManager redisManager = new RedisManager();
|
|
|
|
|
+ redisManager.setHost(redisHost + ":" + redisPort);
|
|
|
|
|
+ redisManager.setDatabase(database);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(password))
|
|
|
{
|
|
{
|
|
|
- IOUtils.closeQuietly(inputStream);
|
|
|
|
|
|
|
+ redisManager.setPassword(password);
|
|
|
}
|
|
}
|
|
|
|
|
+ redisManager.setTimeout(expireTime * 60);
|
|
|
|
|
+ return redisManager;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 缓存管理器 使用Ehcache实现
|
|
|
|
|
+// */
|
|
|
|
|
+// @Bean
|
|
|
|
|
+// public EhCacheManager getEhCacheManager() {
|
|
|
|
|
+// net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("biandan");
|
|
|
|
|
+// EhCacheManager em = new EhCacheManager();
|
|
|
|
|
+// if (StringUtils.isNull(cacheManager)) {
|
|
|
|
|
+// em.setCacheManager(new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream()));
|
|
|
|
|
+// return em;
|
|
|
|
|
+// } else {
|
|
|
|
|
+// em.setCacheManager(cacheManager);
|
|
|
|
|
+// return em;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
|
|
|
|
|
+// */
|
|
|
|
|
+// protected InputStream getCacheManagerConfigFileInputStream() {
|
|
|
|
|
+// String configFile = "classpath:ehcache/ehcache-shiro.xml";
|
|
|
|
|
+// InputStream inputStream = null;
|
|
|
|
|
+// try {
|
|
|
|
|
+// inputStream = ResourceUtils.getInputStreamForPath(configFile);
|
|
|
|
|
+// byte[] b = IOUtils.toByteArray(inputStream);
|
|
|
|
|
+// InputStream in = new ByteArrayInputStream(b);
|
|
|
|
|
+// return in;
|
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
|
+// throw new ConfigurationException(
|
|
|
|
|
+// "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
|
|
|
|
|
+// } finally {
|
|
|
|
|
+// IOUtils.closeQuietly(inputStream);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 自定义Realm
|
|
* 自定义Realm
|
|
|
*/
|
|
*/
|
|
|
@Bean
|
|
@Bean
|
|
|
- public UserRealm userRealm(EhCacheManager cacheManager)
|
|
|
|
|
|
|
+ public UserRealm userRealm()
|
|
|
{
|
|
{
|
|
|
UserRealm userRealm = new UserRealm();
|
|
UserRealm userRealm = new UserRealm();
|
|
|
userRealm.setAuthorizationCacheName(Constants.SYS_AUTH_CACHE);
|
|
userRealm.setAuthorizationCacheName(Constants.SYS_AUTH_CACHE);
|
|
|
- userRealm.setCacheManager(cacheManager);
|
|
|
|
|
|
|
+ userRealm.setCacheManager(redisCacheManager());
|
|
|
return userRealm;
|
|
return userRealm;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 自定义sessionDAO会话
|
|
|
|
|
|
|
+ * RedisSessionDAO (shiro-redis)
|
|
|
*/
|
|
*/
|
|
|
@Bean
|
|
@Bean
|
|
|
- public OnlineSessionDAO sessionDAO()
|
|
|
|
|
|
|
+ public RedisSessionDAO redisSessionDAO()
|
|
|
{
|
|
{
|
|
|
- OnlineSessionDAO sessionDAO = new OnlineSessionDAO();
|
|
|
|
|
- return sessionDAO;
|
|
|
|
|
|
|
+ RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
|
|
|
|
|
+ redisSessionDAO.setRedisManager(redisManager());
|
|
|
|
|
+ redisSessionDAO.setExpire(expireTime * 60);
|
|
|
|
|
+ return redisSessionDAO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 自定义sessionFactory会话
|
|
|
|
|
- */
|
|
|
|
|
- @Bean
|
|
|
|
|
- public OnlineSessionFactory sessionFactory()
|
|
|
|
|
- {
|
|
|
|
|
- OnlineSessionFactory sessionFactory = new OnlineSessionFactory();
|
|
|
|
|
- return sessionFactory;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 自定义sessionDAO会话
|
|
|
|
|
+// */
|
|
|
|
|
+// @Bean
|
|
|
|
|
+// public OnlineSessionDAO sessionDAO() {
|
|
|
|
|
+// OnlineSessionDAO sessionDAO = new OnlineSessionDAO();
|
|
|
|
|
+// return sessionDAO;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 自定义sessionFactory会话
|
|
|
|
|
+// */
|
|
|
|
|
+// @Bean
|
|
|
|
|
+// public OnlineSessionFactory sessionFactory() {
|
|
|
|
|
+// OnlineSessionFactory sessionFactory = new OnlineSessionFactory();
|
|
|
|
|
+// return sessionFactory;
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 会话管理器
|
|
* 会话管理器
|
|
|
*/
|
|
*/
|
|
|
@Bean
|
|
@Bean
|
|
|
- public OnlineWebSessionManager sessionManager()
|
|
|
|
|
|
|
+ public SessionManager sessionManager()
|
|
|
{
|
|
{
|
|
|
- OnlineWebSessionManager manager = new OnlineWebSessionManager();
|
|
|
|
|
|
|
+ DefaultWebSessionManager manager = new DefaultWebSessionManager();
|
|
|
// 加入缓存管理器
|
|
// 加入缓存管理器
|
|
|
- manager.setCacheManager(getEhCacheManager());
|
|
|
|
|
- // 删除过期的session
|
|
|
|
|
- manager.setDeleteInvalidSessions(true);
|
|
|
|
|
- // 设置全局session超时时间
|
|
|
|
|
- manager.setGlobalSessionTimeout(expireTime * 60 * 1000);
|
|
|
|
|
|
|
+ manager.setCacheManager(redisCacheManager());
|
|
|
// 去掉 JSESSIONID
|
|
// 去掉 JSESSIONID
|
|
|
manager.setSessionIdUrlRewritingEnabled(false);
|
|
manager.setSessionIdUrlRewritingEnabled(false);
|
|
|
- // 定义要使用的无效的Session定时调度器
|
|
|
|
|
- manager.setSessionValidationScheduler(SpringUtils.getBean(SpringSessionValidationScheduler.class));
|
|
|
|
|
- // 是否定时检查session
|
|
|
|
|
- manager.setSessionValidationSchedulerEnabled(true);
|
|
|
|
|
// 自定义SessionDao
|
|
// 自定义SessionDao
|
|
|
- manager.setSessionDAO(sessionDAO());
|
|
|
|
|
- // 自定义sessionFactory
|
|
|
|
|
- manager.setSessionFactory(sessionFactory());
|
|
|
|
|
|
|
+ manager.setSessionDAO(redisSessionDAO());
|
|
|
|
|
+ // 设置全局session超时时间
|
|
|
|
|
+ manager.setGlobalSessionTimeout(expireTime * 60 * 1000);
|
|
|
return manager;
|
|
return manager;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -247,7 +282,7 @@ public class ShiroConfig
|
|
|
// 记住我
|
|
// 记住我
|
|
|
securityManager.setRememberMeManager(rememberMe ? rememberMeManager() : null);
|
|
securityManager.setRememberMeManager(rememberMe ? rememberMeManager() : null);
|
|
|
// 注入缓存管理器;
|
|
// 注入缓存管理器;
|
|
|
- securityManager.setCacheManager(getEhCacheManager());
|
|
|
|
|
|
|
+ securityManager.setCacheManager(redisCacheManager());
|
|
|
// session管理器
|
|
// session管理器
|
|
|
securityManager.setSessionManager(sessionManager());
|
|
securityManager.setSessionManager(sessionManager());
|
|
|
return securityManager;
|
|
return securityManager;
|
|
@@ -260,6 +295,7 @@ public class ShiroConfig
|
|
|
{
|
|
{
|
|
|
LogoutFilter logoutFilter = new LogoutFilter();
|
|
LogoutFilter logoutFilter = new LogoutFilter();
|
|
|
logoutFilter.setLoginUrl(loginUrl);
|
|
logoutFilter.setLoginUrl(loginUrl);
|
|
|
|
|
+ logoutFilter.setCacheManager(redisCacheManager());
|
|
|
return logoutFilter;
|
|
return logoutFilter;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -280,22 +316,19 @@ public class ShiroConfig
|
|
|
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
|
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
|
|
// 对静态资源设置匿名访问
|
|
// 对静态资源设置匿名访问
|
|
|
filterChainDefinitionMap.put("/favicon.ico**", "anon");
|
|
filterChainDefinitionMap.put("/favicon.ico**", "anon");
|
|
|
- filterChainDefinitionMap.put("/ruoyi.png**", "anon");
|
|
|
|
|
|
|
+ filterChainDefinitionMap.put("/biandan.png**", "anon");
|
|
|
|
|
+ filterChainDefinitionMap.put("/beian.png**", "anon");
|
|
|
filterChainDefinitionMap.put("/html/**", "anon");
|
|
filterChainDefinitionMap.put("/html/**", "anon");
|
|
|
filterChainDefinitionMap.put("/css/**", "anon");
|
|
filterChainDefinitionMap.put("/css/**", "anon");
|
|
|
filterChainDefinitionMap.put("/docs/**", "anon");
|
|
filterChainDefinitionMap.put("/docs/**", "anon");
|
|
|
filterChainDefinitionMap.put("/fonts/**", "anon");
|
|
filterChainDefinitionMap.put("/fonts/**", "anon");
|
|
|
filterChainDefinitionMap.put("/img/**", "anon");
|
|
filterChainDefinitionMap.put("/img/**", "anon");
|
|
|
|
|
+ filterChainDefinitionMap.put("/i18n/**", "anon");
|
|
|
filterChainDefinitionMap.put("/ajax/**", "anon");
|
|
filterChainDefinitionMap.put("/ajax/**", "anon");
|
|
|
filterChainDefinitionMap.put("/js/**", "anon");
|
|
filterChainDefinitionMap.put("/js/**", "anon");
|
|
|
- filterChainDefinitionMap.put("/ruoyi/**", "anon");
|
|
|
|
|
|
|
+ filterChainDefinitionMap.put("/biandan/**", "anon");
|
|
|
|
|
+ filterChainDefinitionMap.put("/api/expfeeds/**", "anon");
|
|
|
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
|
|
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
|
|
|
- // 匿名访问不鉴权注解列表
|
|
|
|
|
- List<String> permitAllUrl = SpringUtils.getBean(PermitAllUrlProperties.class).getUrls();
|
|
|
|
|
- if (StringUtils.isNotEmpty(permitAllUrl))
|
|
|
|
|
- {
|
|
|
|
|
- permitAllUrl.forEach(url -> filterChainDefinitionMap.put(url, "anon"));
|
|
|
|
|
- }
|
|
|
|
|
// 退出 logout地址,shiro去清除session
|
|
// 退出 logout地址,shiro去清除session
|
|
|
filterChainDefinitionMap.put("/logout", "logout");
|
|
filterChainDefinitionMap.put("/logout", "logout");
|
|
|
// 不需要拦截的访问
|
|
// 不需要拦截的访问
|
|
@@ -305,9 +338,9 @@ public class ShiroConfig
|
|
|
// 系统权限列表
|
|
// 系统权限列表
|
|
|
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());
|
|
// filterChainDefinitionMap.putAll(SpringUtils.getBean(IMenuService.class).selectPermsAll());
|
|
|
|
|
|
|
|
- Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
|
|
|
|
|
- filters.put("onlineSession", onlineSessionFilter());
|
|
|
|
|
- filters.put("syncOnlineSession", syncOnlineSessionFilter());
|
|
|
|
|
|
|
+ Map<String, Filter> filters = new LinkedHashMap<>();
|
|
|
|
|
+// filters.put("onlineSession", onlineSessionFilter());
|
|
|
|
|
+// filters.put("syncOnlineSession", syncOnlineSessionFilter());
|
|
|
filters.put("captchaValidate", captchaValidateFilter());
|
|
filters.put("captchaValidate", captchaValidateFilter());
|
|
|
filters.put("kickout", kickoutSessionFilter());
|
|
filters.put("kickout", kickoutSessionFilter());
|
|
|
// 注销成功,则跳转到指定页面
|
|
// 注销成功,则跳转到指定页面
|
|
@@ -315,32 +348,30 @@ public class ShiroConfig
|
|
|
shiroFilterFactoryBean.setFilters(filters);
|
|
shiroFilterFactoryBean.setFilters(filters);
|
|
|
|
|
|
|
|
// 所有请求需要认证
|
|
// 所有请求需要认证
|
|
|
- filterChainDefinitionMap.put("/**", "user,kickout,onlineSession,syncOnlineSession");
|
|
|
|
|
|
|
+ filterChainDefinitionMap.put("/**", "user,kickout");
|
|
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
|
|
|
|
|
|
|
return shiroFilterFactoryBean;
|
|
return shiroFilterFactoryBean;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 自定义在线用户处理过滤器
|
|
|
|
|
- */
|
|
|
|
|
- public OnlineSessionFilter onlineSessionFilter()
|
|
|
|
|
- {
|
|
|
|
|
- OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
|
|
|
|
|
- onlineSessionFilter.setLoginUrl(loginUrl);
|
|
|
|
|
- onlineSessionFilter.setOnlineSessionDAO(sessionDAO());
|
|
|
|
|
- return onlineSessionFilter;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 自定义在线用户同步过滤器
|
|
|
|
|
- */
|
|
|
|
|
- public SyncOnlineSessionFilter syncOnlineSessionFilter()
|
|
|
|
|
- {
|
|
|
|
|
- SyncOnlineSessionFilter syncOnlineSessionFilter = new SyncOnlineSessionFilter();
|
|
|
|
|
- syncOnlineSessionFilter.setOnlineSessionDAO(sessionDAO());
|
|
|
|
|
- return syncOnlineSessionFilter;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 自定义在线用户处理过滤器
|
|
|
|
|
+// */
|
|
|
|
|
+// public OnlineSessionFilter onlineSessionFilter() {
|
|
|
|
|
+// OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
|
|
|
|
|
+// onlineSessionFilter.setLoginUrl(loginUrl);
|
|
|
|
|
+// onlineSessionFilter.setOnlineSessionDAO(sessionDAO());
|
|
|
|
|
+// return onlineSessionFilter;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 自定义在线用户同步过滤器
|
|
|
|
|
+// */
|
|
|
|
|
+// public SyncOnlineSessionFilter syncOnlineSessionFilter() {
|
|
|
|
|
+// SyncOnlineSessionFilter syncOnlineSessionFilter = new SyncOnlineSessionFilter();
|
|
|
|
|
+// syncOnlineSessionFilter.setOnlineSessionDAO(sessionDAO());
|
|
|
|
|
+// return syncOnlineSessionFilter;
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 自定义验证码过滤器
|
|
* 自定义验证码过滤器
|
|
@@ -369,9 +400,9 @@ public class ShiroConfig
|
|
|
/**
|
|
/**
|
|
|
* 记住我
|
|
* 记住我
|
|
|
*/
|
|
*/
|
|
|
- public CustomCookieRememberMeManager rememberMeManager()
|
|
|
|
|
|
|
+ public CookieRememberMeManager rememberMeManager()
|
|
|
{
|
|
{
|
|
|
- CustomCookieRememberMeManager cookieRememberMeManager = new CustomCookieRememberMeManager();
|
|
|
|
|
|
|
+ CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
|
|
cookieRememberMeManager.setCookie(rememberMeCookie());
|
|
cookieRememberMeManager.setCookie(rememberMeCookie());
|
|
|
if (StringUtils.isNotEmpty(cipherKey))
|
|
if (StringUtils.isNotEmpty(cipherKey))
|
|
|
{
|
|
{
|
|
@@ -390,7 +421,7 @@ public class ShiroConfig
|
|
|
public KickoutSessionFilter kickoutSessionFilter()
|
|
public KickoutSessionFilter kickoutSessionFilter()
|
|
|
{
|
|
{
|
|
|
KickoutSessionFilter kickoutSessionFilter = new KickoutSessionFilter();
|
|
KickoutSessionFilter kickoutSessionFilter = new KickoutSessionFilter();
|
|
|
- kickoutSessionFilter.setCacheManager(getEhCacheManager());
|
|
|
|
|
|
|
+ kickoutSessionFilter.setCacheManager(redisCacheManager());
|
|
|
kickoutSessionFilter.setSessionManager(sessionManager());
|
|
kickoutSessionFilter.setSessionManager(sessionManager());
|
|
|
// 同一个用户最大的会话数,默认-1无限制;比如2的意思是同一个用户允许最多同时两个人登录
|
|
// 同一个用户最大的会话数,默认-1无限制;比如2的意思是同一个用户允许最多同时两个人登录
|
|
|
kickoutSessionFilter.setMaxSession(maxSession);
|
|
kickoutSessionFilter.setMaxSession(maxSession);
|
|
@@ -414,11 +445,18 @@ public class ShiroConfig
|
|
|
* 开启Shiro注解通知器
|
|
* 开启Shiro注解通知器
|
|
|
*/
|
|
*/
|
|
|
@Bean
|
|
@Bean
|
|
|
- public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
|
|
|
|
|
- @Qualifier("securityManager") SecurityManager securityManager)
|
|
|
|
|
|
|
+ public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager)
|
|
|
{
|
|
{
|
|
|
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
|
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
|
|
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
|
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
|
|
return authorizationAttributeSourceAdvisor;
|
|
return authorizationAttributeSourceAdvisor;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator()
|
|
|
|
|
+ {
|
|
|
|
|
+ DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
|
|
|
|
+ defaultAdvisorAutoProxyCreator.setUsePrefix(true);
|
|
|
|
|
+ return defaultAdvisorAutoProxyCreator;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|