mirror of https://github.com/jeecgboot/jeecg-boot
commit
ea6927a2a7
|
@ -0,0 +1,47 @@
|
||||||
|
package org.jeecg.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.SpringApplicationRunListener;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.MapPropertySource;
|
||||||
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
|
import org.springframework.core.env.PropertySource;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author eightmonth@qq.com
|
||||||
|
* @date 2024/4/8 11:37
|
||||||
|
*/
|
||||||
|
public class DruidWallConfigRegister implements SpringApplicationRunListener {
|
||||||
|
|
||||||
|
public SpringApplication application;
|
||||||
|
|
||||||
|
private String[] args;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必备,否则启动报错
|
||||||
|
* @param application
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public DruidWallConfigRegister(SpringApplication application, String[] args) {
|
||||||
|
this.application = application;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextLoaded(ConfigurableApplicationContext context) {
|
||||||
|
ConfigurableEnvironment env = context.getEnvironment();
|
||||||
|
Map<String, Object> props = new HashMap<>();
|
||||||
|
props.put("spring.datasource.dynamic.druid.wall.selectWhereAlwayTrueCheck", false);
|
||||||
|
|
||||||
|
MutablePropertySources propertySources = env.getPropertySources();
|
||||||
|
|
||||||
|
PropertySource<Map<String, Object>> propertySource = new MapPropertySource("jeecg-datasource-config", props);
|
||||||
|
|
||||||
|
propertySources.addLast(propertySource);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,18 +16,16 @@ import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.config.JeecgBaseConfig;
|
import org.jeecg.config.JeecgBaseConfig;
|
||||||
import org.jeecg.config.shiro.filters.CustomShiroFilterFactoryBean;
|
import org.jeecg.config.shiro.filters.CustomShiroFilterFactoryBean;
|
||||||
import org.jeecg.config.shiro.filters.JwtFilter;
|
import org.jeecg.config.shiro.filters.JwtFilter;
|
||||||
import org.springframework.aop.framework.Advised;
|
|
||||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.DependsOn;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.*;
|
||||||
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -39,7 +37,6 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +47,8 @@ import java.util.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
|
// 免认证注解 @IgnoreAuth 注解生效范围配置
|
||||||
|
@ComponentScan(basePackages = {"org.jeecg"})
|
||||||
public class ShiroConfig {
|
public class ShiroConfig {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -60,9 +59,6 @@ public class ShiroConfig {
|
||||||
private JeecgBaseConfig jeecgBaseConfig;
|
private JeecgBaseConfig jeecgBaseConfig;
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private RedisProperties redisProperties;
|
private RedisProperties redisProperties;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApplicationContext ctx;
|
|
||||||
/**
|
/**
|
||||||
* Filter Chain定义说明
|
* Filter Chain定义说明
|
||||||
*
|
*
|
||||||
|
@ -177,13 +173,15 @@ public class ShiroConfig {
|
||||||
// 企业微信证书排除
|
// 企业微信证书排除
|
||||||
filterChainDefinitionMap.put("/WW_verify*", "anon");
|
filterChainDefinitionMap.put("/WW_verify*", "anon");
|
||||||
|
|
||||||
// // 通过注解免登录url
|
|
||||||
// List<String> ignoreAuthUrlList = collectIgnoreAuthUrl(ctx);
|
// 通过注解免登录url
|
||||||
// if (!CollectionUtils.isEmpty(ignoreAuthUrlList)) {
|
List<String> ignoreAuthUrlList = collectIgnoreAuthUrl();
|
||||||
// for (String url : ignoreAuthUrlList) {
|
if (!CollectionUtils.isEmpty(ignoreAuthUrlList)) {
|
||||||
// filterChainDefinitionMap.put(url, "anon");
|
for (String url : ignoreAuthUrlList) {
|
||||||
// }
|
filterChainDefinitionMap.put(url, "anon");
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 添加自己的过滤器并且取名为jwt
|
// 添加自己的过滤器并且取名为jwt
|
||||||
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
||||||
|
@ -339,20 +337,27 @@ public class ShiroConfig {
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public List<String> collectIgnoreAuthUrl(ApplicationContext context) {
|
public List<String> collectIgnoreAuthUrl() {
|
||||||
List<String> ignoreAuthUrls = new ArrayList<>();
|
List<String> ignoreAuthUrls = new ArrayList<>();
|
||||||
Map<String, Object> controllers = context.getBeansWithAnnotation(RestController.class);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
for (Object bean : controllers.values()) {
|
provider.addIncludeFilter(new AnnotationTypeFilter(RestController.class));
|
||||||
if (!(bean instanceof Advised)) {
|
|
||||||
continue;
|
// 获取当前类的扫描注解的配置
|
||||||
}
|
Set<BeanDefinition> components = new HashSet<>();
|
||||||
Class<?> beanClass = ((Advised) bean).getTargetSource().getTarget().getClass();
|
for (String basePackage : AnnotationUtils.getAnnotation(ShiroConfig.class, ComponentScan.class).basePackages()) {
|
||||||
RequestMapping base = beanClass.getAnnotation(RequestMapping.class);
|
components.addAll(provider.findCandidateComponents(basePackage));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 逐个匹配获取免认证路径
|
||||||
|
for (BeanDefinition component : components) {
|
||||||
|
String beanClassName = component.getBeanClassName();
|
||||||
|
Class<?> clazz = Class.forName(beanClassName);
|
||||||
|
RequestMapping base = clazz.getAnnotation(RequestMapping.class);
|
||||||
String[] baseUrl = {};
|
String[] baseUrl = {};
|
||||||
if (Objects.nonNull(base)) {
|
if (Objects.nonNull(base)) {
|
||||||
baseUrl = base.value();
|
baseUrl = base.value();
|
||||||
}
|
}
|
||||||
Method[] methods = beanClass.getDeclaredMethods();
|
Method[] methods = clazz.getDeclaredMethods();
|
||||||
|
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (method.isAnnotationPresent(IgnoreAuth.class) && method.isAnnotationPresent(RequestMapping.class)) {
|
if (method.isAnnotationPresent(IgnoreAuth.class) && method.isAnnotationPresent(RequestMapping.class)) {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
org.springframework.boot.SpringApplicationRunListener=\
|
||||||
|
org.jeecg.config.DruidWallConfigRegister
|
|
@ -79,6 +79,7 @@ public enum RangeDateEnum {
|
||||||
//本周
|
//本周
|
||||||
calendar1.set(Calendar.DAY_OF_WEEK, 2);
|
calendar1.set(Calendar.DAY_OF_WEEK, 2);
|
||||||
|
|
||||||
|
calendar2.set(Calendar.DAY_OF_WEEK,2);
|
||||||
calendar2.add(Calendar.WEEK_OF_MONTH,1);
|
calendar2.add(Calendar.WEEK_OF_MONTH,1);
|
||||||
calendar2.add(Calendar.DAY_OF_WEEK,-1);
|
calendar2.add(Calendar.DAY_OF_WEEK,-1);
|
||||||
} else if(SZ.key.equals(key)){
|
} else if(SZ.key.equals(key)){
|
||||||
|
|
Loading…
Reference in New Issue