From ab0d02a473e2bfb57cfd2bc7defcfbdacb802ce0 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Tue, 2 Apr 2024 20:22:02 +0800 Subject: [PATCH 01/14] update --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea0770a2..0312d08e 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,13 @@ | github | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web | | 码云 | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web | -#### 赞助商 | Sponsor - - -明道云零代码构建平台 +#### VPS推荐 + + +使用优惠码: `BWHCCNCXVV`,可获得 6.81% 的折扣, [查看介绍](https://bwhstock.in/) + #### 主要特性 - 使用最新技术栈,社区资源丰富。 - 高效率开发,代码生成器可一键生成前后端代码 From 3e659922559db3c73037ff0e5e0372b276e20003 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Fri, 24 May 2024 16:11:33 +0800 Subject: [PATCH 02/14] update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0312d08e..084873ab 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,10 @@ | github | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web | | 码云 | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web | -#### VPS推荐 - - - +#### 赞助商 | Sponsor -使用优惠码: `BWHCCNCXVV`,可获得 6.81% 的折扣, [查看介绍](https://bwhstock.in/) + +明道云零代码构建平台 #### 主要特性 - 使用最新技术栈,社区资源丰富。 From 0494f6ad17b93817dbb5c8453e3d76242ca4a5d6 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Fri, 9 Aug 2024 20:03:02 +0800 Subject: [PATCH 03/14] =?UTF-8?q?feat:=20quartz=20=E5=88=86=E5=B8=83?= =?UTF-8?q?=E5=BC=8F=E6=94=AF=E6=8C=81=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=8D=95?= =?UTF-8?q?=E6=9C=BA=E8=BF=90=E8=A1=8C=EF=BC=8C=E5=A6=82=E6=9E=9C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=94=AF=E6=8C=81=E5=88=86=E5=B8=83=E5=BC=8F=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=9F=A5=E7=9C=8B=20application-quartz.yml=20?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-system/pom.xml | 12 +- .../modules/quartz/config/QuartzConfig.java | 24 ++- .../modules/quartz/utils/QuartzManage.java | 9 +- .../resources/config/application-quartz.yml | 29 +++ .../src/main/resources/config/application.yml | 1 + sql/quartz.sql | 170 ++++++++++++++++++ 6 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 eladmin-system/src/main/resources/config/application-quartz.yml create mode 100644 sql/quartz.sql diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 9119bc12..e1799196 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -45,6 +45,12 @@ spring-boot-starter-websocket + + + org.springframework.boot + spring-boot-starter-quartz + + io.jsonwebtoken @@ -62,12 +68,6 @@ ${jjwt.version} - - - org.quartz-scheduler - quartz - - ch.ethz.ganymed diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java index 99f2e50e..d542a36a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/config/QuartzConfig.java @@ -15,9 +15,13 @@ */ package me.zhengjie.modules.quartz.config; +import lombok.extern.slf4j.Slf4j; import org.quartz.spi.TriggerFiredBundle; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.lang.NonNull; import org.springframework.scheduling.quartz.AdaptableJobFactory; import org.springframework.stereotype.Component; @@ -26,7 +30,9 @@ import org.springframework.stereotype.Component; * @author / * @date 2019-01-07 */ +@Slf4j @Configuration +@Scope("singleton") public class QuartzConfig { /** @@ -37,16 +43,24 @@ public class QuartzConfig { private final AutowireCapableBeanFactory capableBeanFactory; + @Autowired public QuartzJobFactory(AutowireCapableBeanFactory capableBeanFactory) { this.capableBeanFactory = capableBeanFactory; } + @NonNull @Override - protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { - //调用父类的方法,把Job注入到spring中 - Object jobInstance = super.createJobInstance(bundle); - capableBeanFactory.autowireBean(jobInstance); - return jobInstance; + protected Object createJobInstance(@NonNull TriggerFiredBundle bundle) throws Exception { + try { + // 调用父类的方法,把Job注入到spring中 + Object jobInstance = super.createJobInstance(bundle); + capableBeanFactory.autowireBean(jobInstance); + log.debug("Job instance created and autowired: {}", jobInstance.getClass().getName()); + return jobInstance; + } catch (Exception e) { + log.error("Error creating job instance for bundle: {}", bundle, e); + throw e; + } } } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java index e0cf1e0a..4dbac76b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java @@ -20,7 +20,6 @@ import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.quartz.domain.QuartzJob; import org.quartz.*; import org.quartz.impl.triggers.CronTriggerImpl; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.Date; @@ -57,8 +56,12 @@ public class QuartzManage { //重置启动时间 ((CronTriggerImpl)cronTrigger).setStartTime(new Date()); - //执行定时任务 - scheduler.scheduleJob(jobDetail,cronTrigger); + //执行定时任务,如果是持久化的,这里会报错,捕获输出 + try { + scheduler.scheduleJob(jobDetail,cronTrigger); + } catch (ObjectAlreadyExistsException e) { + log.warn("定时任务已存在,跳过加载"); + } // 暂停任务 if (quartzJob.getIsPause()) { diff --git a/eladmin-system/src/main/resources/config/application-quartz.yml b/eladmin-system/src/main/resources/config/application-quartz.yml new file mode 100644 index 00000000..561482c6 --- /dev/null +++ b/eladmin-system/src/main/resources/config/application-quartz.yml @@ -0,0 +1,29 @@ +# 配置 quartz 分布式支持, sql 文件在 sql 目录下,需要导入到数据库,并且需要修改 application.yml 文件的 active: dev 配置 +spring: + quartz: + # 必需,指定使用 JDBC 存储 + job-store-type: jdbc + properties: + org: + quartz: + scheduler: + # 必需,指定调度器实例的名称 + instanceName: eladmin + # 必需,指定调度器实例的 ID + instanceId: auto + threadPool: + # 可选,线程池的线程数量,可以根据需要调整 + threadCount: 5 + jobStore: + # 可选,如果你不需要集群,可以去掉 + isClustered: true + # 可选,集群检查间隔时间,可以根据需要调整 + clusterCheckinInterval: 10000 + # 必需,指定 JDBC 驱动代理类 + driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate + # 可选,是否使用属性存储,可以根据需要调整 + useProperties: false + # 必需,指定表的前缀 + tablePrefix: qrtz_ + # 可选,指定误触发阈值,可以根据需要调整 + misfireThreshold: 60000 \ No newline at end of file diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index 11884259..6eb7fd4e 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -8,6 +8,7 @@ spring: freemarker: check-template-location: false profiles: + # 激活的环境,如果需要 quartz 分布式支持,需要修改 active: dev,quartz active: dev data: redis: diff --git a/sql/quartz.sql b/sql/quartz.sql new file mode 100644 index 00000000..0c71cb59 --- /dev/null +++ b/sql/quartz.sql @@ -0,0 +1,170 @@ +drop table if exists qrtz_fired_triggers; +drop table if exists qrtz_paused_trigger_grps; +drop table if exists qrtz_scheduler_state; +drop table if exists qrtz_locks; +drop table if exists qrtz_simple_triggers; +drop table if exists qrtz_simprop_triggers; +drop table if exists qrtz_cron_triggers; +drop table if exists qrtz_blob_triggers; +drop table if exists qrtz_triggers; +drop table if exists qrtz_job_details; +drop table if exists qrtz_calendars; + +create table qrtz_job_details( +sched_name varchar(120) not null, +job_name varchar(200) not null, +job_group varchar(200) not null, +description varchar(250) null, +job_class_name varchar(250) not null, +is_durable varchar(1) not null, +is_nonconcurrent varchar(1) not null, +is_update_data varchar(1) not null, +requests_recovery varchar(1) not null, +job_data blob null, +primary key (sched_name, job_name, job_group)) +engine=innodb; + +create table qrtz_triggers ( +sched_name varchar(120) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +job_name varchar(200) not null, +job_group varchar(200) not null, +description varchar(250) null, +next_fire_time bigint(13) null, +prev_fire_time bigint(13) null, +priority integer null, +trigger_state varchar(16) not null, +trigger_type varchar(8) not null, +start_time bigint(13) not null, +end_time bigint(13) null, +calendar_name varchar(200) null, +misfire_instr smallint(2) null, +job_data blob null, +primary key (sched_name, trigger_name, trigger_group), +foreign key (sched_name, job_name, job_group) +references qrtz_job_details(sched_name, job_name, job_group)) +engine=innodb; + +create table qrtz_simple_triggers ( +sched_name varchar(120) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +repeat_count bigint(7) not null, +repeat_interval bigint(12) not null, +times_triggered bigint(10) not null, +primary key (sched_name, trigger_name, trigger_group), +foreign key (sched_name, trigger_name, trigger_group) +references qrtz_triggers(sched_name, trigger_name, trigger_group)) +engine=innodb; + +create table qrtz_cron_triggers ( +sched_name varchar(120) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +cron_expression varchar(120) not null, +time_zone_id varchar(80), +primary key (sched_name, trigger_name, trigger_group), +foreign key (sched_name, trigger_name, trigger_group) +references qrtz_triggers(sched_name, trigger_name, trigger_group)) +engine=innodb; + +create table qrtz_simprop_triggers ( +sched_name varchar(120) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +str_prop_1 varchar(512) null, +str_prop_2 varchar(512) null, +str_prop_3 varchar(512) null, +int_prop_1 int null, +int_prop_2 int null, +long_prop_1 bigint null, +long_prop_2 bigint null, +dec_prop_1 numeric(13, 4) null, +dec_prop_2 numeric(13, 4) null, +bool_prop_1 varchar(1) null, +bool_prop_2 varchar(1) null, +primary key (sched_name, trigger_name, trigger_group), +foreign key (sched_name, trigger_name, trigger_group) +references qrtz_triggers(sched_name, trigger_name, trigger_group)) +engine=innodb; + +create table qrtz_blob_triggers ( +sched_name varchar(120) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +blob_data blob null, +primary key (sched_name, trigger_name, trigger_group), +index (sched_name, trigger_name, trigger_group), +foreign key (sched_name, trigger_name, trigger_group) +references qrtz_triggers(sched_name, trigger_name, trigger_group)) +engine=innodb; + +create table qrtz_calendars ( +sched_name varchar(120) not null, +calendar_name varchar(200) not null, +calendar blob not null, +primary key (sched_name, calendar_name)) +engine=innodb; + +create table qrtz_paused_trigger_grps ( +sched_name varchar(120) not null, +trigger_group varchar(200) not null, +primary key (sched_name, trigger_group)) +engine=innodb; + +create table qrtz_fired_triggers ( +sched_name varchar(120) not null, +entry_id varchar(95) not null, +trigger_name varchar(200) not null, +trigger_group varchar(200) not null, +instance_name varchar(200) not null, +fired_time bigint(13) not null, +sched_time bigint(13) not null, +priority integer not null, +state varchar(16) not null, +job_name varchar(200) null, +job_group varchar(200) null, +is_nonconcurrent varchar(1) null, +requests_recovery varchar(1) null, +primary key (sched_name, entry_id)) +engine=innodb; + +create table qrtz_scheduler_state ( +sched_name varchar(120) not null, +instance_name varchar(200) not null, +last_checkin_time bigint(13) not null, +checkin_interval bigint(13) not null, +primary key (sched_name, instance_name)) +engine=innodb; + +create table qrtz_locks ( +sched_name varchar(120) not null, +lock_name varchar(40) not null, +primary key (sched_name, lock_name)) +engine=innodb; + +create index idx_qrtz_j_req_recovery on qrtz_job_details(sched_name, requests_recovery); +create index idx_qrtz_j_grp on qrtz_job_details(sched_name, job_group); + +create index idx_qrtz_t_j on qrtz_triggers(sched_name, job_name, job_group); +create index idx_qrtz_t_jg on qrtz_triggers(sched_name, job_group); +create index idx_qrtz_t_c on qrtz_triggers(sched_name, calendar_name); +create index idx_qrtz_t_g on qrtz_triggers(sched_name, trigger_group); +create index idx_qrtz_t_state on qrtz_triggers(sched_name, trigger_state); +create index idx_qrtz_t_n_state on qrtz_triggers(sched_name, trigger_name, trigger_group, trigger_state); +create index idx_qrtz_t_n_g_state on qrtz_triggers(sched_name, trigger_group, trigger_state); +create index idx_qrtz_t_next_fire_time on qrtz_triggers(sched_name, next_fire_time); +create index idx_qrtz_t_nft_st on qrtz_triggers(sched_name, trigger_state, next_fire_time); +create index idx_qrtz_t_nft_misfire on qrtz_triggers(sched_name, misfire_instr, next_fire_time); +create index idx_qrtz_t_nft_st_misfire on qrtz_triggers(sched_name, misfire_instr, next_fire_time, trigger_state); +create index idx_qrtz_t_nft_st_misfire_grp on qrtz_triggers(sched_name, misfire_instr, next_fire_time, trigger_group, trigger_state); + +create index idx_qrtz_ft_trig_inst_name on qrtz_fired_triggers(sched_name, instance_name); +create index idx_qrtz_ft_inst_job_req_rcvry on qrtz_fired_triggers(sched_name, instance_name, requests_recovery); +create index idx_qrtz_ft_j_g on qrtz_fired_triggers(sched_name, job_name, job_group); +create index idx_qrtz_ft_jg on qrtz_fired_triggers(sched_name, job_group); +create index idx_qrtz_ft_t_g on qrtz_fired_triggers(sched_name, trigger_name, trigger_group); +create index idx_qrtz_ft_tg on qrtz_fired_triggers(sched_name, trigger_group); + +commit; \ No newline at end of file From f4f76deaf9a1353b25f4df214c35340592c8e9a7 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Fri, 9 Aug 2024 20:21:32 +0800 Subject: [PATCH 04/14] =?UTF-8?q?fix:=20=E5=88=9D=E5=A7=8B=E5=8C=96sql?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/eladmin.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/eladmin.sql b/sql/eladmin.sql index 20ee0949..2711d6e9 100644 --- a/sql/eladmin.sql +++ b/sql/eladmin.sql @@ -615,7 +615,6 @@ INSERT INTO `sys_roles_menus` VALUES (112, 1); INSERT INTO `sys_roles_menus` VALUES (113, 1); INSERT INTO `sys_roles_menus` VALUES (114, 1); INSERT INTO `sys_roles_menus` VALUES (116, 1); -INSERT INTO `sys_roles_menus` VALUES (120, 1); INSERT INTO `sys_roles_menus` VALUES (1, 2); INSERT INTO `sys_roles_menus` VALUES (2, 2); INSERT INTO `sys_roles_menus` VALUES (6, 2); From 08f4860483b4091c5d1383c51380a894fc0952a5 Mon Sep 17 00:00:00 2001 From: l2063610646 <64514383+l2063610646@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:01:03 +0800 Subject: [PATCH 05/14] =?UTF-8?q?fix(LimitAspect):=20=E4=BF=AE=E5=A4=8Dlua?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9D=9F=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84bug=20(#810)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(EmailServiceImpl): 解决由于jdk8之后默认禁用了部分tls协议,从而导致发送邮件失败的问题 1、测试jdk版本:jdk1.8.0_351 * fix(LimitAspect): 修复lua脚本执行结束后,类型转换失败的bug 1、测试jdk版本:jdk1.8.0_351、jdk11.0.18 类型转换失败,不能将值转换为Number,用Long进行替代 --- .../src/main/java/me/zhengjie/aspect/LimitAspect.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java b/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java index 31f40404..4b9a7b8e 100644 --- a/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java +++ b/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java @@ -71,8 +71,8 @@ public class LimitAspect { ImmutableList keys = ImmutableList.of(StringUtils.join(limit.prefix(), "_", key, "_", request.getRequestURI().replace("/","_"))); String luaScript = buildLuaScript(); - RedisScript redisScript = new DefaultRedisScript<>(luaScript, Number.class); - Number count = redisTemplate.execute(redisScript, keys, limit.count(), limit.period()); + RedisScript redisScript = new DefaultRedisScript<>(luaScript, Long.class); + Long count = redisTemplate.execute(redisScript, keys, limit.count(), limit.period()); if (null != count && count.intValue() <= limit.count()) { logger.info("第{}次访问key为 {},描述为 [{}] 的接口", count, keys, limit.name()); return joinPoint.proceed(); From bb11e403cbfd17432524af53b6ae29973b141be3 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Mon, 9 Dec 2024 09:04:16 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E7=A7=BB=E9=99=A4OnlineUserService?= =?UTF-8?q?=E4=B8=ADkickOutForUsername=E7=9A=84@Async=E6=B3=A8=E8=A7=A3=20?= =?UTF-8?q?close=20https://github.com/elunez/eladmin-mp/issues/43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/modules/security/service/OnlineUserService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java index ede78681..d1fd765d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java @@ -141,7 +141,6 @@ public class OnlineUserService { * 根据用户名强退用户 * @param username / */ - @Async public void kickOutForUsername(String username) { String loginKey = properties.getOnlineKey() + username + "*"; redisUtils.scanDel(loginKey); From ba5b42bde7ae05cf0de5f4318a1ef1501b18a358 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Sun, 29 Dec 2024 10:44:50 +0800 Subject: [PATCH 07/14] update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 084873ab..615ec89d 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,12 @@ | github | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web | | 码云 | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web | -#### 赞助商 | Sponsor +#### VPS推荐 + + + - -明道云零代码构建平台 +使用优惠码: `BWHCGLUKKB`,可获得 6.81% 的折扣 [查看介绍](https://bwhstock.in/) #### 主要特性 - 使用最新技术栈,社区资源丰富。 From 6159b94c90854c34a52b5031ef60f51ccc2cc818 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Mon, 13 Jan 2025 18:30:20 +0800 Subject: [PATCH 08/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DEncryptUtils?= =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E7=8E=AF=E5=A2=83=E4=B8=AD=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E5=90=8C=E4=B8=80=E4=B8=AA=20Cipher=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E3=80=90=20Cipher=20not=20initialized?= =?UTF-8?q?=E3=80=91=E7=9A=84=E9=97=AE=E9=A2=98=20close=20https://github.c?= =?UTF-8?q?om/elunez/eladmin/issues/865?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/zhengjie/utils/EncryptUtils.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java index 4f334aac..191fdbbe 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/EncryptUtils.java @@ -27,20 +27,15 @@ import java.nio.charset.StandardCharsets; * @author Zheng Jie * @date 2018-11-23 */ - public class EncryptUtils { private static final String STR_PARAM = "Passw0rd"; - - private static Cipher cipher; - private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8)); private static DESKeySpec getDesKeySpec(String source) throws Exception { - if (source == null || source.length() == 0){ + if (source == null || source.isEmpty()) { return null; } - cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); String strKey = "Passw0rd"; return new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8)); } @@ -49,18 +44,19 @@ public class EncryptUtils { * 对称加密 */ public static String desEncrypt(String source) throws Exception { + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); DESKeySpec desKeySpec = getDesKeySpec(source); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey secretKey = keyFactory.generateSecret(desKeySpec); cipher.init(Cipher.ENCRYPT_MODE, secretKey, IV); - return byte2hex( - cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase(); + return byte2hex(cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase(); } /** * 对称解密 */ public static String desDecrypt(String source) throws Exception { + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); byte[] src = hex2byte(source.getBytes(StandardCharsets.UTF_8)); DESKeySpec desKeySpec = getDesKeySpec(source); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); @@ -76,7 +72,6 @@ public class EncryptUtils { for (byte b : inStr) { stmp = Integer.toHexString(b & 0xFF); if (stmp.length() == 1) { - // 如果是0至F的单位字符串,则添加0 out.append("0").append(stmp); } else { out.append(stmp); @@ -87,7 +82,7 @@ public class EncryptUtils { private static byte[] hex2byte(byte[] b) { int size = 2; - if ((b.length % size) != 0){ + if ((b.length % size) != 0) { throw new IllegalArgumentException("长度不是偶数"); } byte[] b2 = new byte[b.length / 2]; From d6a16e9afc0a3b96a56f1a24ed167e1beec6ce2f Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 09:21:51 +0800 Subject: [PATCH 09/14] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2CSV=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=EF=BC=8C=E5=A4=84=E7=90=86=E5=AF=BC=E5=87=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/863 --- .../main/java/me/zhengjie/utils/FileUtil.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java index ca2b674d..1761fc80 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java @@ -33,8 +33,10 @@ import java.security.MessageDigest; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * File工具类,扩展 hutool 工具包 @@ -213,8 +215,25 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; File file = new File(tempPath); BigExcelWriter writer = ExcelUtil.getBigWriter(file); + // 处理数据以防止CSV注入 + List> sanitizedList = list.parallelStream().map(map -> { + Map sanitizedMap = new HashMap<>(); + map.forEach((key, value) -> { + if (value instanceof String) { + String strValue = (String) value; + // 检查并处理以特殊字符开头的值 + if (strValue.startsWith("=") || strValue.startsWith("+") || strValue.startsWith("-") || strValue.startsWith("@")) { + strValue = "'" + strValue; // 添加单引号前缀 + } + sanitizedMap.put(key, strValue); + } else { + sanitizedMap.put(key, value); + } + }); + return sanitizedMap; + }).collect(Collectors.toList()); // 一次性写出内容,使用默认样式,强制输出标题 - writer.write(list, true); + writer.write(sanitizedList, true); SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); //上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法 sheet.trackAllColumnsForAutoSizing(); From a14d2c43242c42cb89fe9e4abc05e7840d2dc198 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 09:26:29 +0800 Subject: [PATCH 10/14] =?UTF-8?q?fix(LimitAspect):=20=E4=BD=BF=E7=94=A8Obj?= =?UTF-8?q?Util=E4=BC=98=E5=8C=96=E7=A9=BA=E5=80=BC=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/zhengjie/aspect/LimitAspect.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java b/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java index 4b9a7b8e..63fb8211 100644 --- a/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java +++ b/eladmin-common/src/main/java/me/zhengjie/aspect/LimitAspect.java @@ -15,6 +15,7 @@ */ package me.zhengjie.aspect; +import cn.hutool.core.util.ObjUtil; import com.google.common.collect.ImmutableList; import me.zhengjie.annotation.Limit; import me.zhengjie.exception.BadRequestException; @@ -73,7 +74,7 @@ public class LimitAspect { String luaScript = buildLuaScript(); RedisScript redisScript = new DefaultRedisScript<>(luaScript, Long.class); Long count = redisTemplate.execute(redisScript, keys, limit.count(), limit.period()); - if (null != count && count.intValue() <= limit.count()) { + if (ObjUtil.isNotNull(count) && count.intValue() <= limit.count()) { logger.info("第{}次访问key为 {},描述为 [{}] 的接口", count, keys, limit.name()); return joinPoint.proceed(); } else { From 5a3786bd03d33bd015334767e4bfcaa4416842cc Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 10:09:27 +0800 Subject: [PATCH 11/14] =?UTF-8?q?update:=20=E5=8D=87=E7=BA=A7hutool?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=87=B35.8.21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-common/pom.xml b/eladmin-common/pom.xml index 23d1024e..dd010d62 100644 --- a/eladmin-common/pom.xml +++ b/eladmin-common/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - 5.8.20 + 5.8.21 eladmin-common From 008181b0798e233662b49732345b0e498b013868 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 10:30:39 +0800 Subject: [PATCH 12/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=90?= =?UTF-8?q?=E7=BB=B4=E7=AE=A1=E7=90=86=EF=BC=9A=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E7=BD=B2=E7=AE=A1=E7=90=86=E4=B8=AD=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E4=BB=BB=E6=84=8F=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E6=BC=8F=E6=B4=9E=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=9D=9E=E6=B3=95=E6=96=87=E4=BB=B6=E5=90=8D=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=20close=20https://github.com/elunez/eladmin/issues/85?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/mnt/rest/DatabaseController.java | 4 ++-- .../modules/mnt/rest/DeployController.java | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DatabaseController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DatabaseController.java index 0ce1a4e8..ded799d3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DatabaseController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DatabaseController.java @@ -111,8 +111,8 @@ public class DatabaseController { DatabaseDto database = databaseService.findById(id); String fileName; if(database != null){ - fileName = file.getOriginalFilename(); - File executeFile = new File(fileSavePath+fileName); + fileName = FileUtil.verifyFilename(file.getOriginalFilename()); + File executeFile = new File(fileSavePath + fileName); FileUtil.del(executeFile); file.transferTo(executeFile); String result = SqlUtils.executeFile(database.getJdbcUrl(), database.getUserName(), database.getPwd(), executeFile); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java index 3f13813b..161e7b5d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java @@ -18,6 +18,7 @@ package me.zhengjie.modules.mnt.rest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.Log; import me.zhengjie.modules.mnt.domain.Deploy; import me.zhengjie.modules.mnt.domain.DeployHistory; @@ -39,13 +40,13 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Set; /** * @author zhanghouying * @date 2019-08-24 */ +@Slf4j @RestController @Api(tags = "运维:部署管理") @RequiredArgsConstructor @@ -67,7 +68,7 @@ public class DeployController { @GetMapping @PreAuthorize("@el.check('deploy:list')") public ResponseEntity> queryDeployData(DeployQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK); + return new ResponseEntity<>(deployService.queryAll(criteria,pageable),HttpStatus.OK); } @Log("新增部署") @@ -105,21 +106,21 @@ public class DeployController { Long id = Long.valueOf(request.getParameter("id")); String fileName = ""; if(file != null){ - fileName = file.getOriginalFilename(); - File deployFile = new File(fileSavePath+fileName); + fileName = FileUtil.verifyFilename(file.getOriginalFilename()); + File deployFile = new File(fileSavePath + fileName); FileUtil.del(deployFile); file.transferTo(deployFile); //文件下一步要根据文件名字来 - deployService.deploy(fileSavePath+fileName ,id); + deployService.deploy(fileSavePath + fileName ,id); }else{ - System.out.println("没有找到相对应的文件"); + log.warn("没有找到相对应的文件"); } - System.out.println("文件上传的原名称为:"+ Objects.requireNonNull(file).getOriginalFilename()); Map map = new HashMap<>(2); - map.put("errno",0); + map.put("error",0); map.put("id",fileName); return new ResponseEntity<>(map,HttpStatus.OK); } + @Log("系统还原") @ApiOperation(value = "系统还原") @PostMapping(value = "/serverReduction") @@ -128,14 +129,16 @@ public class DeployController { String result = deployService.serverReduction(resources); return new ResponseEntity<>(result,HttpStatus.OK); } + @Log("服务运行状态") @ApiOperation(value = "服务运行状态") @PostMapping(value = "/serverStatus") @PreAuthorize("@el.check('deploy:edit')") public ResponseEntity serverStatus(@Validated @RequestBody Deploy resources){ String result = deployService.serverStatus(resources); - return new ResponseEntity<>(result,HttpStatus.OK); + return new ResponseEntity<>(result,HttpStatus.OK); } + @Log("启动服务") @ApiOperation(value = "启动服务") @PostMapping(value = "/startServer") @@ -144,6 +147,7 @@ public class DeployController { String result = deployService.startServer(resources); return new ResponseEntity<>(result,HttpStatus.OK); } + @Log("停止服务") @ApiOperation(value = "停止服务") @PostMapping(value = "/stopServer") From 13ae86ad15aa7994e5817a016450291d672b0820 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 10:37:18 +0800 Subject: [PATCH 13/14] update --- .../modules/mnt/domain/DeployHistory.java | 14 ++++---- .../modules/mnt/rest/AppController.java | 10 +++--- .../mnt/rest/DeployHistoryController.java | 4 +-- .../mnt/rest/ServerDeployController.java | 26 +++++++-------- .../service/impl/ServerDeployServiceImpl.java | 32 +++++++++---------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java index 6e07e136..b4213a41 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java @@ -37,24 +37,24 @@ public class DeployHistory implements Serializable { @Id @Column(name = "history_id") - @ApiModelProperty(value = "ID", hidden = true) + @ApiModelProperty(value = "ID", hidden = true) private String id; @ApiModelProperty(value = "应用名称") private String appName; - @ApiModelProperty(value = "IP") + @ApiModelProperty(value = "IP") private String ip; - @CreationTimestamp - @ApiModelProperty(value = "部署时间") + @CreationTimestamp + @ApiModelProperty(value = "部署时间") private Timestamp deployDate; - @ApiModelProperty(value = "部署者") + @ApiModelProperty(value = "部署者") private String deployUser; - @ApiModelProperty(value = "部署ID") - private Long deployId; + @ApiModelProperty(value = "部署ID") + private Long deployId; public void copy(DeployHistory source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java index 5dac15eb..96cfbed3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java @@ -55,7 +55,7 @@ public class AppController { @ApiOperation(value = "查询应用") @GetMapping - @PreAuthorize("@el.check('app:list')") + @PreAuthorize("@el.check('app:list')") public ResponseEntity> queryApp(AppQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(appService.queryAll(criteria,pageable),HttpStatus.OK); } @@ -63,7 +63,7 @@ public class AppController { @Log("新增应用") @ApiOperation(value = "新增应用") @PostMapping - @PreAuthorize("@el.check('app:add')") + @PreAuthorize("@el.check('app:add')") public ResponseEntity createApp(@Validated @RequestBody App resources){ appService.create(resources); return new ResponseEntity<>(HttpStatus.CREATED); @@ -72,7 +72,7 @@ public class AppController { @Log("修改应用") @ApiOperation(value = "修改应用") @PutMapping - @PreAuthorize("@el.check('app:edit')") + @PreAuthorize("@el.check('app:edit')") public ResponseEntity updateApp(@Validated @RequestBody App resources){ appService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -80,8 +80,8 @@ public class AppController { @Log("删除应用") @ApiOperation(value = "删除应用") - @DeleteMapping - @PreAuthorize("@el.check('app:del')") + @DeleteMapping + @PreAuthorize("@el.check('app:del')") public ResponseEntity deleteApp(@RequestBody Set ids){ appService.delete(ids); return new ResponseEntity<>(HttpStatus.OK); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java index 8d3c902d..60ee88c4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployHistoryController.java @@ -53,14 +53,14 @@ public class DeployHistoryController { @ApiOperation(value = "查询部署历史") @GetMapping - @PreAuthorize("@el.check('deployHistory:list')") + @PreAuthorize("@el.check('deployHistory:list')") public ResponseEntity> queryDeployHistory(DeployHistoryQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK); } @Log("删除DeployHistory") @ApiOperation(value = "删除部署历史") - @DeleteMapping + @DeleteMapping @PreAuthorize("@el.check('deployHistory:del')") public ResponseEntity deleteDeployHistory(@RequestBody Set ids){ deployhistoryService.delete(ids); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java index 5ccb0ed3..f4c60f42 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java @@ -55,15 +55,15 @@ public class ServerDeployController { @ApiOperation(value = "查询服务器") @GetMapping - @PreAuthorize("@el.check('serverDeploy:list')") + @PreAuthorize("@el.check('serverDeploy:list')") public ResponseEntity> queryServerDeploy(ServerDeployQueryCriteria criteria, Pageable pageable){ - return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK); + return new ResponseEntity<>(serverDeployService.queryAll(criteria,pageable),HttpStatus.OK); } @Log("新增服务器") @ApiOperation(value = "新增服务器") @PostMapping - @PreAuthorize("@el.check('serverDeploy:add')") + @PreAuthorize("@el.check('serverDeploy:add')") public ResponseEntity createServerDeploy(@Validated @RequestBody ServerDeploy resources){ serverDeployService.create(resources); return new ResponseEntity<>(HttpStatus.CREATED); @@ -72,7 +72,7 @@ public class ServerDeployController { @Log("修改服务器") @ApiOperation(value = "修改服务器") @PutMapping - @PreAuthorize("@el.check('serverDeploy:edit')") + @PreAuthorize("@el.check('serverDeploy:edit')") public ResponseEntity updateServerDeploy(@Validated @RequestBody ServerDeploy resources){ serverDeployService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -80,18 +80,18 @@ public class ServerDeployController { @Log("删除服务器") @ApiOperation(value = "删除Server") - @DeleteMapping - @PreAuthorize("@el.check('serverDeploy:del')") + @DeleteMapping + @PreAuthorize("@el.check('serverDeploy:del')") public ResponseEntity deleteServerDeploy(@RequestBody Set ids){ serverDeployService.delete(ids); return new ResponseEntity<>(HttpStatus.OK); } - @Log("测试连接服务器") - @ApiOperation(value = "测试连接服务器") - @PostMapping("/testConnect") - @PreAuthorize("@el.check('serverDeploy:add')") - public ResponseEntity testConnectServerDeploy(@Validated @RequestBody ServerDeploy resources){ - return new ResponseEntity<>(serverDeployService.testConnect(resources),HttpStatus.CREATED); - } + @Log("测试连接服务器") + @ApiOperation(value = "测试连接服务器") + @PostMapping("/testConnect") + @PreAuthorize("@el.check('serverDeploy:add')") + public ResponseEntity testConnectServerDeploy(@Validated @RequestBody ServerDeploy resources){ + return new ResponseEntity<>(serverDeployService.testConnect(resources),HttpStatus.CREATED); + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java index 9e25eb4a..24b29e0e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java @@ -67,22 +67,22 @@ public class ServerDeployServiceImpl implements ServerDeployService { return serverDeployMapper.toDto(deploy); } - @Override - public Boolean testConnect(ServerDeploy resources) { - ExecuteShellUtil executeShellUtil = null; - try { - executeShellUtil = new ExecuteShellUtil(resources.getIp(), resources.getAccount(), resources.getPassword(),resources.getPort()); - return executeShellUtil.execute("ls")==0; - } catch (Exception e) { - return false; - }finally { - if (executeShellUtil != null) { - executeShellUtil.close(); - } - } - } + @Override + public Boolean testConnect(ServerDeploy resources) { + ExecuteShellUtil executeShellUtil = null; + try { + executeShellUtil = new ExecuteShellUtil(resources.getIp(), resources.getAccount(), resources.getPassword(),resources.getPort()); + return executeShellUtil.execute("ls")==0; + } catch (Exception e) { + return false; + }finally { + if (executeShellUtil != null) { + executeShellUtil.close(); + } + } + } - @Override + @Override @Transactional(rollbackFor = Exception.class) public void create(ServerDeploy resources) { serverDeployRepository.save(resources); @@ -93,7 +93,7 @@ public class ServerDeployServiceImpl implements ServerDeployService { public void update(ServerDeploy resources) { ServerDeploy serverDeploy = serverDeployRepository.findById(resources.getId()).orElseGet(ServerDeploy::new); ValidationUtil.isNull( serverDeploy.getId(),"ServerDeploy","id",resources.getId()); - serverDeploy.copy(resources); + serverDeploy.copy(resources); serverDeployRepository.save(serverDeploy); } From c62ac4c38350d0001ac7ca7489f47633f539b17e Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 15 Jan 2025 11:05:47 +0800 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0JDBC=20URL?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=8F=82=E6=95=B0=E8=BF=87=E6=BB=A4=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2SQL=E6=B3=A8=E5=85=A5=E7=AD=89=E6=BC=8F?= =?UTF-8?q?=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/839 --- .../mnt/service/impl/DatabaseServiceImpl.java | 18 +++++------ .../zhengjie/modules/mnt/util/SqlUtils.java | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DatabaseServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DatabaseServiceImpl.java index fa55782e..386b4c29 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DatabaseServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DatabaseServiceImpl.java @@ -88,15 +88,15 @@ public class DatabaseServiceImpl implements DatabaseService { } } - @Override - public boolean testConnection(Database resources) { - try { - return SqlUtils.testConnection(resources.getJdbcUrl(), resources.getUserName(), resources.getPwd()); - } catch (Exception e) { - log.error(e.getMessage()); - return false; - } - } + @Override + public boolean testConnection(Database resources) { + try { + return SqlUtils.testConnection(resources.getJdbcUrl(), resources.getUserName(), resources.getPwd()); + } catch (Exception e) { + log.error(e.getMessage()); + return false; + } + } @Override public void download(List queryAll, HttpServletResponse response) throws IOException { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/SqlUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/SqlUtils.java index d7e06b17..0e867af5 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/SqlUtils.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/SqlUtils.java @@ -61,6 +61,8 @@ public class SqlUtils { druidDataSource.setDriverClassName(className); } + // 去掉不安全的参数 + jdbcUrl = sanitizeJdbcUrl(jdbcUrl); druidDataSource.setUrl(jdbcUrl); druidDataSource.setUsername(userName); @@ -198,4 +200,33 @@ public class SqlUtils { return sqlList; } + /** + * 去除不安全的参数 + * @param jdbcUrl / + * @return / + */ + private static String sanitizeJdbcUrl(String jdbcUrl) { + // 定义不安全参数和其安全替代值 + String[][] unsafeParams = { + // allowLoadLocalInfile:允许使用 LOAD DATA LOCAL INFILE,可能导致文件泄露 + {"allowLoadLocalInfile", "false"}, + // allowUrlInLocalInfile:允许在 LOAD DATA LOCAL INFILE 中使用 URL,可能导致未经授权的文件访问 + {"allowUrlInLocalInfile", "false"}, + // autoDeserialize:允许自动反序列化对象,可能导致反序列化漏洞 + {"autoDeserialize", "false"}, + // allowNanAndInf:允许使用 NaN 和 Infinity 作为数字值,可能导致不一致的数据处理 + {"allowNanAndInf", "false"}, + // allowMultiQueries:允许在一个语句中执行多个查询,可能导致 SQL 注入攻击 + {"allowMultiQueries", "false"}, + // allowPublicKeyRetrieval:允许从服务器检索公钥,可能导致中间人攻击 + {"allowPublicKeyRetrieval", "false"} + }; + + // 替换不安全的参数 + for (String[] param : unsafeParams) { + jdbcUrl = jdbcUrl.replaceAll("(?i)" + param[0] + "=true", param[0] + "=" + param[1]); + } + return jdbcUrl; + } + }