修改注释
This commit is contained in:
parent
0c76d45349
commit
e9a9aa2eee
|
|
@ -1,8 +1,16 @@
|
||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
||||||
import java.util.Map;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import javax.servlet.Filter;
|
import com.ruoyi.framework.shiro.realm.UserRealm;
|
||||||
|
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
||||||
|
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
|
||||||
|
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
|
||||||
|
import com.ruoyi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
|
||||||
|
import com.ruoyi.framework.shiro.web.filter.online.OnlineSessionFilter;
|
||||||
|
import com.ruoyi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
|
||||||
|
import com.ruoyi.framework.shiro.web.session.OnlineWebSessionManager;
|
||||||
|
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
|
||||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||||
import org.apache.shiro.codec.Base64;
|
import org.apache.shiro.codec.Base64;
|
||||||
import org.apache.shiro.mgt.SecurityManager;
|
import org.apache.shiro.mgt.SecurityManager;
|
||||||
|
|
@ -15,65 +23,77 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
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.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.framework.shiro.realm.UserRealm;
|
import javax.servlet.Filter;
|
||||||
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
import java.util.LinkedHashMap;
|
||||||
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
|
import java.util.Map;
|
||||||
import com.ruoyi.framework.shiro.web.filter.LogoutFilter;
|
|
||||||
import com.ruoyi.framework.shiro.web.filter.captcha.CaptchaValidateFilter;
|
|
||||||
import com.ruoyi.framework.shiro.web.filter.online.OnlineSessionFilter;
|
|
||||||
import com.ruoyi.framework.shiro.web.filter.sync.SyncOnlineSessionFilter;
|
|
||||||
import com.ruoyi.framework.shiro.web.session.OnlineWebSessionManager;
|
|
||||||
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
|
|
||||||
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限配置加载
|
* 权限配置加载
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ShiroConfig
|
public class ShiroConfig {
|
||||||
{
|
|
||||||
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
||||||
|
|
||||||
// Session超时时间,单位为毫秒(默认30分钟)
|
/**
|
||||||
|
* Session超时时间,单位为毫秒(默认30分钟)
|
||||||
|
*/
|
||||||
@Value("${shiro.session.expireTime}")
|
@Value("${shiro.session.expireTime}")
|
||||||
private int expireTime;
|
private int expireTime;
|
||||||
|
|
||||||
// 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
|
/**
|
||||||
|
* 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
|
||||||
|
*/
|
||||||
@Value("${shiro.session.validationInterval}")
|
@Value("${shiro.session.validationInterval}")
|
||||||
private int validationInterval;
|
private int validationInterval;
|
||||||
|
|
||||||
// 验证码开关
|
/**
|
||||||
|
* 验证码开关
|
||||||
|
*/
|
||||||
@Value("${shiro.user.captchaEnabled}")
|
@Value("${shiro.user.captchaEnabled}")
|
||||||
private boolean captchaEnabled;
|
private boolean captchaEnabled;
|
||||||
|
|
||||||
// 验证码类型
|
/**
|
||||||
|
* 验证码类型
|
||||||
|
*/
|
||||||
@Value("${shiro.user.captchaType}")
|
@Value("${shiro.user.captchaType}")
|
||||||
private String captchaType;
|
private String captchaType;
|
||||||
|
|
||||||
// 设置Cookie的域名
|
/**
|
||||||
|
* 设置Cookie的域名
|
||||||
|
*/
|
||||||
@Value("${shiro.cookie.domain}")
|
@Value("${shiro.cookie.domain}")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
// 设置cookie的有效访问路径
|
/**
|
||||||
|
* 设置cookie的有效访问路径
|
||||||
|
*/
|
||||||
@Value("${shiro.cookie.path}")
|
@Value("${shiro.cookie.path}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
// 设置HttpOnly属性
|
/**
|
||||||
|
* 设置HttpOnly属性
|
||||||
|
*/
|
||||||
@Value("${shiro.cookie.httpOnly}")
|
@Value("${shiro.cookie.httpOnly}")
|
||||||
private boolean httpOnly;
|
private boolean httpOnly;
|
||||||
|
|
||||||
// 设置Cookie的过期时间,秒为单位
|
/**
|
||||||
|
* 设置Cookie的过期时间,秒为单位
|
||||||
|
*/
|
||||||
@Value("${shiro.cookie.maxAge}")
|
@Value("${shiro.cookie.maxAge}")
|
||||||
private int maxAge;
|
private int maxAge;
|
||||||
|
|
||||||
// 登录地址
|
/**
|
||||||
|
* 登录地址
|
||||||
|
*/
|
||||||
@Value("${shiro.user.loginUrl}")
|
@Value("${shiro.user.loginUrl}")
|
||||||
private String loginUrl;
|
private String loginUrl;
|
||||||
|
|
||||||
// 权限认证失败地址
|
/**
|
||||||
|
* 权限认证失败地址
|
||||||
|
*/
|
||||||
@Value("${shiro.user.unauthorizedUrl}")
|
@Value("${shiro.user.unauthorizedUrl}")
|
||||||
private String unauthorizedUrl;
|
private String unauthorizedUrl;
|
||||||
|
|
||||||
|
|
@ -81,17 +101,13 @@ public class ShiroConfig
|
||||||
* 缓存管理器 使用Ehcache实现
|
* 缓存管理器 使用Ehcache实现
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public EhCacheManager getEhCacheManager()
|
public EhCacheManager getEhCacheManager() {
|
||||||
{
|
|
||||||
net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("ruoyi");
|
net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("ruoyi");
|
||||||
EhCacheManager em = new EhCacheManager();
|
EhCacheManager em = new EhCacheManager();
|
||||||
if (StringUtils.isNull(cacheManager))
|
if (StringUtils.isNull(cacheManager)) {
|
||||||
{
|
|
||||||
em.setCacheManagerConfigFile("classpath:ehcache/ehcache-shiro.xml");
|
em.setCacheManagerConfigFile("classpath:ehcache/ehcache-shiro.xml");
|
||||||
return em;
|
return em;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
em.setCacheManager(cacheManager);
|
em.setCacheManager(cacheManager);
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
@ -101,8 +117,7 @@ public class ShiroConfig
|
||||||
* 自定义Realm
|
* 自定义Realm
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public UserRealm userRealm(EhCacheManager cacheManager)
|
public UserRealm userRealm(EhCacheManager cacheManager) {
|
||||||
{
|
|
||||||
UserRealm userRealm = new UserRealm();
|
UserRealm userRealm = new UserRealm();
|
||||||
userRealm.setCacheManager(cacheManager);
|
userRealm.setCacheManager(cacheManager);
|
||||||
return userRealm;
|
return userRealm;
|
||||||
|
|
@ -112,8 +127,7 @@ public class ShiroConfig
|
||||||
* 自定义sessionDAO会话
|
* 自定义sessionDAO会话
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OnlineSessionDAO sessionDAO()
|
public OnlineSessionDAO sessionDAO() {
|
||||||
{
|
|
||||||
OnlineSessionDAO sessionDAO = new OnlineSessionDAO();
|
OnlineSessionDAO sessionDAO = new OnlineSessionDAO();
|
||||||
return sessionDAO;
|
return sessionDAO;
|
||||||
}
|
}
|
||||||
|
|
@ -122,8 +136,7 @@ public class ShiroConfig
|
||||||
* 自定义sessionFactory会话
|
* 自定义sessionFactory会话
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OnlineSessionFactory sessionFactory()
|
public OnlineSessionFactory sessionFactory() {
|
||||||
{
|
|
||||||
OnlineSessionFactory sessionFactory = new OnlineSessionFactory();
|
OnlineSessionFactory sessionFactory = new OnlineSessionFactory();
|
||||||
return sessionFactory;
|
return sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
@ -132,8 +145,7 @@ public class ShiroConfig
|
||||||
* 自定义sessionFactory调度器
|
* 自定义sessionFactory调度器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public SpringSessionValidationScheduler sessionValidationScheduler()
|
public SpringSessionValidationScheduler sessionValidationScheduler() {
|
||||||
{
|
|
||||||
SpringSessionValidationScheduler sessionValidationScheduler = new SpringSessionValidationScheduler();
|
SpringSessionValidationScheduler sessionValidationScheduler = new SpringSessionValidationScheduler();
|
||||||
// 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
|
// 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
|
||||||
sessionValidationScheduler.setSessionValidationInterval(validationInterval * 60 * 1000);
|
sessionValidationScheduler.setSessionValidationInterval(validationInterval * 60 * 1000);
|
||||||
|
|
@ -146,8 +158,7 @@ public class ShiroConfig
|
||||||
* 会话管理器
|
* 会话管理器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OnlineWebSessionManager sessionValidationManager()
|
public OnlineWebSessionManager sessionValidationManager() {
|
||||||
{
|
|
||||||
OnlineWebSessionManager manager = new OnlineWebSessionManager();
|
OnlineWebSessionManager manager = new OnlineWebSessionManager();
|
||||||
// 加入缓存管理器
|
// 加入缓存管理器
|
||||||
manager.setCacheManager(getEhCacheManager());
|
manager.setCacheManager(getEhCacheManager());
|
||||||
|
|
@ -170,8 +181,7 @@ public class ShiroConfig
|
||||||
* 会话管理器
|
* 会话管理器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OnlineWebSessionManager sessionManager()
|
public OnlineWebSessionManager sessionManager() {
|
||||||
{
|
|
||||||
OnlineWebSessionManager manager = new OnlineWebSessionManager();
|
OnlineWebSessionManager manager = new OnlineWebSessionManager();
|
||||||
// 加入缓存管理器
|
// 加入缓存管理器
|
||||||
manager.setCacheManager(getEhCacheManager());
|
manager.setCacheManager(getEhCacheManager());
|
||||||
|
|
@ -196,8 +206,7 @@ public class ShiroConfig
|
||||||
* 安全管理器
|
* 安全管理器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityManager securityManager(UserRealm userRealm)
|
public SecurityManager securityManager(UserRealm userRealm) {
|
||||||
{
|
|
||||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||||
// 设置realm.
|
// 设置realm.
|
||||||
securityManager.setRealm(userRealm);
|
securityManager.setRealm(userRealm);
|
||||||
|
|
@ -213,8 +222,7 @@ public class ShiroConfig
|
||||||
/**
|
/**
|
||||||
* 退出过滤器
|
* 退出过滤器
|
||||||
*/
|
*/
|
||||||
public LogoutFilter logoutFilter()
|
public LogoutFilter logoutFilter() {
|
||||||
{
|
|
||||||
LogoutFilter logoutFilter = new LogoutFilter();
|
LogoutFilter logoutFilter = new LogoutFilter();
|
||||||
logoutFilter.setLoginUrl(loginUrl);
|
logoutFilter.setLoginUrl(loginUrl);
|
||||||
return logoutFilter;
|
return logoutFilter;
|
||||||
|
|
@ -224,8 +232,7 @@ public class ShiroConfig
|
||||||
* Shiro过滤器配置
|
* Shiro过滤器配置
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager)
|
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
|
||||||
{
|
|
||||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||||
// Shiro的核心安全接口,这个属性是必须的
|
// Shiro的核心安全接口,这个属性是必须的
|
||||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||||
|
|
@ -273,8 +280,7 @@ public class ShiroConfig
|
||||||
* 自定义在线用户处理过滤器
|
* 自定义在线用户处理过滤器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OnlineSessionFilter onlineSessionFilter()
|
public OnlineSessionFilter onlineSessionFilter() {
|
||||||
{
|
|
||||||
OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
|
OnlineSessionFilter onlineSessionFilter = new OnlineSessionFilter();
|
||||||
onlineSessionFilter.setLoginUrl(loginUrl);
|
onlineSessionFilter.setLoginUrl(loginUrl);
|
||||||
return onlineSessionFilter;
|
return onlineSessionFilter;
|
||||||
|
|
@ -284,8 +290,7 @@ public class ShiroConfig
|
||||||
* 自定义在线用户同步过滤器
|
* 自定义在线用户同步过滤器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public SyncOnlineSessionFilter syncOnlineSessionFilter()
|
public SyncOnlineSessionFilter syncOnlineSessionFilter() {
|
||||||
{
|
|
||||||
SyncOnlineSessionFilter syncOnlineSessionFilter = new SyncOnlineSessionFilter();
|
SyncOnlineSessionFilter syncOnlineSessionFilter = new SyncOnlineSessionFilter();
|
||||||
return syncOnlineSessionFilter;
|
return syncOnlineSessionFilter;
|
||||||
}
|
}
|
||||||
|
|
@ -294,8 +299,7 @@ public class ShiroConfig
|
||||||
* 自定义验证码过滤器
|
* 自定义验证码过滤器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public CaptchaValidateFilter captchaValidateFilter()
|
public CaptchaValidateFilter captchaValidateFilter() {
|
||||||
{
|
|
||||||
CaptchaValidateFilter captchaValidateFilter = new CaptchaValidateFilter();
|
CaptchaValidateFilter captchaValidateFilter = new CaptchaValidateFilter();
|
||||||
captchaValidateFilter.setCaptchaEnabled(captchaEnabled);
|
captchaValidateFilter.setCaptchaEnabled(captchaEnabled);
|
||||||
captchaValidateFilter.setCaptchaType(captchaType);
|
captchaValidateFilter.setCaptchaType(captchaType);
|
||||||
|
|
@ -305,8 +309,7 @@ public class ShiroConfig
|
||||||
/**
|
/**
|
||||||
* cookie 属性设置
|
* cookie 属性设置
|
||||||
*/
|
*/
|
||||||
public SimpleCookie rememberMeCookie()
|
public SimpleCookie rememberMeCookie() {
|
||||||
{
|
|
||||||
SimpleCookie cookie = new SimpleCookie("rememberMe");
|
SimpleCookie cookie = new SimpleCookie("rememberMe");
|
||||||
cookie.setDomain(domain);
|
cookie.setDomain(domain);
|
||||||
cookie.setPath(path);
|
cookie.setPath(path);
|
||||||
|
|
@ -318,8 +321,7 @@ public class ShiroConfig
|
||||||
/**
|
/**
|
||||||
* 记住我
|
* 记住我
|
||||||
*/
|
*/
|
||||||
public CookieRememberMeManager rememberMeManager()
|
public CookieRememberMeManager rememberMeManager() {
|
||||||
{
|
|
||||||
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
||||||
cookieRememberMeManager.setCookie(rememberMeCookie());
|
cookieRememberMeManager.setCookie(rememberMeCookie());
|
||||||
cookieRememberMeManager.setCipherKey(Base64.decode("fCq+/xW488hMTCD+cmJ3aQ=="));
|
cookieRememberMeManager.setCipherKey(Base64.decode("fCq+/xW488hMTCD+cmJ3aQ=="));
|
||||||
|
|
@ -330,8 +332,7 @@ public class ShiroConfig
|
||||||
* thymeleaf模板引擎和shiro框架的整合
|
* thymeleaf模板引擎和shiro框架的整合
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ShiroDialect shiroDialect()
|
public ShiroDialect shiroDialect() {
|
||||||
{
|
|
||||||
return new ShiroDialect();
|
return new ShiroDialect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,8 +341,7 @@ public class ShiroConfig
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
|
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
|
||||||
@Qualifier("securityManager") SecurityManager securityManager)
|
@Qualifier("securityManager") SecurityManager securityManager) {
|
||||||
{
|
|
||||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
||||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
||||||
return authorizationAttributeSourceAdvisor;
|
return authorizationAttributeSourceAdvisor;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue