From 5e32b5f0bf07fbc8018e90088f89df81e9c8c753 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期二, 18 五月 2021 11:38:16 +0800
Subject: [PATCH] update 配置统一提取为 properties 配置类
---
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/CaptchaProperties.java | 24 +++
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java | 64 ++-----
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/ThreadPoolProperties.java | 47 +++++
ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java | 33 +--
ruoyi-admin/src/main/resources/application.yml | 12
ruoyi-common/pom.xml | 5
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java | 8
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/TokenProperties.java | 26 +++
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/XssProperties.java | 32 ++++
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java | 29 +--
ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java | 36 ++++
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java | 55 ++----
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java | 82 +++------
13 files changed, 270 insertions(+), 183 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
index 48e4e4e..c01cc4e 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
@@ -13,8 +13,8 @@
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.framework.config.properties.CaptchaProperties;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -42,18 +42,8 @@
@Autowired
private RedisCache redisCache;
- // 楠岃瘉鐮佺被鍨�
- @Value("${captcha.captchaType}")
- private String captchaType;
- // 楠岃瘉鐮佺被鍒�
- @Value("${captcha.captchaCategory}")
- private String captchaCategory;
- // 鏁板瓧楠岃瘉鐮佷綅鏁�
- @Value("${captcha.captchaNumberLength}")
- private int numberLength;
- // 瀛楃楠岃瘉鐮侀暱搴�
- @Value("${captcha.captchaCharLength}")
- private int charLength;
+ @Autowired
+ private CaptchaProperties captchaProperties;
/**
* 鐢熸垚楠岃瘉鐮�
@@ -67,17 +57,17 @@
// 鐢熸垚楠岃瘉鐮�
CodeGenerator codeGenerator;
AbstractCaptcha captcha;
- switch (captchaType) {
+ switch (captchaProperties.getType()) {
case "math":
- codeGenerator = new MathGenerator(numberLength);
+ codeGenerator = new MathGenerator(captchaProperties.getNumberLength());
break;
case "char":
- codeGenerator = new RandomGenerator(charLength);
+ codeGenerator = new RandomGenerator(captchaProperties.getCharLength());
break;
default:
throw new IllegalArgumentException("楠岃瘉鐮佺被鍨嬪紓甯�");
}
- switch (captchaCategory) {
+ switch (captchaProperties.getCategory()) {
case "line":
captcha = lineCaptcha;
break;
@@ -92,9 +82,9 @@
}
captcha.setGenerator(codeGenerator);
captcha.createCode();
- if ("math".equals(captchaType)) {
+ if ("math".equals(captchaProperties.getType())) {
code = getCodeResult(captcha.getCode());
- } else if ("char".equals(captchaType)) {
+ } else if ("char".equals(captchaProperties.getType())) {
code = captcha.getCode();
}
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
@@ -105,6 +95,7 @@
}
private String getCodeResult(String capStr) {
+ int numberLength = captchaProperties.getNumberLength();
int a = Convert.toInt(StrUtil.sub(capStr, 0, numberLength).trim());
char operator = capStr.charAt(numberLength);
int b = Convert.toInt(StrUtil.sub(capStr, numberLength + 1, numberLength + 1 + numberLength).trim());
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 4f6d876..d072872 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -15,13 +15,13 @@
captcha:
# 楠岃瘉鐮佺被鍨� math 鏁扮粍璁$畻 char 瀛楃楠岃瘉
- captchaType: math
+ type: math
# line 绾挎骞叉壈 circle 鍦嗗湀骞叉壈 shear 鎵洸骞叉壈
- captchaCategory: circle
+ category: circle
# 鏁板瓧楠岃瘉鐮佷綅鏁�
- captchaNumberLength: 1
+ numberLength: 1
# 瀛楃楠岃瘉鐮侀暱搴�
- captchaCharLength: 4
+ charLength: 4
# 寮�鍙戠幆澧冮厤缃�
server:
@@ -187,8 +187,6 @@
swagger:
# 鏄惁寮�鍚痵wagger
enabled: true
- # 璇锋眰鍓嶇紑
- pathMapping: /dev-api
# 鏍囬
title: '鏍囬锛歊uoYi-Vue-Plus鍚庡彴绠$悊绯荤粺_鎺ュ彛鏂囨。'
# 鎻忚堪
@@ -206,7 +204,7 @@
urlPatterns: /system/*,/monitor/*,/tool/*
# 鍏ㄥ眬绾跨▼姹犵浉鍏抽厤缃�
-threadPoolConfig:
+thread-pool:
# 鏄惁寮�鍚嚎绋嬫睜
enabled: false
# 鏍稿績绾跨▼姹犲ぇ灏�
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 2391586..4e99076 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -145,6 +145,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
+ <!-- 鑷姩鐢熸垚YML閰嶇疆鍏宠仈JSON鏂囦欢 -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ </dependency>
</dependencies>
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java
index 4626aa1..73f7f93 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java
@@ -3,7 +3,8 @@
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.filter.RepeatableFilter;
import com.ruoyi.common.filter.XssFilter;
-import org.springframework.beans.factory.annotation.Value;
+import com.ruoyi.framework.config.properties.XssProperties;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -15,41 +16,33 @@
/**
* Filter閰嶇疆
*
- * @author ruoyi
+ * @author Lion Li
*/
@Configuration
-public class FilterConfig
-{
- @Value("${xss.enabled}")
- private String enabled;
+public class FilterConfig {
- @Value("${xss.excludes}")
- private String excludes;
+ @Autowired
+ private XssProperties xssProperties;
- @Value("${xss.urlPatterns}")
- private String urlPatterns;
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Bean
- public FilterRegistrationBean xssFilterRegistration()
- {
+ public FilterRegistrationBean xssFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setDispatcherTypes(DispatcherType.REQUEST);
registration.setFilter(new XssFilter());
- registration.addUrlPatterns(StrUtil.split(urlPatterns, ","));
+ registration.addUrlPatterns(StrUtil.split(xssProperties.getUrlPatterns(), ","));
registration.setName("xssFilter");
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
Map<String, String> initParameters = new HashMap<String, String>();
- initParameters.put("excludes", excludes);
- initParameters.put("enabled", enabled);
+ initParameters.put("excludes", xssProperties.getExcludes());
+ initParameters.put("enabled", xssProperties.getEnabled());
registration.setInitParameters(initParameters);
return registration;
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Bean
- public FilterRegistrationBean someFilterRegistration()
- {
+ public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new RepeatableFilter());
registration.addUrlPatterns("/*");
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
similarity index 96%
rename from ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java
rename to ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
index 39c7786..8b43f17 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
@@ -1,4 +1,4 @@
-package com.ruoyi.web.core.config;
+package com.ruoyi.framework.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.ruoyi.common.config.RuoYiConfig;
@@ -37,12 +37,6 @@
*/
@Autowired
private RuoYiConfig ruoyiConfig;
-
- /**
- * 璁剧疆璇锋眰鐨勭粺涓�鍓嶇紑
- */
- @Value("${swagger.pathMapping}")
- private String pathMapping;
/**
* 鏍囬
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
index 30d5ef9..1048383 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ThreadPoolConfig.java
@@ -1,8 +1,9 @@
package com.ruoyi.framework.config;
import com.ruoyi.common.utils.Threads;
+import com.ruoyi.framework.config.properties.ThreadPoolProperties;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -21,43 +22,31 @@
@Configuration
public class ThreadPoolConfig {
- // 鏍稿績绾跨▼姹犲ぇ灏�
- @Value("${threadPoolConfig.corePoolSize}")
- private int corePoolSize;
-
- // 鏈�澶у彲鍒涘缓鐨勭嚎绋嬫暟
- @Value("${threadPoolConfig.maxPoolSize}")
- private int maxPoolSize;
-
- // 闃熷垪鏈�澶ч暱搴�
- @Value("${threadPoolConfig.queueCapacity}")
- private int queueCapacity;
-
- // 绾跨▼姹犵淮鎶ょ嚎绋嬫墍鍏佽鐨勭┖闂叉椂闂�
- @Value("${threadPoolConfig.keepAliveSeconds}")
- private int keepAliveSeconds;
-
- // 绾跨▼姹犲鎷掔粷浠诲姟(鏃犵嚎绋嬪彲鐢�)鐨勫鐞嗙瓥鐣�
- @Value("${threadPoolConfig.rejectedExecutionHandler}")
- private String rejectedExecutionHandler;
+ @Autowired
+ private ThreadPoolProperties threadPoolProperties;
@Bean(name = "threadPoolTaskExecutor")
@ConditionalOnProperty(prefix = "threadPoolTaskExecutor", name = "enabled", havingValue = "true")
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- executor.setMaxPoolSize(maxPoolSize);
- executor.setCorePoolSize(corePoolSize);
- executor.setQueueCapacity(queueCapacity);
- executor.setKeepAliveSeconds(keepAliveSeconds);
+ executor.setMaxPoolSize(threadPoolProperties.getMaxPoolSize());
+ executor.setCorePoolSize(threadPoolProperties.getCorePoolSize());
+ executor.setQueueCapacity(threadPoolProperties.getQueueCapacity());
+ executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds());
RejectedExecutionHandler handler;
- if (rejectedExecutionHandler.equals("CallerRunsPolicy")) {
- handler = new ThreadPoolExecutor.CallerRunsPolicy();
- } else if (rejectedExecutionHandler.equals("DiscardOldestPolicy")) {
- handler = new ThreadPoolExecutor.DiscardOldestPolicy();
- } else if (rejectedExecutionHandler.equals("DiscardPolicy")) {
- handler = new ThreadPoolExecutor.DiscardPolicy();
- } else {
- handler = new ThreadPoolExecutor.AbortPolicy();
+ switch (threadPoolProperties.getRejectedExecutionHandler()) {
+ case "CallerRunsPolicy":
+ handler = new ThreadPoolExecutor.CallerRunsPolicy();
+ break;
+ case "DiscardOldestPolicy":
+ handler = new ThreadPoolExecutor.DiscardOldestPolicy();
+ break;
+ case "DiscardPolicy":
+ handler = new ThreadPoolExecutor.DiscardPolicy();
+ break;
+ default:
+ handler = new ThreadPoolExecutor.AbortPolicy();
+ break;
}
executor.setRejectedExecutionHandler(handler);
return executor;
@@ -68,7 +57,7 @@
*/
@Bean(name = "scheduledExecutorService")
protected ScheduledExecutorService scheduledExecutorService() {
- return new ScheduledThreadPoolExecutor(corePoolSize,
+ return new ScheduledThreadPoolExecutor(threadPoolProperties.getCorePoolSize(),
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/CaptchaProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/CaptchaProperties.java
new file mode 100644
index 0000000..24356bc
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/CaptchaProperties.java
@@ -0,0 +1,24 @@
+package com.ruoyi.framework.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * 楠岃瘉鐮� 閰嶇疆灞炴��
+ *
+ * @author Lion Li
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "captcha")
+public class CaptchaProperties {
+ // 楠岃瘉鐮佺被鍨�
+ private String type;
+ // 楠岃瘉鐮佺被鍒�
+ private String category;
+ // 鏁板瓧楠岃瘉鐮佷綅鏁�
+ private Integer numberLength;
+ // 瀛楃楠岃瘉鐮侀暱搴�
+ private Integer charLength;
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java
index 84f7e00..03ddc2c 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java
@@ -1,76 +1,54 @@
package com.ruoyi.framework.config.properties;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
import com.alibaba.druid.pool.DruidDataSource;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
/**
* druid 閰嶇疆灞炴��
- *
- * @author ruoyi
+ *
+ * @author Lion Li
*/
+@Data
@Configuration
-public class DruidProperties
-{
- @Value("${spring.datasource.druid.initialSize}")
+@ConfigurationProperties(prefix = "spring.datasource.druid")
+public class DruidProperties {
+
+ /** 鍒濆杩炴帴鏁� */
private int initialSize;
-
- @Value("${spring.datasource.druid.minIdle}")
+ /** 鏈�灏忚繛鎺ユ睜鏁伴噺 */
private int minIdle;
-
- @Value("${spring.datasource.druid.maxActive}")
+ /** 鏈�澶ц繛鎺ユ睜鏁伴噺 */
private int maxActive;
-
- @Value("${spring.datasource.druid.maxWait}")
+ /** 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂� */
private int maxWait;
-
- @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}")
+ /** 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫�娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 */
private int timeBetweenEvictionRunsMillis;
-
- @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}")
+ /** 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�灏忕敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 */
private int minEvictableIdleTimeMillis;
-
- @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}")
+ /** 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 */
private int maxEvictableIdleTimeMillis;
-
- @Value("${spring.datasource.druid.validationQuery}")
+ /** 閰嶇疆妫�娴嬭繛鎺ユ槸鍚︽湁鏁� */
private String validationQuery;
-
- @Value("${spring.datasource.druid.testWhileIdle}")
+ /** 鍒濆杩炴帴鏁� */
private boolean testWhileIdle;
-
- @Value("${spring.datasource.druid.testOnBorrow}")
+ /** 鍒濆杩炴帴鏁� */
private boolean testOnBorrow;
-
- @Value("${spring.datasource.druid.testOnReturn}")
+ /** 鍒濆杩炴帴鏁� */
private boolean testOnReturn;
- public DruidDataSource dataSource(DruidDataSource datasource)
- {
- /** 閰嶇疆鍒濆鍖栧ぇ灏忋�佹渶灏忋�佹渶澶� */
+ public DruidDataSource dataSource(DruidDataSource datasource) {
datasource.setInitialSize(initialSize);
datasource.setMaxActive(maxActive);
datasource.setMinIdle(minIdle);
-
- /** 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂� */
datasource.setMaxWait(maxWait);
-
- /** 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫�娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 */
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-
- /** 閰嶇疆涓�涓繛鎺ュ湪姹犱腑鏈�灏忋�佹渶澶х敓瀛樼殑鏃堕棿锛屽崟浣嶆槸姣 */
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
-
- /**
- * 鐢ㄦ潵妫�娴嬭繛鎺ユ槸鍚︽湁鏁堢殑sql锛岃姹傛槸涓�涓煡璇㈣鍙ワ紝甯哥敤select 'x'銆傚鏋渧alidationQuery涓簄ull锛宼estOnBorrow銆乼estOnReturn銆乼estWhileIdle閮戒笉浼氳捣浣滅敤銆�
- */
datasource.setValidationQuery(validationQuery);
- /** 寤鸿閰嶇疆涓簍rue锛屼笉褰卞搷鎬ц兘锛屽苟涓斾繚璇佸畨鍏ㄦ�с�傜敵璇疯繛鎺ョ殑鏃跺�欐娴嬶紝濡傛灉绌洪棽鏃堕棿澶т簬timeBetweenEvictionRunsMillis锛屾墽琛寁alidationQuery妫�娴嬭繛鎺ユ槸鍚︽湁鏁堛�� */
datasource.setTestWhileIdle(testWhileIdle);
- /** 鐢宠杩炴帴鏃舵墽琛寁alidationQuery妫�娴嬭繛鎺ユ槸鍚︽湁鏁堬紝鍋氫簡杩欎釜閰嶇疆浼氶檷浣庢�ц兘銆� */
datasource.setTestOnBorrow(testOnBorrow);
- /** 褰掕繕杩炴帴鏃舵墽琛寁alidationQuery妫�娴嬭繛鎺ユ槸鍚︽湁鏁堬紝鍋氫簡杩欎釜閰嶇疆浼氶檷浣庢�ц兘銆� */
datasource.setTestOnReturn(testOnReturn);
return datasource;
}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java
new file mode 100644
index 0000000..4a37fbc
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java
@@ -0,0 +1,36 @@
+package com.ruoyi.framework.config.properties;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * 楠岃瘉鐮� 閰嶇疆灞炴��
+ *
+ * @author Lion Li
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "swagger")
+public class SwaggerProperties {
+
+ /**
+ * 楠岃瘉鐮佺被鍨�
+ */
+ private Boolean enabled;
+ /**
+ * 楠岃瘉鐮佺被鍒�
+ */
+ private String title;
+ /**
+ * 鏁板瓧楠岃瘉鐮佷綅鏁�
+ */
+ private String description;
+ /**
+ * 瀛楃楠岃瘉鐮侀暱搴�
+ */
+ private String version;
+
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/ThreadPoolProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/ThreadPoolProperties.java
new file mode 100644
index 0000000..68cb093
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/ThreadPoolProperties.java
@@ -0,0 +1,47 @@
+package com.ruoyi.framework.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * 楠岃瘉鐮� 閰嶇疆灞炴��
+ *
+ * @author Lion Li
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "thread-pool")
+public class ThreadPoolProperties {
+
+ /**
+ * 鏄惁寮�鍚嚎绋嬫睜
+ */
+ private boolean enabled;
+
+ /**
+ * 鏍稿績绾跨▼姹犲ぇ灏�
+ */
+ private int corePoolSize;
+
+ /**
+ * 鏈�澶у彲鍒涘缓鐨勭嚎绋嬫暟
+ */
+ private int maxPoolSize;
+
+ /**
+ * 闃熷垪鏈�澶ч暱搴�
+ */
+ private int queueCapacity;
+
+ /**
+ * 绾跨▼姹犵淮鎶ょ嚎绋嬫墍鍏佽鐨勭┖闂叉椂闂�
+ */
+ private int keepAliveSeconds;
+
+ /**
+ * 绾跨▼姹犲鎷掔粷浠诲姟(鏃犵嚎绋嬪彲鐢�)鐨勫鐞嗙瓥鐣�
+ */
+ private String rejectedExecutionHandler;
+
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/TokenProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/TokenProperties.java
new file mode 100644
index 0000000..d582e54
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/TokenProperties.java
@@ -0,0 +1,26 @@
+package com.ruoyi.framework.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "token")
+public class TokenProperties {
+
+ /**
+ * 浠ょ墝鑷畾涔夋爣璇�
+ */
+ private String header;
+
+ /**
+ * 浠ょ墝绉橀挜
+ */
+ private String secret;
+
+ /**
+ * 浠ょ墝鏈夋晥鏈燂紙榛樿30鍒嗛挓锛�
+ */
+ private int expireTime;
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/XssProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/XssProperties.java
new file mode 100644
index 0000000..35ae2e4
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/XssProperties.java
@@ -0,0 +1,32 @@
+package com.ruoyi.framework.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * 楠岃瘉鐮� 閰嶇疆灞炴��
+ *
+ * @author Lion Li
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "xss")
+public class XssProperties {
+
+ /**
+ * 杩囨护寮�鍏�
+ */
+ private String enabled;
+
+ /**
+ * 鎺掗櫎閾炬帴锛堝涓敤閫楀彿鍒嗛殧锛�
+ */
+ private String excludes;
+
+ /**
+ * 鍖归厤閾炬帴
+ */
+ private String urlPatterns;
+
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
index c55078d..0db777b 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
@@ -10,11 +10,11 @@
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.ip.AddressUtils;
import com.ruoyi.common.utils.ip.IpUtils;
+import com.ruoyi.framework.config.properties.TokenProperties;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
@@ -25,22 +25,10 @@
/**
* token楠岃瘉澶勭悊
*
- * @author ruoyi
+ * @author Lion Li
*/
@Component
-public class TokenService
-{
- // 浠ょ墝鑷畾涔夋爣璇�
- @Value("${token.header}")
- private String header;
-
- // 浠ょ墝绉橀挜
- @Value("${token.secret}")
- private String secret;
-
- // 浠ょ墝鏈夋晥鏈燂紙榛樿30鍒嗛挓锛�
- @Value("${token.expireTime}")
- private int expireTime;
+public class TokenService {
protected static final long MILLIS_SECOND = 1000;
@@ -51,17 +39,18 @@
@Autowired
private RedisCache redisCache;
+ @Autowired
+ private TokenProperties tokenProperties;
+
/**
* 鑾峰彇鐢ㄦ埛韬唤淇℃伅
*
* @return 鐢ㄦ埛淇℃伅
*/
- public LoginUser getLoginUser(HttpServletRequest request)
- {
+ public LoginUser getLoginUser(HttpServletRequest request) {
// 鑾峰彇璇锋眰鎼哄甫鐨勪护鐗�
String token = getToken(request);
- if (Validator.isNotEmpty(token))
- {
+ if (Validator.isNotEmpty(token)) {
Claims claims = parseToken(token);
// 瑙f瀽瀵瑰簲鐨勬潈闄愪互鍙婄敤鎴蜂俊鎭�
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
@@ -75,10 +64,8 @@
/**
* 璁剧疆鐢ㄦ埛韬唤淇℃伅
*/
- public void setLoginUser(LoginUser loginUser)
- {
- if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken()))
- {
+ public void setLoginUser(LoginUser loginUser) {
+ if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken())) {
refreshToken(loginUser);
}
}
@@ -86,10 +73,8 @@
/**
* 鍒犻櫎鐢ㄦ埛韬唤淇℃伅
*/
- public void delLoginUser(String token)
- {
- if (Validator.isNotEmpty(token))
- {
+ public void delLoginUser(String token) {
+ if (Validator.isNotEmpty(token)) {
String userKey = getTokenKey(token);
redisCache.deleteObject(userKey);
}
@@ -101,8 +86,7 @@
* @param loginUser 鐢ㄦ埛淇℃伅
* @return 浠ょ墝
*/
- public String createToken(LoginUser loginUser)
- {
+ public String createToken(LoginUser loginUser) {
String token = IdUtil.fastUUID();
loginUser.setToken(token);
setUserAgent(loginUser);
@@ -119,12 +103,10 @@
* @param loginUser
* @return 浠ょ墝
*/
- public void verifyToken(LoginUser loginUser)
- {
+ public void verifyToken(LoginUser loginUser) {
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
- if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
- {
+ if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
refreshToken(loginUser);
}
}
@@ -134,13 +116,12 @@
*
* @param loginUser 鐧诲綍淇℃伅
*/
- public void refreshToken(LoginUser loginUser)
- {
+ public void refreshToken(LoginUser loginUser) {
loginUser.setLoginTime(System.currentTimeMillis());
- loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
+ loginUser.setExpireTime(loginUser.getLoginTime() + tokenProperties.getExpireTime() * MILLIS_MINUTE);
// 鏍规嵁uuid灏唋oginUser缂撳瓨
String userKey = getTokenKey(loginUser.getToken());
- redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
+ redisCache.setCacheObject(userKey, loginUser, tokenProperties.getExpireTime(), TimeUnit.MINUTES);
}
/**
@@ -148,8 +129,7 @@
*
* @param loginUser 鐧诲綍淇℃伅
*/
- public void setUserAgent(LoginUser loginUser)
- {
+ public void setUserAgent(LoginUser loginUser) {
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
loginUser.setIpaddr(ip);
@@ -164,11 +144,10 @@
* @param claims 鏁版嵁澹版槑
* @return 浠ょ墝
*/
- private String createToken(Map<String, Object> claims)
- {
+ private String createToken(Map<String, Object> claims) {
String token = Jwts.builder()
.setClaims(claims)
- .signWith(SignatureAlgorithm.HS512, secret).compact();
+ .signWith(SignatureAlgorithm.HS512, tokenProperties.getSecret()).compact();
return token;
}
@@ -178,10 +157,9 @@
* @param token 浠ょ墝
* @return 鏁版嵁澹版槑
*/
- private Claims parseToken(String token)
- {
+ private Claims parseToken(String token) {
return Jwts.parser()
- .setSigningKey(secret)
+ .setSigningKey(tokenProperties.getSecret())
.parseClaimsJws(token)
.getBody();
}
@@ -192,8 +170,7 @@
* @param token 浠ょ墝
* @return 鐢ㄦ埛鍚�
*/
- public String getUsernameFromToken(String token)
- {
+ public String getUsernameFromToken(String token) {
Claims claims = parseToken(token);
return claims.getSubject();
}
@@ -204,18 +181,15 @@
* @param request
* @return token
*/
- private String getToken(HttpServletRequest request)
- {
- String token = request.getHeader(header);
- if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
- {
+ private String getToken(HttpServletRequest request) {
+ String token = request.getHeader(tokenProperties.getHeader());
+ if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
token = token.replace(Constants.TOKEN_PREFIX, "");
}
return token;
}
- private String getTokenKey(String uuid)
- {
+ private String getTokenKey(String uuid) {
return Constants.LOGIN_TOKEN_KEY + uuid;
}
}
--
Gitblit v1.9.3