Compare commits

...

22 Commits
0.6.1 ... 0.8.2

Author SHA1 Message Date
曾文豪
fe9d107eef publish 0.8.2 2023-03-07 15:16:53 +08:00
曾文豪
0094bf2e69 perf: 加解密数据处理 2023-03-07 15:16:26 +08:00
曾文豪
c0fb149558 perf:添加一个是否成功的方法 2023-03-07 14:38:46 +08:00
曾文豪
eb55969063 publish 0.8.1 2023-03-07 09:52:48 +08:00
曾文豪
488c53def0 publish 0.8.0 2023-03-06 15:35:39 +08:00
曾文豪
c02e67f85f perf;对数据库文件排序后执行 2023-03-06 14:02:27 +08:00
曾文豪
9f62986a1e perf;优化log日志 2023-02-28 11:35:33 +08:00
曾文豪
07136a6679 publish 0.7.4 2023-02-28 11:32:45 +08:00
曾文豪
c3edb50e80 perf;区分token过期 2023-02-27 09:54:27 +08:00
曾文豪
aee1861630 publish 0.7.3 2023-02-26 18:57:10 +08:00
曾文豪
4196b2531d perf;PasswordUtils校验调整 2023-02-26 12:12:42 +08:00
曾文豪
dfaeacae92 perf;调整TsTokenConfig中的ignores 2023-02-26 11:10:51 +08:00
曾文豪
b304c48dd1 perf;调整TsTokenConfig中的ignores 2023-02-26 11:10:33 +08:00
曾文豪
d045534be6 perf;调整TsTokenConfig中的ignores 2023-02-26 11:09:05 +08:00
曾文豪
56b923f5db publish 0.7.2 2023-02-24 18:42:42 +08:00
曾文豪
f3e8231814 fixed:修复登录日志中未正确保存userId的bug 2023-02-24 12:02:32 +08:00
曾文豪
2ca04e654f perf:tokenignore提到类上面 2023-02-23 14:03:26 +08:00
曾文豪
149f4ab061 publish 0.7.1 2023-02-23 12:13:55 +08:00
曾文豪
a22c08738a publish 0.7.0 2023-02-23 11:57:01 +08:00
曾文豪
d28f3250e3 perf:优化脱敏类 2023-02-22 12:52:14 +08:00
曾文豪
bf3b88b43b publish 0.6.2 2023-02-22 12:16:51 +08:00
曾文豪
0a98e81109 perf:标记为false,可以不实现 2023-02-22 12:04:45 +08:00
40 changed files with 522 additions and 304 deletions

25
CHANGELOG.md Normal file
View File

@@ -0,0 +1,25 @@
## 0.8.0
### 调整
> 1移除**PasswordUtil**类,新增**EncryptConfig**配置;
> 2默认启用网络请求的加解密前端请配合接口使用。
## 0.7.4
### 新增
> 现在操作日志默认收集不包括GET请求使用方法名称和接口作为参数存储。如果存在OperationLog注解则使用注解的内容。
## 0.7.3
### 增加
> 1TsTokenConfig增加新的属性**ignorePaths**用于通过路径忽略token
> 2PasswordUtils增加密码复杂度校验方法
> 3PasswordUtils.verifyPassword增加登录次数限制10分钟内不能错误6次
>
### 调整
> 1TsTokenConfig中的**ignores**属性调整为**testMap**

4
README.md Normal file
View File

@@ -0,0 +1,4 @@
## 杭州铁晟科技有限公司基础项目
更新日志可点击查看[changelog](./CHANGELOG.md ':include')

22
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
<packaging>pom</packaging>
<name>springboot-parent</name>
<description>杭州铁晟科技有限公司基础依赖</description>
@@ -57,55 +57,55 @@
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-database</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-login</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-web</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-util</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-platform</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-message</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-encrypt</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-poi</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</dependency>
<dependency>
@@ -136,7 +136,7 @@
<plugin>
<groupId>com.tiesheng.springboot-plugin</groupId>
<artifactId>tiesheng-maven-plugin</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
<executions>
<execution>
<goals>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-ademo</artifactId>

View File

@@ -3,6 +3,7 @@ package com.tiesheng.demo;
import com.tiesheng.core.EnableTieshengWeb;
import com.tiesheng.demo.config.DemoWebConfigurer;
import com.tiesheng.encrypt.EnableEncryptConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -13,6 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@SpringBootApplication
@EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class)
@EnableEncryptConfig
public class DemoApplication {
public static void main(String[] args) {

View File

@@ -1,7 +1,7 @@
package com.tiesheng.demo.config;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.core.pojos.CurrentWebUser;
import com.tiesheng.core.pojos.RequestUserInfo;
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
import com.tiesheng.core.service.TieshengWebConfigurer;
import com.tiesheng.login.config.token.bean.TokenBean;
@@ -19,8 +19,11 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
GlobalConfig globalConfig;
@Override
public CurrentWebUser getCurrentUserName(TokenBean tokenBean) {
return null;
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
RequestUserInfo info = new RequestUserInfo();
info.setId("1");
info.setName("test");
return info;
}
@Override

View File

@@ -1,12 +1,15 @@
package com.tiesheng.demo.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.demo.pojos.TestFile;
import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.login.config.token.bean.TokenBean;
import com.tiesheng.message.config.aliyun.AliyunSmsConfig;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.util.config.EncryptConfig;
import com.tiesheng.util.config.GlobalConfig;
import com.tiesheng.util.config.Ip2regionConfig;
import com.tiesheng.util.pojos.ApiResp;
@@ -16,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author hao
@@ -32,6 +36,8 @@ public class TestController {
TsTokenConfig tsTokenConfig;
@Autowired
Ip2regionConfig ip2regionConfig;
@Autowired
EncryptConfig encryptConfig;
@RequestMapping("/index")
@@ -47,13 +53,12 @@ public class TestController {
@RequestMapping("/redirect")
@TokenIgnore
public void redirect(HttpServletResponse response) {
tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
// globalConfig.redirect("mobile", "/test", response);
}
@RequestMapping("/send")
@TokenIgnore
public ApiResp<MessageReqResp> sendMessage() {
MessageReqResp reqResp = aliyunSmsConfig.sendSms("13567116463", "SMS_154950909",
JSONUtil.createObj().putOpt("code", "123456"));
@@ -92,4 +97,25 @@ public class TestController {
return ApiResp.respOK(search);
}
@RequestMapping("desensitize")
@TokenIgnore
public ApiResp<List<TestFile>> desensitize() {
TestFile file = new TestFile("11111");
TestFile file1 = new TestFile("22222");
return ApiResp.respOK(CollUtil.newArrayList(file, file1));
}
@RequestMapping("passwd")
@TokenIgnore
public ApiResp<String> passwd() {
String passwdCreate = encryptConfig.passwdCreate("12345Zeng!", "");
LogFactory.get().info(passwdCreate);
encryptConfig.passwdVerify("12345Zeng!", passwdCreate);
return ApiResp.respOK("");
}
}

View File

@@ -1,27 +1,27 @@
//package com.tiesheng.demo.pojos;
//
//import com.alibaba.excel.annotation.ExcelProperty;
//import com.tiesheng.poi.pojos.PoiWriteBase;
//
//public class TestFile implements PoiWriteBase {
//
//
// @ExcelProperty("测试")
// private String test;
//
// public TestFile(String test) {
// this.test = test;
// }
//
// ///////////////////////////////////////////////////////////////////////////
// // setter、getter
// ///////////////////////////////////////////////////////////////////////////
//
// public String getTest() {
// return test;
// }
//
// public void setTest(String test) {
// this.test = test;
// }
//}
package com.tiesheng.demo.pojos;
import com.tiesheng.annotation.desensitize.Desensitize;
import com.tiesheng.poi.pojos.PoiWriteBase;
public class TestFile implements PoiWriteBase {
@Desensitize()
private String test;
public TestFile(String test) {
this.test = test;
}
///////////////////////////////////////////////////////////////////////////
// setter、getter
///////////////////////////////////////////////////////////////////////////
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}

View File

@@ -16,7 +16,7 @@ platform:
tiesheng:
token:
ignores:
test-map:
"1111":
id: "1111"
global:

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-annotation</artifactId>

View File

@@ -0,0 +1,16 @@
package com.tiesheng.annotation.desensitize;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @author hao
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Desensitize {
int prefix() default 1;
int suffix() default 1;
}

View File

@@ -1,12 +0,0 @@
package com.tiesheng.annotation.encrypt;
import java.lang.annotation.*;
/**
* @author hao
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EncryptedRespBody {
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-database</artifactId>

View File

@@ -4,7 +4,6 @@ package com.tiesheng.database.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.func.VoidFunc1;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;
@@ -20,6 +19,8 @@ import javax.servlet.ServletContext;
import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.zip.Checksum;
@@ -35,7 +36,7 @@ public class DbMigrationInitializer implements ServletContextInitializer {
DataSource dataSource;
@Autowired
DbMigrationConfig dbMigrationConfig;
@Autowired
@Autowired(required = false)
List<DbDataInitializer> dbDataInitializerList;
@@ -43,7 +44,9 @@ public class DbMigrationInitializer implements ServletContextInitializer {
public void onStartup(ServletContext servletContext) {
try {
startDeal();
dbDataInitializerList.forEach(DbDataInitializer::init);
if (dbDataInitializerList != null) {
dbDataInitializerList.forEach(DbDataInitializer::init);
}
} catch (Exception ignore) {
}
}
@@ -59,14 +62,16 @@ public class DbMigrationInitializer implements ServletContextInitializer {
dbMigrationConfig.checkDbExists(coreDb);
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
List<Resource> resourceList = new ArrayList<>();
for (String location : dbMigrationConfig.getLocations()) {
Resource[] resources = patternResolver.getResources(location);
if (ArrayUtil.isEmpty(resources)) {
return;
}
for (Resource resource : resources) {
migrationByResource(resource, coreDb);
}
resourceList.addAll(Arrays.asList(resources));
}
// 排序后执行sql
resourceList.sort((o1, o2) -> StrUtil.compare(o1.getFilename(), o2.getFilename(), true));
for (Resource resource : resourceList) {
migrationByResource(resource, coreDb);
}
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-encrypt</artifactId>
@@ -18,11 +18,6 @@
</properties>
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.68</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -1,20 +1,21 @@
package com.tiesheng.encrypt;
import com.tiesheng.encrypt.config.EncryptConfig;
import com.tiesheng.encrypt.config.EncryptRequestBodyAdvice;
import com.tiesheng.encrypt.config.DecryptRequestBodyAdvice;
import com.tiesheng.encrypt.config.EncryptResponseBodyAdvice;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author hao
*/
@Configuration
@ComponentScan(basePackageClasses = {
EncryptConfig.class,
EncryptRequestBodyAdvice.class,
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Import({
DecryptRequestBodyAdvice.class,
EncryptResponseBodyAdvice.class,
})
public class EnableEncryptConfig {
public @interface EnableEncryptConfig {
}

View File

@@ -3,13 +3,8 @@ package com.tiesheng.encrypt.config;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.ECKeyUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;
import cn.hutool.json.JSONUtil;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import com.tiesheng.util.config.EncryptConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
@@ -26,7 +21,7 @@ import java.nio.charset.Charset;
* @author hao
*/
@ControllerAdvice
public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
@Autowired
@@ -42,12 +37,8 @@ public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) {
if (!encryptConfig.isEnable()) {
return inputMessage;
}
try {
return new DecryptHttpInputMessage(inputMessage, encryptConfig.getPrivateQ());
return new DecryptHttpInputMessage(inputMessage, encryptConfig);
} catch (Exception ignore) {
}
@@ -72,16 +63,12 @@ public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
private HttpHeaders headers;
private InputStream body;
DecryptHttpInputMessage(HttpInputMessage inputMessage, String privateQ) throws Exception {
DecryptHttpInputMessage(HttpInputMessage inputMessage, EncryptConfig encryptConfig) throws Exception {
this.headers = inputMessage.getHeaders();
String bodyStr = IoUtil.read(inputMessage.getBody(), CharsetUtil.CHARSET_UTF_8);
String encryptData = JSONUtil.parseObj(bodyStr).getStr("encryptData");
if (!StrUtil.isEmpty(encryptData)) {
// 部分语言加密之后缺少04前缀如果解密失败可尝试增加04
ECPrivateKeyParameters privateKeyParameters = ECKeyUtil.toSm2PrivateParams(privateQ);
ECPublicKeyParameters publicKeyParameters = ECKeyUtil.getPublicParams(privateKeyParameters);
SM2 sm2 = SmUtil.sm2(privateKeyParameters, publicKeyParameters);
String decrypt = sm2.decryptStr(encryptData, KeyType.PrivateKey);
String decrypt = encryptConfig.decrypt(encryptData);
this.body = IoUtil.toStream(decrypt, Charset.defaultCharset());
} else {
this.body = IoUtil.toStream(bodyStr, Charset.defaultCharset());

View File

@@ -1,44 +0,0 @@
package com.tiesheng.encrypt.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author hao
*/
@Configuration
@ConfigurationProperties(prefix = "tiesheng.encrypt")
public class EncryptConfig {
public String publicD;
public String privateQ;
private boolean enable = false;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getPublicD() {
return publicD;
}
public void setPublicD(String publicD) {
this.publicD = publicD;
}
public String getPrivateQ() {
return privateQ;
}
public void setPrivateQ(String privateQ) {
this.privateQ = privateQ;
}
}

View File

@@ -1,17 +1,10 @@
package com.tiesheng.encrypt.config;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.ECKeyUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
import com.tiesheng.annotation.encrypt.EncryptedRespBody;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import com.tiesheng.util.CommonUtil;
import com.tiesheng.util.config.EncryptConfig;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
@@ -19,6 +12,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@@ -26,50 +20,30 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
* @author hao
*/
@ControllerAdvice
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<Object> {
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<ApiResp> {
@Autowired
EncryptConfig encryptConfig;
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return true;
return AnnotationUtil.getAnnotation(returnType.getContainingClass(), RestController.class) != null;
}
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
public ApiResp beforeBodyWrite(ApiResp body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
if (!encryptConfig.isEnable()) {
return body;
}
boolean encrypt = AnnotationUtil.getAnnotation(returnType.getContainingClass(), EncryptedRespBody.class) != null;
if (!encrypt) {
return body;
}
try {
String content = JSONUtil.toJsonStr(body);
String respData = JSONUtil.parseObj(content).getStr("data");
if (StrUtil.isEmpty(respData)) {
// 无需加密
Object data = body.getData();
if (data == null || !body.successful()) {
return body;
}
JSONObject resp = JSONUtil.parseObj(content);
resp.set("encrypted", true);
if (resp.getInt("code") == 200) {
// 用公钥进行加密
ECPrivateKeyParameters privateKeyParameters = ECKeyUtil.toSm2PrivateParams(encryptConfig.getPrivateQ());
ECPublicKeyParameters publicKeyParameters = ECKeyUtil.getPublicParams(privateKeyParameters);
SM2 sm2 = SmUtil.sm2(privateKeyParameters, publicKeyParameters);
String decrypt = sm2.encryptHex(respData, KeyType.PublicKey);
resp.set("data", decrypt.substring(2));
}
return resp;
body.setEncrypt(true);
body.setData(encryptConfig.encrypt(CommonUtil.writeJsonString(data)));
return body;
} catch (Exception var17) {
LogFactory.get().info("加密数据异常", var17);
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-login</artifactId>

View File

@@ -1,6 +1,8 @@
package com.tiesheng.login.config.token;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.util.ServletKit;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@@ -46,13 +48,18 @@ public class TsTokenAspect {
@Before("methodArgs()")
public void before(JoinPoint joinPoint) {
// 过滤不要需要验证的接口path
String requestURI = ServletKit.getRequest().getRequestURI();
if (StrUtil.startWithAnyIgnoreCase(requestURI, tsTokenConfig.getIgnorePaths())) {
return;
}
// 过滤不要需要验证的接口(注解)
Object aThis = joinPoint.getTarget();
TokenIgnore annotation = aThis.getClass().getAnnotation(TokenIgnore.class);
if (annotation != null) {
return;
}
// 过滤不要需要验证的接口
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
TokenIgnore apiTokenIgnore = method.getAnnotation(TokenIgnore.class);

View File

@@ -1,7 +1,6 @@
package com.tiesheng.login.config.token;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
@@ -24,9 +23,10 @@ import java.util.Map;
@ConfigurationProperties("tiesheng.token")
public class TsTokenConfig {
private Map<String, TokenBean> ignores = MapUtil.newHashMap();
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
private String encryptKey = "%kIp9frQCu";
private Integer expireHours = 48;
private String[] ignorePaths;
/**
@@ -57,11 +57,11 @@ public class TsTokenConfig {
* @param token
* @return
*/
public TokenBean isIgnored(String token) {
if (ignores == null) {
public TokenBean isTestToken(String token) {
if (testMap == null) {
return null;
}
return ignores.get(token);
return testMap.get(token);
}
@@ -83,7 +83,7 @@ public class TsTokenConfig {
* @return
*/
public TokenBean validToken(String token, boolean thrExp) {
TokenBean tokenBean = isIgnored(token);
TokenBean tokenBean = isTestToken(token);
if (tokenBean != null) {
return tokenBean;
}
@@ -101,7 +101,8 @@ public class TsTokenConfig {
}
if (tokenBean == null && thrExp) {
throw new ApiException(StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
throw new ApiException(StrUtil.isEmpty(token) ? 110 : 112,
StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
}
if (tokenBean == null) {
@@ -116,12 +117,12 @@ public class TsTokenConfig {
// setter\getter
///////////////////////////////////////////////////////////////////////////
public Map<String, TokenBean> getIgnores() {
return ignores;
public Map<String, TokenBean> getTestMap() {
return testMap;
}
public void setIgnores(Map<String, TokenBean> ignores) {
this.ignores = ignores;
public void setTestMap(Map<String, TokenBean> testMap) {
this.testMap = testMap;
}
public String getEncryptKey() {
@@ -139,4 +140,12 @@ public class TsTokenConfig {
public void setExpireHours(Integer expireHours) {
this.expireHours = expireHours;
}
public String[] getIgnorePaths() {
return ignorePaths;
}
public void setIgnorePaths(String[] ignorePaths) {
this.ignorePaths = ignorePaths;
}
}

View File

@@ -35,6 +35,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/login")
@TokenIgnore
public class LoginController {
@@ -56,7 +57,6 @@ public class LoginController {
* @return
*/
@GetMapping("/unique/redirect")
@TokenIgnore
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
@@ -71,7 +71,6 @@ public class LoginController {
* @return
*/
@PostMapping("/unique/index")
@TokenIgnore
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
@@ -94,7 +93,6 @@ public class LoginController {
* @param response
*/
@GetMapping("/ding/index/{service}")
@TokenIgnore
public void dingIndex(@PathVariable String service, String extra, HttpServletResponse response) {
if (StrUtil.isEmpty(extra)) {
extra = "";
@@ -118,7 +116,6 @@ public class LoginController {
* @param service
*/
@RequestMapping("/ding/oauth2/{service}")
@TokenIgnore
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
@@ -136,7 +133,6 @@ public class LoginController {
* @return
*/
@GetMapping("/ding/jssdk/{service}")
@TokenIgnore
public ApiResp<DingJsapiSignature> dingJssdk(@PathVariable String service, String url) {
DingJsapiSignature jsapiSignature = platformDingConfig.createJsapiSignature(service, url);
return ApiResp.respOK(jsapiSignature);
@@ -154,7 +150,6 @@ public class LoginController {
* @return
*/
@RequestMapping("/wxmp/index/{service}")
@TokenIgnore
public void wxmpIndex(@PathVariable String service, String extra, HttpServletResponse response) throws IOException {
if (StrUtil.isEmpty(extra)) {
extra = "";
@@ -169,7 +164,6 @@ public class LoginController {
* 微信授权回调
*/
@RequestMapping("/wxmp/oauth2/{service}")
@TokenIgnore
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
@@ -185,7 +179,6 @@ public class LoginController {
* @return
*/
@GetMapping("/wxmp/jssdk/{service}")
@TokenIgnore
public ApiResp<WxJsapiSignature> wxmpJssdk(@PathVariable String service, String url) {
WxJsapiSignature jsapiSignature = platformWxmpConfig.createJsapiSignature(service, url);
return ApiResp.respOK(jsapiSignature);
@@ -201,7 +194,6 @@ public class LoginController {
* @return
*/
@RequestMapping("/wxmini/index/{service}")
@TokenIgnore
public ApiResp<WxminiLoginVo> wxminiIndex(@PathVariable String service, String code) {
String openid = platformWxminiConfig.jscode2session(service, code);
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-message</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-platform</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-poi</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-util</artifactId>
@@ -25,6 +25,11 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
@@ -37,6 +42,14 @@
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
<!-- 加解密 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.68</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,55 @@
package com.tiesheng.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.tiesheng.util.config.desensitize.DesensitizeValueFilter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CommonUtil {
/**
* FastJson配置
*
* @return
*/
public static FastJsonConfig fastJsonConfig() {
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteEnumUsingName);
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setSerializeFilters(new DesensitizeValueFilter());
return config;
}
/**
* 格式化数据
*
* @param value
* @return
* @throws IOException
*/
public static String writeJsonString(Object value) throws IOException {
FastJsonConfig fastJsonConfig = fastJsonConfig();
SerializeFilter[] globalFilters = fastJsonConfig.getSerializeFilters();
List<SerializeFilter> allFilters = new ArrayList(Arrays.asList(globalFilters));
ByteArrayOutputStream outnew = new ByteArrayOutputStream();
JSON.writeJSONStringWithFastJsonConfig(outnew, fastJsonConfig.getCharset(),
value, fastJsonConfig.getSerializeConfig(),
allFilters.toArray(new SerializeFilter[allFilters.size()]),
fastJsonConfig.getDateFormat(), JSON.DEFAULT_GENERATE_FEATURE,
fastJsonConfig.getSerializerFeatures());
return outnew.toString();
}
}

View File

@@ -1,44 +0,0 @@
package com.tiesheng.util;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.tiesheng.util.exception.ApiException;
public class PasswordUtils {
private static final int PREFIX_SIZE = 8;
/**
* 获取加密密码
*
* @param password
* @return
*/
public static String buildPassword(String password) {
String prefix = RandomUtil.randomString(PREFIX_SIZE);
return prefix + SecureUtil.sha1(password);
}
/**
* 验证密码
*
* @param userInput
* @param encrypted
* @return
*/
public static void verifyPassword(String userInput, String encrypted) {
String userEncrypted = buildPassword(userInput);
userEncrypted = StrUtil.subSuf(userEncrypted, PREFIX_SIZE);
encrypted = StrUtil.subSuf(encrypted, PREFIX_SIZE);
if (!StrUtil.equals(userEncrypted, encrypted)) {
throw new ApiException("账号或密码错误");
}
}
}

View File

@@ -20,5 +20,14 @@ public class ServletKit extends ServletUtil {
return attributes.getRequest();
}
/**
* 获取客户端IP
*
* @return
*/
public static String getClientIP() {
return getClientIP(getRequest());
}
}

View File

@@ -0,0 +1,136 @@
package com.tiesheng.util.config;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author hao
*/
@Configuration
@ConfigurationProperties(prefix = "tiesheng.encrypt")
public class EncryptConfig {
/**
* 加解密对象
*/
private final SM4 sm4;
/**
* 加密密钥
*/
private String key = "WmdUzPJXbngVNiaSsQrihg==";
private Integer saltSize = 8;
public EncryptConfig() {
sm4 = SmUtil.sm4(Base64.decode(getKey()));
}
/**
* 加密
*
* @param content
* @return
*/
public String encrypt(String content) {
if (StrUtil.isEmpty(content)) {
return "";
}
return sm4.encryptBase64(content);
}
/**
* 解密
*
* @param base64
* @return
*/
public String decrypt(String base64) {
try {
return sm4.decryptStr(base64);
} catch (Exception ignore) {
}
return base64;
}
/**
* 创建密码
*
* @param inputPasswd
* @param salt 盐,不存将自动生成
* @return
*/
public String passwdCreate(String inputPasswd, String salt) {
if (StrUtil.isEmpty(salt)) {
salt = RandomUtil.randomString(saltSize);
}
if (!passwdComplexity(inputPasswd)) {
throw new ApiException("需要包含数字、大小写字母、特殊符号且长度不低于8位");
}
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);
}
/**
* 密码校验
*
* @param inputPasswd
*/
public void passwdVerify(String inputPasswd, String encrypted) {
String salt = decrypt(encrypted).substring(0, saltSize);
String inputEncrypted = passwdCreate(inputPasswd, salt);
if (!StrUtil.equals(inputEncrypted, encrypted)) {
String clientIp = ServletKit.getClientIP();
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
if (num > 5) {
throw new ApiException("登录失败已达6次请10分钟后再试");
}
TimedCacheHelper.getTimedCache().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
throw new ApiException("账号或密码错误");
}
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Integer getSaltSize() {
return saltSize;
}
public void setSaltSize(Integer saltSize) {
this.saltSize = saltSize;
}
}

View File

@@ -0,0 +1,37 @@
package com.tiesheng.util.config.desensitize;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.tiesheng.annotation.desensitize.Desensitize;
import java.lang.reflect.Field;
/**
* 脱敏过滤类
*
* @author hao
*/
public class DesensitizeValueFilter implements ValueFilter {
@Override
public Object process(Object object, String name, Object value) {
if (ObjectUtil.isEmpty(value) || !(value instanceof String)) {
return value;
}
Field field = ClassUtil.getDeclaredField(object.getClass(), name);
if (ObjectUtil.isEmpty(field)) {
return value;
}
Desensitize desensitize = field.getAnnotation(Desensitize.class);
if (String.class != field.getType() || ObjectUtil.isEmpty(desensitize)) {
return value;
}
String originVal = String.valueOf(value);
return StrUtil.hide(originVal, desensitize.prefix(),
StrUtil.length(originVal) - desensitize.suffix());
}
}

View File

@@ -129,6 +129,15 @@ public class ApiResp<T> {
}
/**
* 是否成功
*
* @return
*/
public boolean successful() {
return code == CODE_OK;
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>0.6.1</version>
<version>0.8.2</version>
</parent>
<artifactId>springboot-web</artifactId>
@@ -72,11 +72,6 @@
<artifactId>springboot-poi</artifactId>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-login</artifactId>
@@ -87,6 +82,11 @@
<artifactId>springboot-message</artifactId>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-encrypt</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,8 +1,7 @@
package com.tiesheng.core.config.json;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.tiesheng.util.CommonUtil;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -25,14 +24,9 @@ public class FastJsonMessageConverter {
*/
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty,
SerializerFeature.WriteEnumUsingName);
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
fastConverter.setFastJsonConfig(config);
fastConverter.setFastJsonConfig(CommonUtil.fastJsonConfig());
fastConverter.setDefaultCharset(StandardCharsets.UTF_8);
List<MediaType> mediaTypes = new ArrayList<>();

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.annotation.operation.OperationLog;
import com.tiesheng.core.service.CoreLogService;
import com.tiesheng.util.ServletKit;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -13,6 +14,7 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -35,7 +37,7 @@ public class OperationAspect {
CoreLogService coreLogService;
@Pointcut("@annotation(com.tiesheng.annotation.operation.OperationLog)")
@Pointcut("execution(* com..controller..*.*(..))")
public void methodArgs() {
}
@@ -48,11 +50,24 @@ public class OperationAspect {
*/
@Around("methodArgs()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
// GET请求不处理
HttpServletRequest request = ServletKit.getRequest();
if (StrUtil.equalsIgnoreCase(request.getMethod(), "GET")) {
return joinPoint.proceed(joinPoint.getArgs());
}
String title = "", subject = "";
String insertKey = "";
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
OperationLog operationLog = method.getAnnotation(OperationLog.class);
String subject = operationLog.subject();
String insertKey = operationLog.insertKey();
if (operationLog != null) {
title = operationLog.title();
subject = operationLog.subject();
insertKey = operationLog.insertKey();
}
Object reqObj = null;
Map<String, Object> allParams = new HashMap<>(16);
@@ -65,7 +80,6 @@ public class OperationAspect {
allParams.putAll(BeanUtil.beanToMap(response));
if (!StrUtil.isEmpty(subject)) {
// 添加、编辑关键字处理
if (!StrUtil.isEmpty(insertKey)) {
String insertVal = MapUtil.getStr(allParams, insertKey);
@@ -74,9 +88,12 @@ public class OperationAspect {
// 占位符处理
subject = StrUtil.format(subject, allParams);
} else {
title = method.getName();
subject = ServletKit.getRequest().getRequestURI();
}
coreLogService.addOperationLog(operationLog.title(), subject, reqObj);
coreLogService.addOperationLog(title, subject, reqObj);
return response;
}

View File

@@ -1,6 +1,11 @@
package com.tiesheng.core.pojos;
public class CurrentWebUser {
/**
* 当前token的数据
*
* @author hao
*/
public class RequestUserInfo {
private String id;
private String name;

View File

@@ -1,12 +1,13 @@
package com.tiesheng.core.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;
import com.tiesheng.core.mapper.CoreLogLoginMapper;
import com.tiesheng.core.mapper.CoreLogMessageMapper;
import com.tiesheng.core.mapper.CoreLogOperationMapper;
import com.tiesheng.core.pojos.CurrentWebUser;
import com.tiesheng.core.pojos.RequestUserInfo;
import com.tiesheng.core.pojos.dao.CoreLogLogin;
import com.tiesheng.core.pojos.dao.CoreLogMessage;
import com.tiesheng.core.pojos.dao.CoreLogOperation;
@@ -54,10 +55,15 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
* 添加操作日志
*/
public void addOperationLog(String title, String subject, Object params) {
TokenBean tokenBean = TsTokenConfig.getWithoutThr();
if (tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) {
return;
}
RequestUserInfo requestUserInfo = tieshengWebConfigurer.getCurrentUserName(tokenBean);
CoreLogOperation operation = new CoreLogOperation();
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(TsTokenConfig.get());
operation.setUserId(currentWebUser.getId());
operation.setUserName(currentWebUser.getName());
operation.setUserId(requestUserInfo.getId());
operation.setUserName(requestUserInfo.getName());
operation.setTitle(title);
operation.setSubject(subject);
if (params != null) {
@@ -82,11 +88,11 @@ public class CoreLogService extends TsServiceBase<CoreLogOperationMapper, CoreLo
String ip = ServletUtil.getClientIP(request);
CoreLogLogin login = new CoreLogLogin();
login.setUserId(platformUnique.getUserId());
login.setUserId(tokenBean.getId());
login.setPlatform(platformUnique.getPlatform());
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName(tokenBean);
login.setUserName(currentWebUser.getName());
RequestUserInfo requestUserInfo = tieshengWebConfigurer.getCurrentUserName(tokenBean);
login.setUserName(requestUserInfo.getName());
login.setIp(ip);
login.setAddress(ip2regionConfig.search(login.getIp()));

View File

@@ -1,7 +1,6 @@
package com.tiesheng.core.service;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tiesheng.core.mapper.CorePlatformUniqueMapper;
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
import com.tiesheng.login.config.token.bean.TokenBean;
@@ -11,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author hao
@@ -35,15 +33,12 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
platformUnique.setUniqueId(loginInfo.getUnique());
}
platformUnique.setInfo(loginInfo.getInfo());
saveOrUpdate(platformUnique);
TokenBean tokenBean = tieshengWebConfigurer.loginConfigurer().doLogin(platformUnique, loginInfo.getTo());
if (tokenBean != null) {
platformUnique.setUserId(tokenBean.getId());
platformUnique.setIsDeleted(0);
saveOrUpdate(platformUnique);
// 添加登录日志
coreLogService.addLoginLog(platformUnique,tokenBean);
coreLogService.addLoginLog(platformUnique, tokenBean);
}
return tokenBean;
}
@@ -55,22 +50,18 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
/**
* 通过平台和用户id查询
* 更新用户id
*
* @param platform
* @param userIds
* @param uniqueId
* @param userId
* @return
*/
private List<CorePlatformUnique> getByPlatformAndUser(String platform, List<String> userIds) {
if (CollUtil.isEmpty(userIds)) {
return CollUtil.newArrayList();
}
QueryWrapper<CorePlatformUnique> queryWrapper = new QueryWrapper<>();
queryWrapper.in("user_id", userIds);
queryWrapper.eq("platform", platform);
queryWrapper.last("limit 1");
return list(queryWrapper);
public boolean updateUserId(String uniqueId, String userId) {
return update(new UpdateWrapper<CorePlatformUnique>().eq("unique_id", uniqueId)
.set("user_id", userId)
.set("is_deleted", 0)
);
}
}

View File

@@ -1,7 +1,7 @@
package com.tiesheng.core.service;
import cn.hutool.log.LogFactory;
import com.tiesheng.core.pojos.CurrentWebUser;
import com.tiesheng.core.pojos.RequestUserInfo;
import com.tiesheng.core.pojos.dao.CorePlatformUnique;
import com.tiesheng.login.config.token.bean.TokenBean;
import com.tiesheng.util.exception.ApiRespEnum;
@@ -22,7 +22,7 @@ public interface TieshengWebConfigurer {
*
* @return
*/
CurrentWebUser getCurrentUserName(TokenBean userId);
RequestUserInfo getCurrentUserName(TokenBean userId);
/**