|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
/* |
|
|
|
|
package com.huoran.iasf.common.shiro; |
|
|
|
|
|
|
|
|
|
import com.huoran.iasf.common.config.FileUploadProperties; |
|
|
|
|
import com.huoran.iasf.common.filter.AuthFilter; |
|
|
|
|
import org.apache.shiro.mgt.SecurityManager; |
|
|
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; |
|
|
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; |
|
|
|
@ -9,20 +9,21 @@ import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.Filter; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
/** |
|
|
|
|
* ShiroConfig |
|
|
|
|
* |
|
|
|
|
* @author cheney |
|
|
|
|
* @version V1.0 |
|
|
|
|
* @date 2022年7月28日 |
|
|
|
|
*//*
|
|
|
|
|
* @date 2022年7月28日*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@EnableConfigurationProperties(FileUploadProperties.class) |
|
|
|
@ -36,9 +37,8 @@ public class ShiroConfig { |
|
|
|
|
return new CustomHashedCredentialsMatcher(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
/** |
|
|
|
|
* 创建realm*//*
|
|
|
|
|
* 创建realm*/ |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public CustomRealm customRealm() { |
|
|
|
@ -56,7 +56,7 @@ public class ShiroConfig { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
/*@Bean |
|
|
|
|
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) { |
|
|
|
|
|
|
|
|
|
//整个shiro执行过程: 过滤器、认证、授权
|
|
|
|
@ -70,8 +70,7 @@ public class ShiroConfig { |
|
|
|
|
shiroFilterFactoryBean.setFilters(filtersMap); |
|
|
|
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); |
|
|
|
|
// 配置不会被拦截的链接 顺序判断
|
|
|
|
|
*/ |
|
|
|
|
/*filterChainDefinitionMap.put("/sys/user/login", "anon"); |
|
|
|
|
*//* filterChainDefinitionMap.put("/sys/user/login", "anon");
|
|
|
|
|
filterChainDefinitionMap.put("/sys/user/token", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/getVerify", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/checkVerify", "anon"); |
|
|
|
@ -94,22 +93,84 @@ public class ShiroConfig { |
|
|
|
|
filterChainDefinitionMap.put("/layui/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/css/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/layui-ext/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/app/api/**", "anon");*//*
|
|
|
|
|
filterChainDefinitionMap.put("/app/api/**", "anon"); |
|
|
|
|
|
|
|
|
|
filterChainDefinitionMap.put("/sys/getVerify", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/user/login", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/user/login", "anon");*//*
|
|
|
|
|
filterChainDefinitionMap.put("/**", "token,authc"); |
|
|
|
|
shiroFilterFactoryBean.setLoginUrl("/login"); |
|
|
|
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); |
|
|
|
|
return shiroFilterFactoryBean; |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public ShiroFilterFactoryBean shirFilter() { |
|
|
|
|
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); |
|
|
|
|
shiroFilterFactoryBean.setLoginUrl("/login"); |
|
|
|
|
shiroFilterFactoryBean.setSecurityManager(securityManager()); |
|
|
|
|
Map<String, Filter> filterMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
// 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 :这是一个坑呢,一不小心代码就不好使了;
|
|
|
|
|
// ① authc:所有url都必须认证通过才可以访问; ② anon:所有url都都可以匿名访问
|
|
|
|
|
|
|
|
|
|
//过滤器1
|
|
|
|
|
filterMap.put("token", new AuthFilter()); |
|
|
|
|
//过滤器2
|
|
|
|
|
//用来校验token
|
|
|
|
|
filterMap.put("authc", new CustomAccessControlFilter()); |
|
|
|
|
shiroFilterFactoryBean.setFilters(filterMap); |
|
|
|
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); |
|
|
|
|
// 配置不会被拦截的链接 顺序判断
|
|
|
|
|
filterChainDefinitionMap.put("/sys/user/login", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/user/token", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/getVerify", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/checkVerify", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysFiles/preview/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysContent/findById", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/findById", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysContent/articlePreview", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysContent/newlyPublishedArticles", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/listWithTreeMenuVisible", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysContent/hotContent", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/listWithTree", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumnLongPage/getLongPageInformation", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/favicon.ico", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/queryArticlesByColumnType", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/content/label/queryAllArticleSubjectTags", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/oneLevelChecksThemAll", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sysColumn/getTheFullArticleByColumn", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/sys/exportFailure", "anon"); |
|
|
|
|
/*filterChainDefinitionMap.put("/index/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/doc.html", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/swagger-resources/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/v2/api-docs", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/v2/api-docs-ext", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("*.html", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/static/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/webjars/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/druid/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/favicon.ico", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/captcha.jpg", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/csrf", "anon"); |
|
|
|
|
//文件上传可直接访问
|
|
|
|
|
filterChainDefinitionMap.put(fileUploadProperties.getAccessUrl(), "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/images/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/js/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/layui/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/css/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/layui-ext/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/app/api/**", "anon");*/ |
|
|
|
|
// 所有请求经过过滤器
|
|
|
|
|
filterChainDefinitionMap.put("/**", "authc,token"); |
|
|
|
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); |
|
|
|
|
return shiroFilterFactoryBean; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
/** |
|
|
|
|
* 开启shiro aop注解支持. |
|
|
|
|
* 使用代理方式;所以需要开启代码支持; |
|
|
|
|
* |
|
|
|
|
* @return org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor*//*
|
|
|
|
|
* @return org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor*/ |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { |
|
|
|
@ -121,4 +182,3 @@ public class ShiroConfig { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|