Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ef7d2d4a2 | ||
|
|
b90e92f4cb | ||
|
|
cb816d0ff0 | ||
|
|
0470ca0b9a | ||
|
|
d38077b0f8 | ||
|
|
2621c6dedc | ||
|
|
456a95778c | ||
|
|
fd0976a30c | ||
|
|
e519781207 | ||
|
|
e602f4c658 | ||
|
|
a816acaddb | ||
|
|
278429157a | ||
|
|
143b100819 | ||
|
|
d0cd9aed0b | ||
|
|
3080d8a936 | ||
|
|
3f951dfe47 | ||
|
|
9c66dafe6b | ||
|
|
d6ed2b8037 | ||
|
|
02c2ccc0ff |
18
pom.xml
18
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>springboot-parent</name>
|
<name>springboot-parent</name>
|
||||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||||
@@ -58,49 +58,49 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-database</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-role</artifactId>
|
<artifactId>springboot-role</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
31
qodana.yaml
Normal file
31
qodana.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
# Qodana analysis is configured by qodana.yaml file #
|
||||||
|
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
version: "1.0"
|
||||||
|
|
||||||
|
#Specify inspection profile for code analysis
|
||||||
|
profile:
|
||||||
|
name: qodana.starter
|
||||||
|
|
||||||
|
#Enable inspections
|
||||||
|
#include:
|
||||||
|
# - name: <SomeEnabledInspectionId>
|
||||||
|
|
||||||
|
#Disable inspections
|
||||||
|
#exclude:
|
||||||
|
# - name: <SomeDisabledInspectionId>
|
||||||
|
# paths:
|
||||||
|
# - <path/where/not/run/inspection>
|
||||||
|
|
||||||
|
projectJDK: 17 #(Applied in CI/CD pipeline)
|
||||||
|
|
||||||
|
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#bootstrap: sh ./prepare-qodana.sh
|
||||||
|
|
||||||
|
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#plugins:
|
||||||
|
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||||
|
|
||||||
|
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||||
|
linter: jetbrains/qodana-jvm:latest
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-ademo</artifactId>
|
<artifactId>springboot-ademo</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ import java.util.Objects;
|
|||||||
@Component
|
@Component
|
||||||
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
|
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
GlobalConfig globalConfig;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
|
||||||
RequestUserInfo info = new RequestUserInfo();
|
RequestUserInfo info = new RequestUserInfo();
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.tiesheng.demo.config;
|
package com.tiesheng.demo.config;
|
||||||
|
|
||||||
|
|
||||||
import com.tiesheng.web.service.CoreConfigService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@@ -13,9 +11,6 @@ import javax.annotation.PostConstruct;
|
|||||||
@Component
|
@Component
|
||||||
public class TestJobConfig {
|
public class TestJobConfig {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
CoreConfigService coreConfigService;
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.tiesheng.demo.controller;
|
package com.tiesheng.demo.controller;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.date.TimeInterval;
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
@@ -30,11 +29,13 @@ import com.tiesheng.web.service.CoreLogService;
|
|||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +73,9 @@ public class TestController {
|
|||||||
@RequestMapping("/redirect")
|
@RequestMapping("/redirect")
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
@RoleAuthority("redirect")
|
@RoleAuthority("redirect")
|
||||||
public ApiResp<JsonTest> redirect(@RequestBody JsonTest dto, HttpServletResponse response) {
|
public ApiResp<JsonTest> redirect(HttpServletResponse response) {
|
||||||
|
|
||||||
|
encryptConfig.passwdCreate("111111@Zz", "");
|
||||||
|
|
||||||
JsonTest jsonTest = new JsonTest();
|
JsonTest jsonTest = new JsonTest();
|
||||||
jsonTest.setNow(DateUtil.date());
|
jsonTest.setNow(DateUtil.date());
|
||||||
@@ -81,7 +84,8 @@ public class TestController {
|
|||||||
String jsonString = JSON.toJSONString(jsonTest);
|
String jsonString = JSON.toJSONString(jsonTest);
|
||||||
LogFactory.get().info(jsonString);
|
LogFactory.get().info(jsonString);
|
||||||
|
|
||||||
LogFactory.get().info(JSON.toJSONString(dto));
|
String s = OkHttpUtil.get("http://toolbox.tieshengkeji.com/test/login/23232/3232");
|
||||||
|
LogFactory.get().info(s);
|
||||||
|
|
||||||
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
||||||
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||||
@@ -215,8 +219,10 @@ public class TestController {
|
|||||||
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
|
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
|
||||||
paramJson);
|
paramJson);
|
||||||
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
||||||
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
|
if (execute1.body() != null) {
|
||||||
execute1.close();
|
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
|
||||||
|
execute1.close();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ApiException("每分钟最多生成5000个二维码,请稍后再试!");
|
throw new ApiException("每分钟最多生成5000个二维码,请稍后再试!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-annotation</artifactId>
|
<artifactId>springboot-annotation</artifactId>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-database</artifactId>
|
<artifactId>springboot-database</artifactId>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-login</artifactId>
|
<artifactId>springboot-login</artifactId>
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ public class DoLoginInfo {
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
// 设置IP
|
// 设置IP
|
||||||
HttpServletRequest request = ServletKit.getRequest();
|
this.loginIp = ServletKit.getClientIP();
|
||||||
this.loginIp = ServletKit.getClientIP(request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import com.tiesheng.util.service.TsCacheService;
|
|||||||
import com.tiesheng.util.service.TsServiceBase;
|
import com.tiesheng.util.service.TsServiceBase;
|
||||||
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -36,7 +35,12 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
|||||||
TsLoginConfigurer tsLoginConfigurer;
|
TsLoginConfigurer tsLoginConfigurer;
|
||||||
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
/**
|
||||||
|
* 登录操作
|
||||||
|
*
|
||||||
|
* @param loginInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public TokenBean login(DoLoginInfo loginInfo) {
|
public TokenBean login(DoLoginInfo loginInfo) {
|
||||||
|
|
||||||
int loginErrorTimes = coreLogLoginMapper.getLoginErrorTimes(loginInfo.getLoginIp());
|
int loginErrorTimes = coreLogLoginMapper.getLoginErrorTimes(loginInfo.getLoginIp());
|
||||||
@@ -70,8 +74,7 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
|||||||
|
|
||||||
// 更新唯一值
|
// 更新唯一值
|
||||||
String oldUserId = platformUnique.getUserId();
|
String oldUserId = platformUnique.getUserId();
|
||||||
if (!StrUtil.isEmpty(tokenBean.getId()) &&
|
if (!Objects.equals(oldUserId, tokenBean.getId())) {
|
||||||
!Objects.equals(oldUserId, tokenBean.getId())) {
|
|
||||||
platformUnique.setUserId(tokenBean.getId());
|
platformUnique.setUserId(tokenBean.getId());
|
||||||
saveOrUpdate(platformUnique);
|
saveOrUpdate(platformUnique);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,11 @@
|
|||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="getLoginErrorTimes" resultType="int">
|
<select id="getLoginErrorTimes" resultType="int">
|
||||||
select count(1)
|
select count(1)
|
||||||
from core_log_login
|
from core_log_login
|
||||||
where ip = #{ip}
|
where ip = #{ip}
|
||||||
and create_time > date_add(now(), interval -10 minute)
|
and result = 0
|
||||||
|
and create_time > date_add(now(), interval -10 minute)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-message</artifactId>
|
<artifactId>springboot-message</artifactId>
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class AliyunSmsSender implements TsMessageSender {
|
|||||||
String signature = specialUrlEncode(digest);
|
String signature = specialUrlEncode(digest);
|
||||||
queryMap.put("Signature", signature);
|
queryMap.put("Signature", signature);
|
||||||
|
|
||||||
String respBody = "";
|
String respBody;
|
||||||
try {
|
try {
|
||||||
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
|
respBody = OkHttpUtil.get(ENDPOINT + "?Signature=" + signature + sortQueryStringTmp);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-platform</artifactId>
|
<artifactId>springboot-platform</artifactId>
|
||||||
|
|||||||
@@ -76,15 +76,16 @@ public class PlatformDingConfig {
|
|||||||
request = OkHttpUtil.ofPost(url, body);
|
request = OkHttpUtil.ofPost(url, body);
|
||||||
}
|
}
|
||||||
request = request.newBuilder().header("x-acs-dingtalk-access-token", accessToken).build();
|
request = request.newBuilder().header("x-acs-dingtalk-access-token", accessToken).build();
|
||||||
try {
|
try (Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute()) {
|
||||||
Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
|
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
String rawBody = response.body().string();
|
String rawBody = response.body().string();
|
||||||
DingResponse<T> bean = JSON.parseObject(rawBody, typeReference);
|
DingResponse<T> bean = JSON.parseObject(rawBody, typeReference);
|
||||||
bean.setRawBody(rawBody);
|
bean.setRawBody(rawBody);
|
||||||
return bean;
|
return bean;
|
||||||
} else {
|
} else {
|
||||||
LogFactory.get().info(response.body().string());
|
if (response.body() != null) {
|
||||||
|
LogFactory.get().info(response.body().string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogFactory.get().error(e);
|
LogFactory.get().error(e);
|
||||||
@@ -246,7 +247,7 @@ public class PlatformDingConfig {
|
|||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("dept_id", deptId);
|
object.put("dept_id", deptId);
|
||||||
object.put("cursor", cursor);
|
object.put("cursor", cursor);
|
||||||
object.put("size", 100);
|
object.put("size", 200);
|
||||||
|
|
||||||
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list",
|
return doRequest(service, "https://oapi.dingtalk.com/topapi/v2/user/list",
|
||||||
object, new TypeReference<DingResponse<DingUserListVo>>() {
|
object, new TypeReference<DingResponse<DingUserListVo>>() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-role</artifactId>
|
<artifactId>springboot-role</artifactId>
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
coreRoleGroupRxMapper.batchInsert(list);
|
coreRoleGroupRxMapper.batchInsert(list);
|
||||||
onRoleChange(dto.getId(), "");
|
onRoleChange(dto.getId(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +147,9 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
|||||||
* @param roleUser
|
* @param roleUser
|
||||||
*/
|
*/
|
||||||
public void roleUserUpdate(CoreRoleUser roleUser) {
|
public void roleUserUpdate(CoreRoleUser roleUser) {
|
||||||
|
Validator.validateNotEmpty(roleUser.getType(), "请选择授权方式");
|
||||||
|
Validator.validateNotEmpty(roleUser.getTypeId(), "请选择授权" + (Objects.equals(roleUser.getType(), "menu") ? "菜单" : "职位"));
|
||||||
|
|
||||||
if (StrUtil.isNotEmpty(roleUser.getId())) {
|
if (StrUtil.isNotEmpty(roleUser.getId())) {
|
||||||
coreRoleUserMapper.updateById(roleUser);
|
coreRoleUserMapper.updateById(roleUser);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class RoleAuthorityHandler implements TsAuthorityHandler {
|
|||||||
groupAuthority.setParent(parentId);
|
groupAuthority.setParent(parentId);
|
||||||
groupAuthority.setVersion(version);
|
groupAuthority.setVersion(version);
|
||||||
groupAuthority.setSource("auto");
|
groupAuthority.setSource("auto");
|
||||||
|
groupAuthority.setDeps("[]");
|
||||||
groupAuthority.setId(StrUtil.join("_", groupAuthority.getService(), groupAuthority.getNo()));
|
groupAuthority.setId(StrUtil.join("_", groupAuthority.getService(), groupAuthority.getNo()));
|
||||||
list.add(groupAuthority);
|
list.add(groupAuthority);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-util</artifactId>
|
<artifactId>springboot-util</artifactId>
|
||||||
|
|||||||
@@ -17,7 +17,25 @@ public class ServletKit extends ServletUtil {
|
|||||||
public static HttpServletRequest getRequest() {
|
public static HttpServletRequest getRequest() {
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes)
|
ServletRequestAttributes attributes = (ServletRequestAttributes)
|
||||||
RequestContextHolder.getRequestAttributes();
|
RequestContextHolder.getRequestAttributes();
|
||||||
return attributes.getRequest();
|
if (attributes != null) {
|
||||||
|
return attributes.getRequest();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求头
|
||||||
|
*
|
||||||
|
* @param name 请求头
|
||||||
|
* @return 请求头
|
||||||
|
*/
|
||||||
|
public static String getHeader(String name) {
|
||||||
|
HttpServletRequest request = getRequest();
|
||||||
|
if (request == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return getHeader(request, name, "utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +45,9 @@ public class ServletKit extends ServletUtil {
|
|||||||
*/
|
*/
|
||||||
public static String getClientIP() {
|
public static String getClientIP() {
|
||||||
HttpServletRequest request = getRequest();
|
HttpServletRequest request = getRequest();
|
||||||
|
if (request == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return getClientIP(request);
|
return getClientIP(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class EncryptConfig {
|
|||||||
private String key = "WmdUzPJXbngVNiaSsQrihg==";
|
private String key = "WmdUzPJXbngVNiaSsQrihg==";
|
||||||
private Integer saltSize = 8;
|
private Integer saltSize = 8;
|
||||||
private boolean body = false;
|
private boolean body = false;
|
||||||
|
private String pwdPatten = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
|
||||||
|
|
||||||
public EncryptConfig() {
|
public EncryptConfig() {
|
||||||
sm4 = SmUtil.sm4(Base64.decode(getKey()));
|
sm4 = SmUtil.sm4(Base64.decode(getKey()));
|
||||||
@@ -73,25 +74,13 @@ public class EncryptConfig {
|
|||||||
if (StrUtil.isEmpty(salt) || StrUtil.length(salt) != getSaltSize()) {
|
if (StrUtil.isEmpty(salt) || StrUtil.length(salt) != getSaltSize()) {
|
||||||
salt = RandomUtil.randomString(saltSize);
|
salt = RandomUtil.randomString(saltSize);
|
||||||
}
|
}
|
||||||
if (!passwdComplexity(inputPasswd)) {
|
if (!inputPasswd.matches(getPwdPatten())) {
|
||||||
throw new ApiException("需要包含数字、大小写字母、特殊符号,且长度不低于8位");
|
throw new ApiException("密码复杂度不够,请重新设置");
|
||||||
}
|
}
|
||||||
return encrypt(salt + SecureUtil.sha1(salt + inputPasswd));
|
return encrypt(salt + SecureUtil.sha1(salt + inputPasswd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 复杂度校验
|
|
||||||
*
|
|
||||||
* @param inputPasswd
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean passwdComplexity(String inputPasswd) {
|
|
||||||
String password = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
|
|
||||||
return inputPasswd.matches(password);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码校验
|
* 密码校验
|
||||||
*
|
*
|
||||||
@@ -133,4 +122,12 @@ public class EncryptConfig {
|
|||||||
public void setBody(boolean body) {
|
public void setBody(boolean body) {
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPwdPatten() {
|
||||||
|
return pwdPatten;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPwdPatten(String pwdPatten) {
|
||||||
|
this.pwdPatten = pwdPatten;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
|||||||
* @since 5.7.4
|
* @since 5.7.4
|
||||||
*/
|
*/
|
||||||
public boolean validate(long leeway) {
|
public boolean validate(long leeway) {
|
||||||
if (false == verify()) {
|
if (!verify()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.tiesheng.util.jwt;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.tiesheng.util.jwt.signers.JWTSigner;
|
import com.tiesheng.util.jwt.signers.JWTSigner;
|
||||||
import com.tiesheng.util.jwt.signers.NoneJWTSigner;
|
import com.tiesheng.util.jwt.signers.NoneJWTSigner;
|
||||||
@@ -160,13 +161,13 @@ public class JWTValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String algorithmIdInSigner = signer.getAlgorithmId();
|
final String algorithmIdInSigner = signer.getAlgorithmId();
|
||||||
if (false == StrUtil.equals(algorithmId, algorithmIdInSigner)) {
|
if (!StrUtil.equals(algorithmId, algorithmIdInSigner)) {
|
||||||
throw new ValidateException("Algorithm [{}] defined in header doesn't match to [{}]!"
|
throw new ValidateException("Algorithm [{}] defined in header doesn't match to [{}]!"
|
||||||
, algorithmId, algorithmIdInSigner);
|
, algorithmId, algorithmIdInSigner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通过算法验证签名是否正确
|
// 通过算法验证签名是否正确
|
||||||
if (false == jwt.verify(signer)) {
|
if (!jwt.verify(signer)) {
|
||||||
throw new ValidateException("Signature verification failed!");
|
throw new ValidateException("Signature verification failed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,7 +201,10 @@ public class JWTValidator {
|
|||||||
validateNotAfter(JWTPayload.NOT_BEFORE, notBefore, now, leeway);
|
validateNotAfter(JWTPayload.NOT_BEFORE, notBefore, now, leeway);
|
||||||
|
|
||||||
// 检查失效时间(失效时间不能早于当前时间)
|
// 检查失效时间(失效时间不能早于当前时间)
|
||||||
final Date expiresAt = payload.getClaimsJson().getDate(JWTPayload.EXPIRES_AT);
|
// 这里兼容一下旧版本,旧版本使用的是10位数的秒作为数据
|
||||||
|
String string = payload.getClaimsJson().getString(JWTPayload.EXPIRES_AT);
|
||||||
|
Date expiresAt = StrUtil.length(string) == 10 ? DateUtil.date(NumberUtil.parseLong(string) * 1000L)
|
||||||
|
: DateUtil.parse(string);
|
||||||
validateNotBefore(JWTPayload.EXPIRES_AT, expiresAt, now, leeway);
|
validateNotBefore(JWTPayload.EXPIRES_AT, expiresAt, now, leeway);
|
||||||
|
|
||||||
// 检查签发时间(签发时间不能晚于当前时间)
|
// 检查签发时间(签发时间不能晚于当前时间)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class TsCacheService {
|
|||||||
* 验证 图片验证码
|
* 验证 图片验证码
|
||||||
*/
|
*/
|
||||||
public void verifyCaptcha(String value) {
|
public void verifyCaptcha(String value) {
|
||||||
String captchaKey = ServletUtil.getHeader(ServletKit.getRequest(), "captcha", "utf-8");
|
String captchaKey = ServletKit.getHeader("captcha");
|
||||||
String cache = get(captchaKey);
|
String cache = get(captchaKey);
|
||||||
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
|
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
|
||||||
throw new ApiException("验证码不正确");
|
throw new ApiException("验证码不正确");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class, TsCacheTimedHandler.class})
|
@ConditionalOnMissingBean(value = TsCacheHandler.class, ignored = {TsCacheTimedHandler.class})
|
||||||
public class TsCacheTimedHandler implements TsCacheHandler {
|
public class TsCacheTimedHandler implements TsCacheHandler {
|
||||||
|
|
||||||
private static volatile TimedCache<String, String> timedCache;
|
private static volatile TimedCache<String, String> timedCache;
|
||||||
|
|||||||
@@ -83,9 +83,11 @@ public class OkHttpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String get(String urlString, int timeout) {
|
public static String get(String urlString, int timeout) {
|
||||||
try {
|
try (Response execute = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||||
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
.build().newCall(ofGet(urlString)).execute()) {
|
||||||
.build().newCall(ofGet(urlString)).execute().body().string();
|
if (execute.body() != null) {
|
||||||
|
return execute.body().string();
|
||||||
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -117,9 +119,11 @@ public class OkHttpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String post(String urlString, RequestBody body, int timeout) {
|
public static String post(String urlString, RequestBody body, int timeout) {
|
||||||
try {
|
try (Response response = ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
||||||
return ofHttpClient().connectTimeout(timeout, TimeUnit.MILLISECONDS)
|
.build().newCall(ofPost(urlString, body)).execute()) {
|
||||||
.build().newCall(ofPost(urlString, body)).execute().body().string();
|
if (response.body() != null) {
|
||||||
|
return response.body().string();
|
||||||
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -135,11 +139,10 @@ public class OkHttpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static File downloadFile(String url, File destFile) {
|
public static File downloadFile(String url, File destFile) {
|
||||||
try {
|
try (Response response = ofHttpClient()
|
||||||
Response response = ofHttpClient()
|
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
.build().newCall(ofGet(url)).execute()) {
|
||||||
.build().newCall(ofGet(url)).execute();
|
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
FileUtil.writeFromStream(response.body().byteStream(), destFile);
|
FileUtil.writeFromStream(response.body().byteStream(), destFile);
|
||||||
}
|
}
|
||||||
@@ -150,11 +153,10 @@ public class OkHttpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] downloadBytes(String url) {
|
public static byte[] downloadBytes(String url) {
|
||||||
try {
|
try (Response response = ofHttpClient()
|
||||||
Response response = ofHttpClient()
|
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
||||||
.connectTimeout(0, TimeUnit.MILLISECONDS)
|
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
.build().newCall(ofGet(url)).execute()) {
|
||||||
.build().newCall(ofGet(url)).execute();
|
|
||||||
if (response.isSuccessful() && response.body() != null) {
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
return response.body().bytes();
|
return response.body().bytes();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||||
<artifactId>springboot-parent</artifactId>
|
<artifactId>springboot-parent</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>springboot-web</artifactId>
|
<artifactId>springboot-web</artifactId>
|
||||||
|
|||||||
@@ -56,8 +56,12 @@ public class OperationAspect {
|
|||||||
@Around("methodArgs()")
|
@Around("methodArgs()")
|
||||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
|
||||||
// GET请求不处理
|
|
||||||
HttpServletRequest request = ServletKit.getRequest();
|
HttpServletRequest request = ServletKit.getRequest();
|
||||||
|
if (request == null) {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET请求不处理
|
||||||
if (StrUtil.equalsIgnoreCase(request.getMethod(), "GET")) {
|
if (StrUtil.equalsIgnoreCase(request.getMethod(), "GET")) {
|
||||||
return joinPoint.proceed(joinPoint.getArgs());
|
return joinPoint.proceed(joinPoint.getArgs());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.aspectj.lang.JoinPoint;
|
|||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
|
@ConditionalOnBean(value = TsAuthorityHandler.class)
|
||||||
public class RoleAuthorityAspect {
|
public class RoleAuthorityAspect {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import com.tiesheng.annotation.role.RoleAuthority;
|
import com.tiesheng.annotation.role.RoleAuthority;
|
||||||
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
import com.tiesheng.util.service.role.TsAuthorityHandler;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -18,19 +19,15 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ConditionalOnBean(value = TsAuthorityHandler.class)
|
||||||
public class RoleAuthorityCreator implements ApplicationListener<ContextRefreshedEvent> {
|
public class RoleAuthorityCreator implements ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Resource
|
||||||
TsAuthorityHandler tsAuthorityHandler;
|
TsAuthorityHandler tsAuthorityHandler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
|
||||||
if (tsAuthorityHandler == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationContext applicationContext = event.getApplicationContext();
|
ApplicationContext applicationContext = event.getApplicationContext();
|
||||||
Map<String, Object> beansOfType = applicationContext.getBeansWithAnnotation(RoleAuthority.class);
|
Map<String, Object> beansOfType = applicationContext.getBeansWithAnnotation(RoleAuthority.class);
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ public class ImageCodeDTO {
|
|||||||
if (height == null) {
|
if (height == null) {
|
||||||
height = 62;
|
height = 62;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
width = Math.min(width, 500);
|
||||||
|
height = Math.min(height, 200);
|
||||||
|
|
||||||
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(width, height, 4, lineCount);
|
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(width, height, 4, lineCount);
|
||||||
lineCaptcha.setGenerator(new RandomGenerator("0123456789", 4));
|
lineCaptcha.setGenerator(new RandomGenerator("0123456789", 4));
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import javax.annotation.Resource;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class LogApiOkHttpInterceptor implements Interceptor {
|
public class OkHttpLogInterceptor implements Interceptor {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
CoreLogApiMapper coreLogApiMapper;
|
CoreLogApiMapper coreLogApiMapper;
|
||||||
@@ -36,11 +36,14 @@ public class LogApiOkHttpInterceptor implements Interceptor {
|
|||||||
logApi.setResult(response.code());
|
logApi.setResult(response.code());
|
||||||
|
|
||||||
// 如果是json,xml,text,则保存记录
|
// 如果是json,xml,text,则保存记录
|
||||||
if (response.body() != null && StrUtil.containsAll(response.body().contentType().toString(),
|
if (response.body() != null) {
|
||||||
"json", "xml", "text")) {
|
MediaType mediaType = response.body().contentType();
|
||||||
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
|
String contentType = mediaType == null ? "" : mediaType.toString();
|
||||||
logApi.setRespBody(peekBody.string());
|
if (StrUtil.containsAny(contentType, "json", "xml", "text")) {
|
||||||
peekBody.close();
|
ResponseBody peekBody = response.peekBody(Long.MAX_VALUE);
|
||||||
|
logApi.setRespBody(peekBody.string());
|
||||||
|
peekBody.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
@@ -52,6 +55,9 @@ public class LogApiOkHttpInterceptor implements Interceptor {
|
|||||||
|
|
||||||
response = new Response.Builder()
|
response = new Response.Builder()
|
||||||
.request(request)
|
.request(request)
|
||||||
|
.protocol(Protocol.HTTP_1_1)
|
||||||
|
.code(logApi.getResult())
|
||||||
|
.message(e.getMessage())
|
||||||
.body(OkHttpUtil.ofJsonResponse(logApi.getRespBody()))
|
.body(OkHttpUtil.ofJsonResponse(logApi.getRespBody()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user