From fdf82d2479dbfbd2a68cc8ebb8a409279edef3e7 Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Fri, 29 Jan 2021 15:04:37 +0800 Subject: [PATCH 01/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9A=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E9=82=AE=E7=AE=B1=E4=BC=98=E5=8C=96=EF=BC=8C=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E4=B8=BA=E7=A9=BA=E4=B8=8D=E8=B0=83=E7=94=A8=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/modules/quartz/utils/ExecutionJob.java | 7 ++++--- pom.xml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java index 798f9c35..8e261850 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java @@ -42,7 +42,6 @@ import java.util.concurrent.*; * @date 2019-01-07 */ @Async -@SuppressWarnings({"unchecked","all"}) public class ExecutionJob extends QuartzJobBean { /** 该处仅供参考 */ @@ -108,8 +107,10 @@ public class ExecutionJob extends QuartzJobBean { if(quartzJob.getEmail() != null){ EmailService emailService = SpringContextHolder.getBean(EmailService.class); // 邮箱报警 - EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e)); - emailService.send(emailVo, emailService.find()); + if(StringUtils.isNoneBlank(quartzJob.getEmail())){ + EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e)); + emailService.send(emailVo, emailService.find()); + } } } finally { quartzLogRepository.save(log); diff --git a/pom.xml b/pom.xml index b8fe4a46..a69c5d0d 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 1.16 2.9.2 1.2.70 - 1.1.22 + 1.1.24 2.5.0 1.3.1.Final From 0b83ca0646f9c983a3958c88d1e79c527c644a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9A=86=E9=9D=9E?= <53246310+jiefei30@users.noreply.github.com> Date: Sun, 31 Jan 2021 14:15:21 +0800 Subject: [PATCH 02/15] fix findByDeptRoleId sql in UserRepository when delete dept cache (#572) --- .../zhengjie/modules/system/repository/UserRepository.java | 6 +++--- .../modules/system/service/impl/DeptServiceImpl.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java index 99ea5afc..c5c88a8d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java @@ -81,12 +81,12 @@ public interface UserRepository extends JpaRepository, JpaSpecificat /** * 根据角色中的部门查询 - * @param id / + * @param deptId / * @return / */ @Query(value = "SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d WHERE " + - "u.user_id = r.user_id AND r.role_id = d.role_id AND r.role_id = ?1 group by u.user_id", nativeQuery = true) - List findByDeptRoleId(Long id); + "u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = ?1 group by u.user_id", nativeQuery = true) + List findByRoleDeptId(Long deptId); /** * 根据菜单查询 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java index 12c13fed..8c7c331a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java @@ -273,7 +273,7 @@ public class DeptServiceImpl implements DeptService { * @param id / */ public void delCaches(Long id){ - List users = userRepository.findByDeptRoleId(id); + List users = userRepository.findByRoleDeptId(id); // 删除数据权限 redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet())); redisUtils.del(CacheKey.DEPT_ID + id); From 5381ac38ce941cd8c8df9b9f0b4744a674bd255f Mon Sep 17 00:00:00 2001 From: sick-cat <31824316+sick-cat@users.noreply.github.com> Date: Sun, 31 Jan 2021 14:16:21 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=EF=BC=8C=E6=89=BE=E4=B8=8D=E5=88=B0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E3=80=82=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=20(#580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yanzhao.jia --- eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java | 2 +- 1 file changed, 1 insertion(+), 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 10ccd712..bf23eff9 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java @@ -95,7 +95,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { File file = null; try { // 用uuid作为文件名,防止生成的临时文件重复 - file = File.createTempFile(IdUtil.simpleUUID(), prefix); + file = new File(SYS_TEM_DIR + IdUtil.simpleUUID() + prefix); // MultipartFile to File multipartFile.transferTo(file); } catch (IOException e) { From e4e318aa4e090199a97228cb1d9f3048550623a4 Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Mon, 1 Feb 2021 20:51:16 +0800 Subject: [PATCH 04/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9Adruid=20=E9=85=8D=E7=BD=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/config/application-dev.yml | 15 +++++++++++---- .../main/resources/config/application-prod.yml | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/eladmin-system/src/main/resources/config/application-dev.yml b/eladmin-system/src/main/resources/config/application-dev.yml index 65d5aa71..c8bf11f1 100644 --- a/eladmin-system/src/main/resources/config/application-dev.yml +++ b/eladmin-system/src/main/resources/config/application-dev.yml @@ -10,19 +10,26 @@ spring: # 初始连接数 initial-size: 5 # 最小连接数 - min-idle: 10 + min-idle: 15 # 最大连接数 - max-active: 20 + max-active: 30 + # 是否自动回收超时连接 + remove-abandoned: true + # 超时时间(以秒数为单位) + remove-abandoned-timeout: 180 # 获取连接超时时间 - max-wait: 5000 + max-wait: 3000 # 连接有效性检测时间 time-between-eviction-runs-millis: 60000 # 连接在池中最小生存的时间 min-evictable-idle-time-millis: 300000 # 连接在池中最大生存的时间 max-evictable-idle-time-millis: 900000 + # 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除 test-while-idle: true - test-on-borrow: false + # 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个 + test-on-borrow: true + # 是否在归还到池中前进行检验 test-on-return: false # 检测连接是否有效 validation-query: select 1 diff --git a/eladmin-system/src/main/resources/config/application-prod.yml b/eladmin-system/src/main/resources/config/application-prod.yml index ced1f592..4b513e22 100644 --- a/eladmin-system/src/main/resources/config/application-prod.yml +++ b/eladmin-system/src/main/resources/config/application-prod.yml @@ -10,9 +10,9 @@ spring: # 初始连接数 initial-size: 5 # 最小连接数 - min-idle: 10 + min-idle: 15 # 最大连接数 - max-active: 20 + max-active: 30 # 获取连接超时时间 max-wait: 5000 # 连接有效性检测时间 @@ -21,8 +21,11 @@ spring: min-evictable-idle-time-millis: 300000 # 连接在池中最大生存的时间 max-evictable-idle-time-millis: 900000 + # 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除 test-while-idle: true - test-on-borrow: false + # 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个 + test-on-borrow: true + # 是否在归还到池中前进行检验 test-on-return: false # 检测连接是否有效 validation-query: select 1 @@ -31,6 +34,7 @@ spring: enabled: true stat-view-servlet: enabled: true + # 控制台管理用户名和密码 url-pattern: /druid/* reset-enable: false login-username: admin From c968eb36ef15d886c6529973a52ef8ff540c1c95 Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Wed, 3 Feb 2021 09:47:02 +0800 Subject: [PATCH 05/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9A=E4=BF=AE=E6=AD=A3=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6[login-code:=20height]=E6=8B=BC=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/security/config/ConfigBeanConfiguration.java | 4 ++-- .../me/zhengjie/modules/security/config/bean/LoginCode.java | 4 ++-- .../modules/security/config/bean/LoginProperties.java | 1 + eladmin-system/src/main/resources/config/application-dev.yml | 2 +- eladmin-system/src/main/resources/config/application-prod.yml | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/ConfigBeanConfiguration.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/ConfigBeanConfiguration.java index fde89507..8cbc88dd 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/ConfigBeanConfiguration.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/ConfigBeanConfiguration.java @@ -30,13 +30,13 @@ import org.springframework.context.annotation.Configuration; public class ConfigBeanConfiguration { @Bean - @ConfigurationProperties(prefix = "login", ignoreUnknownFields = true) + @ConfigurationProperties(prefix = "login") public LoginProperties loginProperties() { return new LoginProperties(); } @Bean - @ConfigurationProperties(prefix = "jwt", ignoreUnknownFields = true) + @ConfigurationProperties(prefix = "jwt") public SecurityProperties securityProperties() { return new SecurityProperties(); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginCode.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginCode.java index 99660787..fefd252b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginCode.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginCode.java @@ -20,8 +20,8 @@ import lombok.Data; /** * 登录验证码配置信息 * - * @author: liaojinlong - * @date: 2020/6/10 18:53 + * @author liaojinlong + * @date 2020/6/10 18:53 */ @Data public class LoginCode { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java index a609f5c9..ca57213a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java @@ -39,6 +39,7 @@ public class LoginProperties { private boolean singleLogin = false; private LoginCode loginCode; + /** * 用户登录信息缓存 */ diff --git a/eladmin-system/src/main/resources/config/application-dev.yml b/eladmin-system/src/main/resources/config/application-dev.yml index c8bf11f1..d3fbf517 100644 --- a/eladmin-system/src/main/resources/config/application-dev.yml +++ b/eladmin-system/src/main/resources/config/application-dev.yml @@ -66,7 +66,7 @@ login: # 验证码高度 width: 111 # 验证码宽度 - heigth: 36 + height: 36 # 内容长度 length: 2 # 字体名称,为空则使用默认字体 diff --git a/eladmin-system/src/main/resources/config/application-prod.yml b/eladmin-system/src/main/resources/config/application-prod.yml index 4b513e22..52e52ddf 100644 --- a/eladmin-system/src/main/resources/config/application-prod.yml +++ b/eladmin-system/src/main/resources/config/application-prod.yml @@ -65,7 +65,7 @@ login: # 验证码高度 width: 111 # 验证码宽度 - heigth: 36 + height: 36 # 内容长度 length: 2 # 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可 From 0dfdcf11e8704ba62865b0c2fe872336d0e33386 Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Mon, 8 Feb 2021 20:57:44 +0800 Subject: [PATCH 06/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9A=E4=BF=AE=E5=A4=8D=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-tools/pom.xml | 2 +- .../main/java/me/zhengjie/service/impl/EmailServiceImpl.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eladmin-tools/pom.xml b/eladmin-tools/pom.xml index 61b1f6d0..4bbf9f4c 100644 --- a/eladmin-tools/pom.xml +++ b/eladmin-tools/pom.xml @@ -13,7 +13,7 @@ 工具模块 - 1.5.0-b01 + 1.4.7 [7.2.0, 7.2.99] 4.9.153.ALL diff --git a/eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java b/eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java index a71628e3..c98c76ec 100644 --- a/eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java +++ b/eladmin-tools/src/main/java/me/zhengjie/service/impl/EmailServiceImpl.java @@ -69,7 +69,9 @@ public class EmailServiceImpl implements EmailService { } // 封装 MailAccount account = new MailAccount(); - account.setUser(emailConfig.getUser()); + // 设置用户 + String user = emailConfig.getFromUser().split("@")[0]; + account.setUser(user); account.setHost(emailConfig.getHost()); account.setPort(Integer.parseInt(emailConfig.getPort())); account.setAuth(true); From 7b0caae907253b5735475f3a8f99a69ce400bede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= Date: Mon, 1 Mar 2021 19:04:47 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E9=94=99=E5=88=AB=E5=AD=97=E6=9B=B4?= =?UTF-8?q?=E6=AD=A3=20(#590)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/eladmin.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/eladmin.sql b/sql/eladmin.sql index 1cc6ff7e..00234d29 100644 --- a/sql/eladmin.sql +++ b/sql/eladmin.sql @@ -660,7 +660,7 @@ CREATE TABLE `sys_user` ( `is_admin` bit(1) DEFAULT b'0' COMMENT '是否为admin账号', `enabled` bigint(20) DEFAULT NULL COMMENT '状态:1启用、0禁用', `create_by` varchar(255) DEFAULT NULL COMMENT '创建者', - `update_by` varchar(255) DEFAULT NULL COMMENT '更新着', + `update_by` varchar(255) DEFAULT NULL COMMENT '更新者', `pwd_reset_time` datetime DEFAULT NULL COMMENT '修改密码的时间', `create_time` datetime DEFAULT NULL COMMENT '创建日期', `update_time` datetime DEFAULT NULL COMMENT '更新时间', @@ -822,4 +822,4 @@ CREATE TABLE `tool_qiniu_content` ( BEGIN; COMMIT; -SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file +SET FOREIGN_KEY_CHECKS = 1; From 8bb800c68e0a69a4220ec15cfb085a1b8f889f61 Mon Sep 17 00:00:00 2001 From: lWoHvYe <39266195+lWoHvYe@users.noreply.github.com> Date: Mon, 1 Mar 2021 19:07:56 +0800 Subject: [PATCH 08/15] =?UTF-8?q?Spring=20Boot=E7=89=88=E6=9C=AC=E5=8D=87?= =?UTF-8?q?=E7=BA=A72.2.10=EF=BC=8C=E8=A7=A3=E5=86=B3in=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BC=A0null=E6=97=B6=E6=8A=A5=E9=94=99=E3=80=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4Swagger=E4=B8=ADtoken=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=20(#595)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Spring Boot版本调整为2.2.10。在此前的版本,若in 查询传入null,会报错。相关sql 为in ()。在2.2版本修复了此问题,相关sql改为 in (null)。鉴于此,建议进行升级。 * Spring Boot依赖升级后,Sort的设置方式调整。由 new Sort()改为 Sort.by() * 调整接口文档Swagger中,token的设置方式,由每个接口单独设置,改为设置统一的token,日常测试更加方便 --- .../me/zhengjie/config/SwaggerConfig.java | 67 ++++++++++++++----- .../system/service/impl/DeptServiceImpl.java | 4 +- .../system/service/impl/MenuServiceImpl.java | 2 +- .../system/service/impl/RoleServiceImpl.java | 2 +- pom.xml | 2 +- 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java index e5e16216..54e47cbd 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java @@ -16,7 +16,6 @@ package me.zhengjie.config; import com.fasterxml.classmate.TypeResolver; -import com.google.common.base.Predicates; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -26,18 +25,18 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.data.domain.Pageable; import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.schema.AlternateTypeRule; import springfox.documentation.schema.AlternateTypeRuleConvention; -import springfox.documentation.schema.ModelRef; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Parameter; +import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; + import java.util.ArrayList; import java.util.List; + import static com.google.common.collect.Lists.newArrayList; import static springfox.documentation.schema.AlternateTypeRules.newRule; @@ -62,22 +61,26 @@ public class SwaggerConfig { @Bean @SuppressWarnings("all") public Docket createRestApi() { - ParameterBuilder ticketPar = new ParameterBuilder(); - List pars = new ArrayList<>(); - ticketPar.name(tokenHeader).description("token") - .modelRef(new ModelRef("string")) - .parameterType("header") - .defaultValue(tokenStartWith + " ") - .required(true) - .build(); - pars.add(ticketPar.build()); +// ParameterBuilder ticketPar = new ParameterBuilder(); +//// List pars = new ArrayList<>(); +//// ticketPar.name(tokenHeader).description("token") +//// .modelRef(new ModelRef("string")) +//// .parameterType("header") +//// .defaultValue(tokenStartWith + " ") +//// .required(true) +//// .build(); +// pars.add(ticketPar.build()); return new Docket(DocumentationType.SWAGGER_2) .enable(enabled) .apiInfo(apiInfo()) .select() - .paths(Predicates.not(PathSelectors.regex("/error.*"))) +// .paths(Predicates.not(PathSelectors.regex("/error.*"))) + .paths(PathSelectors.any()) .build() - .globalOperationParameters(pars); +// .globalOperationParameters(pars) + //添加登陆认证 + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()); } private ApiInfo apiInfo() { @@ -88,6 +91,38 @@ public class SwaggerConfig { .build(); } + private List securitySchemes() { + //设置请求头信息 + List securitySchemes = new ArrayList<>(); + ApiKey apiKey = new ApiKey(tokenHeader, tokenHeader, "header"); + securitySchemes.add(apiKey); + return securitySchemes; + } + + private List securityContexts() { + //设置需要登录认证的路径 + List securityContexts = new ArrayList<>(); + // ^(?!auth).*$ 表示所有包含auth的接口不需要使用securitySchemes即不需要带token + // ^标识开始 ()里是一子表达式 ?!/auth表示匹配不是/auth的位置,匹配上则添加请求头,注意路径已/开头 .表示任意字符 *表示前面的字符匹配多次 $标识结束 + securityContexts.add(getContextByPath("^(?!/auth).*$")); + return securityContexts; + } + + private SecurityContext getContextByPath(String pathRegex) { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex(pathRegex)) + .build(); + } + + private List defaultAuth() { + List securityReferences = new ArrayList<>(); + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + securityReferences.add(new SecurityReference(tokenHeader, authorizationScopes)); + return securityReferences; + } } /** diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java index 8c7c331a..657a6074 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java @@ -58,7 +58,7 @@ public class DeptServiceImpl implements DeptService { @Override public List queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception { - Sort sort = new Sort(Sort.Direction.ASC, "deptSort"); + Sort sort = Sort.by(Sort.Direction.ASC, "deptSort"); String dataScopeType = SecurityUtils.getDataScopeType(); if (isQuery) { if(dataScopeType.equals(DataScopeEnum.ALL.getValue())){ @@ -278,4 +278,4 @@ public class DeptServiceImpl implements DeptService { redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet())); redisUtils.del(CacheKey.DEPT_ID + id); } -} \ No newline at end of file +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java index c7e45499..0e54fc92 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java @@ -61,7 +61,7 @@ public class MenuServiceImpl implements MenuService { @Override public List queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception { - Sort sort = new Sort(Sort.Direction.ASC, "menuSort"); + Sort sort = Sort.by(Sort.Direction.ASC, "menuSort"); if(isQuery){ criteria.setPidIsNull(true); List fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>()); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java index f8690229..e8b41438 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java @@ -66,7 +66,7 @@ public class RoleServiceImpl implements RoleService { @Override public List queryAll() { - Sort sort = new Sort(Sort.Direction.ASC, "level"); + Sort sort = Sort.by(Sort.Direction.ASC, "level"); return roleMapper.toDto(roleRepository.findAll(sort)); } diff --git a/pom.xml b/pom.xml index a69c5d0d..0b8a4062 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.0.RELEASE + 2.2.10.RELEASE From a1e8005499c7d9009d3fdd5821fd145eb52c8d26 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Mon, 1 Mar 2021 19:35:10 +0800 Subject: [PATCH 09/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9Aupdate=20swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/config/SwaggerConfig.java | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java index 54e47cbd..50343bcb 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java @@ -16,6 +16,7 @@ package me.zhengjie.config; import com.fasterxml.classmate.TypeResolver; +import com.google.common.base.Predicates; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -33,10 +34,8 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; - import java.util.ArrayList; import java.util.List; - import static com.google.common.collect.Lists.newArrayList; import static springfox.documentation.schema.AlternateTypeRules.newRule; @@ -52,32 +51,20 @@ public class SwaggerConfig { @Value("${jwt.header}") private String tokenHeader; - @Value("${jwt.token-start-with}") - private String tokenStartWith; - @Value("${swagger.enabled}") private Boolean enabled; @Bean @SuppressWarnings("all") public Docket createRestApi() { -// ParameterBuilder ticketPar = new ParameterBuilder(); -//// List pars = new ArrayList<>(); -//// ticketPar.name(tokenHeader).description("token") -//// .modelRef(new ModelRef("string")) -//// .parameterType("header") -//// .defaultValue(tokenStartWith + " ") -//// .required(true) -//// .build(); -// pars.add(ticketPar.build()); return new Docket(DocumentationType.SWAGGER_2) .enable(enabled) + .pathMapping("/") .apiInfo(apiInfo()) .select() -// .paths(Predicates.not(PathSelectors.regex("/error.*"))) + .paths(Predicates.not(PathSelectors.regex("/error.*"))) .paths(PathSelectors.any()) .build() -// .globalOperationParameters(pars) //添加登陆认证 .securitySchemes(securitySchemes()) .securityContexts(securityContexts()); @@ -87,7 +74,7 @@ public class SwaggerConfig { return new ApiInfoBuilder() .description("一个简单且易上手的 Spring boot 后台管理框架") .title("EL-ADMIN 接口文档") - .version("2.4") + .version("2.6") .build(); } @@ -104,14 +91,14 @@ public class SwaggerConfig { List securityContexts = new ArrayList<>(); // ^(?!auth).*$ 表示所有包含auth的接口不需要使用securitySchemes即不需要带token // ^标识开始 ()里是一子表达式 ?!/auth表示匹配不是/auth的位置,匹配上则添加请求头,注意路径已/开头 .表示任意字符 *表示前面的字符匹配多次 $标识结束 - securityContexts.add(getContextByPath("^(?!/auth).*$")); + securityContexts.add(getContextByPath()); return securityContexts; } - private SecurityContext getContextByPath(String pathRegex) { + private SecurityContext getContextByPath() { return SecurityContext.builder() .securityReferences(defaultAuth()) - .forPaths(PathSelectors.regex(pathRegex)) + .forPaths(PathSelectors.regex("^(?!/auth).*$")) .build(); } From a0b6e85ee5d402d3378e8425ed4f1aca50a3db6a Mon Sep 17 00:00:00 2001 From: shane Date: Tue, 2 Mar 2021 19:03:20 +0800 Subject: [PATCH 10/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96]Bas?= =?UTF-8?q?eEntity=E9=87=8CupdatedBy=E6=94=B9=E4=B8=BAupdateBy=20(#603)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与其他字段时态一致 --- eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java b/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java index 5f6fbfbd..618e100c 100644 --- a/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java +++ b/eladmin-common/src/main/java/me/zhengjie/base/BaseEntity.java @@ -50,7 +50,7 @@ public class BaseEntity implements Serializable { @LastModifiedBy @Column(name = "update_by") @ApiModelProperty(value = "更新人", hidden = true) - private String updatedBy; + private String updateBy; @CreationTimestamp @Column(name = "create_time", updatable = false) From 162cff269bb426a417467c3c3ab688c562ee87fc Mon Sep 17 00:00:00 2001 From: Tsln Date: Tue, 2 Mar 2021 19:04:02 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20RSAUtils=20=E4=BB=A5?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20RSA=20=E5=8A=A0=E5=AF=86/=E8=A7=A3?= =?UTF-8?q?=E5=AF=86=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6=20(#604)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/zhengjie/utils/RsaUtils.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/RsaUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/RsaUtils.java index 58089211..7c1f6d15 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/RsaUtils.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/RsaUtils.java @@ -2,6 +2,7 @@ package me.zhengjie.utils; import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher; +import java.io.ByteArrayOutputStream; import java.security.*; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; @@ -80,7 +81,7 @@ public class RsaUtils { PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, publicKey); - byte[] result = cipher.doFinal(Base64.decodeBase64(text)); + byte[] result = doLongerCipherFinal(cipher, Base64.decodeBase64(text)); return new String(result); } @@ -98,7 +99,7 @@ public class RsaUtils { PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, privateKey); - byte[] result = cipher.doFinal(text.getBytes()); + byte[] result = doLongerCipherFinal(cipher, text.getBytes()); return Base64.encodeBase64String(result); } @@ -116,7 +117,7 @@ public class RsaUtils { PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec5); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] result = cipher.doFinal(Base64.decodeBase64(text)); + byte[] result = doLongerCipherFinal(cipher, Base64.decodeBase64(text)); return new String(result); } @@ -133,10 +134,23 @@ public class RsaUtils { PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec2); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte[] result = cipher.doFinal(text.getBytes()); + byte[] result = doLongerCipherFinal(cipher, text.getBytes()); return Base64.encodeBase64String(result); } + private static byte[] doLongerCipherFinal(Cipher cipher, byte[] source) throws Exception { + int offset = 0; + int totalSize = source.length; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + while (totalSize - offset > 0) { + int size = Math.min(1024 / 8 - 11, totalSize - offset); + out.write(cipher.doFinal(source, offset, size)); + offset += size; + } + out.close(); + return out.toByteArray(); + } + /** * 构建RSA密钥对 * From d8a458cafa01961e577272739448c1a1eea0ecc5 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Tue, 2 Mar 2021 21:39:40 +0800 Subject: [PATCH 12/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9Aupdate=20UserController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/modules/system/rest/UserController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java index 2e885a71..dfff4ecc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java @@ -21,6 +21,7 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import me.zhengjie.annotation.Log; import me.zhengjie.config.RsaProperties; +import me.zhengjie.modules.system.domain.Dept; import me.zhengjie.modules.system.service.DataService; import me.zhengjie.modules.system.domain.User; import me.zhengjie.exception.BadRequestException; @@ -79,7 +80,10 @@ public class UserController { public ResponseEntity query(UserQueryCriteria criteria, Pageable pageable){ if (!ObjectUtils.isEmpty(criteria.getDeptId())) { criteria.getDeptIds().add(criteria.getDeptId()); - criteria.getDeptIds().addAll(deptService.getDeptChildren(deptService.findByPid(criteria.getDeptId()))); + // 先查找是否存在子节点 + List data = deptService.findByPid(criteria.getDeptId()); + // 然后把子节点的ID都加入到集合中 + criteria.getDeptIds().addAll(deptService.getDeptChildren(data)); } // 数据权限 List dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername())); From 88dc69fdfe62b1f77905736df1bfc82bc829a938 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Tue, 2 Mar 2021 21:42:16 +0800 Subject: [PATCH 13/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9Aupdate=20logback.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-system/src/main/resources/logback.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/resources/logback.xml b/eladmin-system/src/main/resources/logback.xml index dd9fb5a6..815dffc1 100644 --- a/eladmin-system/src/main/resources/logback.xml +++ b/eladmin-system/src/main/resources/logback.xml @@ -2,7 +2,7 @@ elAdmin - + From 3f129e8e851894cb3dc37ba739388fa3b437705b Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Wed, 3 Mar 2021 17:03:08 +0800 Subject: [PATCH 14/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9Aupdate=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 2c67d23f..26a795e4 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,6 @@ **账号密码:** `admin / 123456` -#### 活动福利 - -- 七牛云 2021 ECUG Con 全球技术大会内部票:给大家一共搞来五张小一千块钱的内部票。想要的加群【947578238】联系群主 -- 七牛云 2021 ECUG Con 全球技术大会早鸟特惠票:[点我抢购](http://www.huodongxing.com/event/1573487912300?coupon=EL666) - #### 项目源码 | | 后端源码 | 前端源码 | From 01d1aa9721d1f53b35f70bf244e5c3fd88dc7de8 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Wed, 3 Mar 2021 17:40:22 +0800 Subject: [PATCH 15/15] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2?= =?UTF-8?q?.6)=EF=BC=9A=E5=8A=A0=E5=85=A5=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=8E=B7=E5=8F=96Token=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/585 --- .../modules/security/rest/AuthorizationController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java index d7ff9b4a..9646d73b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java @@ -89,7 +89,10 @@ public class AuthorizationController { new UsernamePasswordAuthenticationToken(authUser.getUsername(), password); Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authentication); - // 生成令牌 + // 生成令牌与第三方系统获取令牌方式 + // UserDetails userDetails = userDetailsService.loadUserByUsername(userInfo.getUsername()); + // Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); + // SecurityContextHolder.getContext().setAuthentication(authentication); String token = tokenProvider.createToken(authentication); final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal(); // 保存在线信息