diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AuditorConfig.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AuditorConfig.java deleted file mode 100644 index 006ef6b..0000000 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AuditorConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package me.zhengjie.config; - -import me.zhengjie.utils.SecurityUtils; -import org.springframework.data.domain.AuditorAware; -import org.springframework.stereotype.Component; -import java.util.Optional; - -/** - * @description : 设置审计 - * @author : Dong ZhaoYang - * @date : 2019/10/28 - */ -@Component("auditorAware") -public class AuditorConfig implements AuditorAware { - - /** - * 返回操作员标志信息 - * - * @return / - */ - @Override - public Optional getCurrentAuditor() { - try { - // 这里应根据实际业务情况获取具体信息 - return Optional.of(SecurityUtils.getCurrentUsername()); - }catch (Exception ignored){} - // 用户定时任务,或者无Token调用的情况 - return Optional.of("System"); - } -} diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RsaProperties.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RsaProperties.java index 0a4a537..09b0b4c 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RsaProperties.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RsaProperties.java @@ -21,7 +21,7 @@ import org.springframework.stereotype.Component; /** * @author Zheng Jie - * @website https://eladmin.vip + * @website ... * @description * @date 2020-05-18 **/ diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/mybatis/CustomP6SpyLogger.java similarity index 98% rename from eladmin/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java rename to eladmin/eladmin-common/src/main/java/me/zhengjie/config/mybatis/CustomP6SpyLogger.java index 7c4afe1..0c12a2b 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/mybatis/CustomP6SpyLogger.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.config; +package me.zhengjie.config.mybatis; import cn.hutool.core.util.StrUtil; import com.p6spy.engine.spy.appender.MessageFormattingStrategy; diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/MultipartConfig.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/MultipartConfig.java similarity index 97% rename from eladmin/eladmin-common/src/main/java/me/zhengjie/config/MultipartConfig.java rename to eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/MultipartConfig.java index cf04de5..0661645 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/MultipartConfig.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/MultipartConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.config; +package me.zhengjie.config.webmvc; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/SwaggerConfig.java similarity index 99% rename from eladmin/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java rename to eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/SwaggerConfig.java index 8ee5222..90b5815 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/webmvc/SwaggerConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.config; +package me.zhengjie.config.webmvc; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java deleted file mode 100644 index ede3691..0000000 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/BadConfigurationException.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2019-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package me.zhengjie.exception; - -/** - * 统一关于错误配置信息 异常 - * - * @author: liaojinlong - * @date: 2020/6/10 18:06 - */ -public class BadConfigurationException extends RuntimeException { - /** - * Constructs a new runtime exception with {@code null} as its - * detail message. The cause is not initialized, and may subsequently be - * initialized by a call to {@link #initCause}. - */ - public BadConfigurationException() { - super(); - } - - /** - * Constructs a new runtime exception with the specified detail message. - * The cause is not initialized, and may subsequently be initialized by a - * call to {@link #initCause}. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public BadConfigurationException(String message) { - super(message); - } - - /** - * Constructs a new runtime exception with the specified detail message and - * cause.

Note that the detail message associated with - * {@code cause} is not automatically incorporated in - * this runtime exception's detail message. - * - * @param message the detail message (which is saved for later retrieval - * by the {@link #getMessage()} method). - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A {@code null} value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public BadConfigurationException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructs a new runtime exception with the specified cause and a - * detail message of {@code (cause==null ? null : cause.toString())} - * (which typically contains the class and detail message of - * {@code cause}). This constructor is useful for runtime exceptions - * that are little more than wrappers for other throwables. - * - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A {@code null} value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public BadConfigurationException(Throwable cause) { - super(cause); - } - - /** - * Constructs a new runtime exception with the specified detail - * message, cause, suppression enabled or disabled, and writable - * stack trace enabled or disabled. - * - * @param message the detail message. - * @param cause the cause. (A {@code null} value is permitted, - * and indicates that the cause is nonexistent or unknown.) - * @param enableSuppression whether or not suppression is enabled - * or disabled - * @param writableStackTrace whether or not the stack trace should - * be writable - * @since 1.7 - */ - protected BadConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java index 977788c..9568df8 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/exception/handler/ApiError.java @@ -22,7 +22,7 @@ import lombok.Data; * @date 2018-11-23 */ @Data -class ApiError { +public class ApiError { private Integer status = 400; private Long timestamp; diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java index 9b10812..2521020 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java @@ -20,7 +20,7 @@ package me.zhengjie.utils; * @author: liaojinlong * @date: 2020/6/9 17:02 * @since: 1.0 - * @see {@link SpringContextHolder} + * @see {@link SpringBeanHolder} * 针对某些初始化方法,在SpringContextHolder 初始化前时,
* 可提交一个 提交回调任务。
* 在SpringContextHolder 初始化后,进行回调使用 diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/PageResult.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/PageResult.java index 0f1fdfe..ce317da 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/PageResult.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/PageResult.java @@ -1,16 +1,15 @@ package me.zhengjie.utils; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - +import lombok.*; +import java.io.Serializable; import java.util.List; -@Getter -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class PageResult { +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PageResult implements Serializable { - private final List content; + private List content; - private final long totalElements; + private long totalElements; } diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java index 28e4672..aa4e376 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java @@ -41,7 +41,7 @@ public class SecurityUtils { * @return UserDetails */ public static UserDetails getCurrentUser() { - UserDetailsService userDetailsService = SpringContextHolder.getBean(UserDetailsService.class); + UserDetailsService userDetailsService = SpringBeanHolder.getBean(UserDetailsService.class); return userDetailsService.loadUserByUsername(getCurrentUsername()); } diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java similarity index 89% rename from eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java rename to eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java index 41ead38..d23ca6a 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java @@ -31,7 +31,7 @@ import java.util.List; * @date 2019-01-07 */ @Slf4j -public class SpringContextHolder implements ApplicationContextAware, DisposableBean { +public class SpringBeanHolder implements ApplicationContextAware, DisposableBean { private static ApplicationContext applicationContext = null; private static final List CALL_BACKS = new ArrayList<>(); @@ -45,7 +45,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB */ public synchronized static void addCallBacks(CallBack callBack) { if (addCallback) { - SpringContextHolder.CALL_BACKS.add(callBack); + SpringBeanHolder.CALL_BACKS.add(callBack); } else { log.warn("CallBack:{} 已无法添加!立即执行", callBack.getCallBackName()); callBack.executor(); @@ -127,22 +127,22 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB @Override public void destroy() { - SpringContextHolder.clearHolder(); + SpringBeanHolder.clearHolder(); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - if (SpringContextHolder.applicationContext != null) { - log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" + SpringContextHolder.applicationContext); + if (SpringBeanHolder.applicationContext != null) { + log.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" + SpringBeanHolder.applicationContext); } - SpringContextHolder.applicationContext = applicationContext; + SpringBeanHolder.applicationContext = applicationContext; if (addCallback) { - for (CallBack callBack : SpringContextHolder.CALL_BACKS) { + for (CallBack callBack : SpringBeanHolder.CALL_BACKS) { callBack.executor(); } CALL_BACKS.clear(); } - SpringContextHolder.addCallback = false; + SpringBeanHolder.addCallback = false; } /** diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java index f6bd259..5208218 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java @@ -41,7 +41,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { /** * 注入bean */ - private final static Ip2regionSearcher IP_SEARCHER = SpringContextHolder.getBean(Ip2regionSearcher.class); + private final static Ip2regionSearcher IP_SEARCHER = SpringBeanHolder.getBean(Ip2regionSearcher.class); /** * 驼峰命名法工具 diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java index 07befa2..77bf42d 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java @@ -18,7 +18,7 @@ package me.zhengjie; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.rest.AnonymousGetMapping; -import me.zhengjie.utils.SpringContextHolder; +import me.zhengjie.utils.SpringBeanHolder; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.ApplicationPidFileWriter; @@ -53,8 +53,8 @@ public class AppRun { } @Bean - public SpringContextHolder springContextHolder() { - return new SpringContextHolder(); + public SpringBeanHolder springContextHolder() { + return new SpringBeanHolder(); } /** diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java index 50a209a..825d264 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java @@ -27,7 +27,7 @@ import me.zhengjie.modules.quartz.domain.QuartzLog; import me.zhengjie.modules.quartz.service.QuartzJobService; import me.zhengjie.modules.quartz.domain.vo.QuartzJobQueryCriteria; import me.zhengjie.utils.PageResult; -import me.zhengjie.utils.SpringContextHolder; +import me.zhengjie.utils.SpringBeanHolder; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; @@ -134,7 +134,7 @@ public class QuartzJobController { private void checkBean(String beanName){ // 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类 // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。 - if(!SpringContextHolder.getAllServiceBeanName().contains(beanName)){ + if(!SpringBeanHolder.getAllServiceBeanName().contains(beanName)){ throw new BadRequestException("非法的 Bean,请重新输入!"); } } diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java index 95bc0bd..5e578f0 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java @@ -26,7 +26,7 @@ import me.zhengjie.modules.quartz.mapper.QuartzLogMapper; import me.zhengjie.modules.quartz.service.QuartzJobService; import me.zhengjie.service.EmailService; import me.zhengjie.utils.RedisUtils; -import me.zhengjie.utils.SpringContextHolder; +import me.zhengjie.utils.SpringBeanHolder; import me.zhengjie.utils.StringUtils; import me.zhengjie.utils.ThrowableUtil; import org.quartz.JobExecutionContext; @@ -49,16 +49,16 @@ public class ExecutionJob extends QuartzJobBean { private final Logger logger = LoggerFactory.getLogger(this.getClass()); // 此处仅供参考,可根据任务执行情况自定义线程池参数 - private final ThreadPoolTaskExecutor executor = SpringContextHolder.getBean("elAsync"); + private final ThreadPoolTaskExecutor executor = SpringBeanHolder.getBean("elAsync"); @Override public void executeInternal(JobExecutionContext context) { // 获取任务 QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY); // 获取spring bean - QuartzLogMapper quartzLogMapper = SpringContextHolder.getBean(QuartzLogMapper.class); - QuartzJobService quartzJobService = SpringContextHolder.getBean(QuartzJobService.class); - RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); + QuartzLogMapper quartzLogMapper = SpringBeanHolder.getBean(QuartzLogMapper.class); + QuartzJobService quartzJobService = SpringBeanHolder.getBean(QuartzJobService.class); + RedisUtils redisUtils = SpringBeanHolder.getBean(RedisUtils.class); String uuid = quartzJob.getUuid(); @@ -105,7 +105,7 @@ public class ExecutionJob extends QuartzJobBean { quartzJobService.updateIsPause(quartzJob); } if(quartzJob.getEmail() != null){ - EmailService emailService = SpringContextHolder.getBean(EmailService.class); + EmailService emailService = SpringBeanHolder.getBean(EmailService.class); // 邮箱报警 if(StringUtils.isNoneBlank(quartzJob.getEmail())){ EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e)); diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java index 31c3a0f..c75925e 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java @@ -16,7 +16,7 @@ package me.zhengjie.modules.quartz.utils; import lombok.extern.slf4j.Slf4j; -import me.zhengjie.utils.SpringContextHolder; +import me.zhengjie.utils.SpringBeanHolder; import org.apache.commons.lang3.StringUtils; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Method; @@ -35,7 +35,7 @@ public class QuartzRunnable implements Callable { QuartzRunnable(String beanName, String methodName, String params) throws NoSuchMethodException, SecurityException { - this.target = SpringContextHolder.getBean(beanName); + this.target = SpringBeanHolder.getBean(beanName); this.params = params; if (StringUtils.isNotBlank(params)) { this.method = target.getClass().getDeclaredMethod(methodName, String.class); diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java index 0201a13..8f03c84 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java @@ -18,7 +18,8 @@ package me.zhengjie.modules.security.config.bean; import com.wf.captcha.*; import com.wf.captcha.base.Captcha; import lombok.Data; -import me.zhengjie.exception.BadConfigurationException; +import lombok.Getter; +import me.zhengjie.exception.BadRequestException; import me.zhengjie.utils.StringUtils; import java.awt.*; import java.util.Objects; @@ -35,16 +36,13 @@ public class LoginProperties { /** * 账号单用户 登录 */ + @Getter private boolean singleLogin = false; private LoginCode loginCode; public static final String cacheKey = "user-login-cache:"; - public boolean isSingleLogin() { - return singleLogin; - } - /** * 获取验证码生产类 * @@ -92,7 +90,7 @@ public class LoginProperties { captcha.setLen(loginCode.getLength()); break; default: - throw new BadConfigurationException("验证码配置信息错误!正确配置查看 LoginCodeEnum "); + throw new BadRequestException("验证码配置信息错误!正确配置查看 LoginCodeEnum "); } if(StringUtils.isNotBlank(loginCode.getFontName())){ captcha.setFont(new Font(loginCode.getFontName(), Font.PLAIN, loginCode.getFontSize())); diff --git a/eladmin/eladmin-system/src/main/resources/spy.properties b/eladmin/eladmin-system/src/main/resources/spy.properties index ff9fafb..5d82027 100644 --- a/eladmin/eladmin-system/src/main/resources/spy.properties +++ b/eladmin/eladmin-system/src/main/resources/spy.properties @@ -1,7 +1,7 @@ # 应用的拦截模块 modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory # 自定义日志打印 -logMessageFormat=me.zhengjie.config.CustomP6SpyLogger +logMessageFormat=me.zhengjie.config.mybatis.CustomP6SpyLogger # 日志输出到控制台 appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger # 日期格式