Compare commits

..

1 Commits

Author SHA1 Message Date
曾文豪
ca96685022 publish 1.1.6
All checks were successful
/ local-deploy (push) Successful in 20s
2025-05-27 13:20:03 +08:00
302 changed files with 3466 additions and 8793 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -1,17 +0,0 @@
stages:
- deploy
deploy-jar:
stage: deploy
tags:
- zengos
rules:
- if: $CI_COMMIT_TAG
script:
- mvn clean deploy -Dmaven.test.skip -DaltDeploymentRepository=master::default::file:$TAG_REPO_FOLDER
- cd $TAG_REPO_FOLDER
- git checkout master
- git pull
- git add .
- git commit -m "deploy $CI_PROJECT_NAME $CI_COMMIT_TAG"
- git push origin master

View File

@@ -1,21 +1,94 @@
## 2.0.12
## 1.1.0
- 调整OkHttp日志
- featglobalConfig增加ext属性。
- feat增加网络请求超时、重定向的配置。
- perf更新数据库对比插件。
- feat(web)增加DaoBase的常量。
- perf(web):操作日志优化。
## 2.0.0.rc46
## 1.0.12
现在导入导出都接入底层流程,无需新增接口,只需要实现接口即可。
- perf(encrypt):开启关闭加解密移动到**yaml**中配置,移除**EnableEncryptConfig**注解。
- feat(login):登录接口增加验签步骤,可通过**validLoginSign**属性开启或关闭(默认)。
- perf(login):可重写**onSignError**方法自定义验签错误的跳转。
- fix(login)修复微信、钉钉授权跳转地址错误的bug
- 过程日志不再和操作日志同时存在
- 过程日志新增params参数
- 通过实现*TsImportHandler*接口编写导入逻辑
- 通过实现*TsExportHandler*接口编写导出逻辑
## 1.0.7
## 2.0.0.rc4
- feat(web): 增加uploadFileCustomize方法允许自定义文件存放情况
- feat(database): 增加db/data目录存放初始化数据的sql
- perf(login): 增加默认值防止token解析异常
- perfTsTokenConfig不在提供静态方法
- perf移除TsTokenAspect由TokenWebMvcConfigurer替代并实现TokenBean参数注入
## 1.0.6
- feat(web):新增 **OperationIgnore** 注解,可以指定接口忽略操作日志的收集。
- feat(web)**OperationLog** 增加 desensitize 属性,用来脱敏指定的字段。
## 1.0.2
- feat(database):增加数据库定时备份;
- feat(database)增加过期备份的删除操作默认过期时间为7天
- perf(message):调整阿里云短信类,方便扩展其他方法。
- perf(message)消息发送接口该body类型为 **JSONObject**
- perf(message):调整消息发送接口和方法(不兼容旧版本)
## 1.0.1
- perf(web)fastjson增加配置 **DisableCircularReferenceDetect**,禁用相同的对象写成引用的形式。
## 1.0.0
- perfhutool依赖升级5.8.11 -> 5.8.16
- perffastjson依赖升级1.2.78 -> 1.2.83
- perfmybatis-plus依赖升级3.5.1 -> 3.5.3
- perf**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。
从该版本开始,仓库地址改为:
``` pom
<repositories>
<repository>
<id>kepai-repo</id>
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
</repository>
</repositories>
```
## 0.9.3
> 1增加版本对比器防止某些情况下版本对比失效
>
## 0.8.3
### 调整
> 1优化返回数据加密
> 2上传文件接口调整统一为**application/json**格式;
## 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**

View File

@@ -1,94 +0,0 @@
## 1.1.0
- featglobalConfig增加ext属性。
- feat增加网络请求超时、重定向的配置。
- perf更新数据库对比插件。
- feat(web)增加DaoBase的常量。
- perf(web):操作日志优化。
## 1.0.12
- perf(encrypt):开启关闭加解密移动到**yaml**中配置,移除**EnableEncryptConfig**注解。
- feat(login):登录接口增加验签步骤,可通过**validLoginSign**属性开启或关闭(默认)。
- perf(login):可重写**onSignError**方法自定义验签错误的跳转。
- fix(login)修复微信、钉钉授权跳转地址错误的bug
## 1.0.7
- feat(web): 增加uploadFileCustomize方法允许自定义文件存放情况
- feat(database): 增加db/data目录存放初始化数据的sql
- perf(login): 增加默认值防止token解析异常
## 1.0.6
- feat(web):新增 **OperationIgnore** 注解,可以指定接口忽略操作日志的收集。
- feat(web)**OperationLog** 增加 desensitize 属性,用来脱敏指定的字段。
## 1.0.2
- feat(database):增加数据库定时备份;
- feat(database)增加过期备份的删除操作默认过期时间为7天
- perf(message):调整阿里云短信类,方便扩展其他方法。
- perf(message)消息发送接口该body类型为 **JSONObject**
- perf(message):调整消息发送接口和方法(不兼容旧版本)
## 1.0.1
- perf(web)fastjson增加配置 **DisableCircularReferenceDetect**,禁用相同的对象写成引用的形式。
## 1.0.0
- perfhutool依赖升级5.8.11 -> 5.8.16
- perffastjson依赖升级1.2.78 -> 1.2.83
- perfmybatis-plus依赖升级3.5.1 -> 3.5.3
- perf**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。
从该版本开始,仓库地址改为:
``` pom
<repositories>
<repository>
<id>kepai-repo</id>
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
</repository>
</repositories>
```
## 0.9.3
> 1增加版本对比器防止某些情况下版本对比失效
>
## 0.8.3
### 调整
> 1优化返回数据加密
> 2上传文件接口调整统一为**application/json**格式;
## 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**

35
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
<packaging>pom</packaging>
<name>springboot-parent</name>
<description>杭州铁晟科技有限公司基础依赖</description>
@@ -23,18 +23,17 @@
<module>springboot-login</module>
<module>springboot-web</module>
<module>springboot-util</module>
<module>springboot-poi</module>
<module>springboot-platform</module>
<module>springboot-message</module>
<module>springboot-encrypt</module>
<module>springboot-annotation</module>
<module>springboot-role</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hutool.version>5.8.31</hutool.version>
</properties>
<developers>
@@ -58,49 +57,55 @@
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-database</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-login</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-web</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-util</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-platform</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-message</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-role</artifactId>
<version>2.0.17</version>
<artifactId>springboot-encrypt</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-poi</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
@@ -120,8 +125,8 @@
<pluginRepositories>
<pluginRepository>
<id>kepai-repo-plugin</id>
<url>http://git.kepai365.com/tiesheng/repository/raw/master</url>
<id>gitea</id>
<url>https://git.tieshengkeji.com/api/packages/tieshengkeji/maven</url>
</pluginRepository>
</pluginRepositories>

View File

@@ -1,31 +0,0 @@
#-------------------------------------------------------------------------------#
# 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

Binary file not shown.

View File

@@ -6,11 +6,11 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
</parent>
<artifactId>springboot-ademo</artifactId>
<version>2.0.17</version>
<version>1.1.6</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
@@ -26,22 +26,11 @@
<artifactId>springboot-web</artifactId>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-role</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>
<repositories>

View File

@@ -1,7 +1,7 @@
package com.tiesheng.demo;
import com.tiesheng.web.EnableTieshengWeb;
import com.tiesheng.core.EnableTieshengWeb;
import com.tiesheng.demo.config.DemoWebConfigurer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -13,6 +13,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,12 +1,11 @@
package com.tiesheng.demo.config;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.login.pojos.RequestUserInfo;
import com.tiesheng.login.pojos.dao.CorePlatformUnique;
import com.tiesheng.login.service.TsLoginConfigurer;
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;
import com.tiesheng.util.config.GlobalConfig;
import com.tiesheng.util.pojos.TokenBean;
import com.tiesheng.web.service.TieshengWebConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -14,26 +13,24 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
@Component
public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigurer {
public class DemoWebConfigurer implements TieshengWebConfigurer {
@Autowired
GlobalConfig globalConfig;
@Override
public RequestUserInfo getCurrentUserName(TokenBean tokenBean) {
RequestUserInfo info = new RequestUserInfo();
info.setId(tokenBean.getId());
info.setName(tokenBean.getExtra());
info.setId("1");
info.setName("test");
return info;
}
@Override
public TokenBean login(CorePlatformUnique platformUnique) {
TokenBean tokenBean = null;
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
tokenBean = new TokenBean(platformUnique.getUserId(), "super");
} else if (Objects.equals(platformUnique.getUniqueId(), "1110290049")) {
tokenBean = new TokenBean("1", "super");
}
if (tokenBean != null) {
tokenBean.setExtra("1110290049");
tokenBean = new TokenBean(platformUnique.getUserId(), "", globalConfig.getService());
}
return tokenBean;
@@ -42,11 +39,13 @@ public class DemoWebConfigurer implements TieshengWebConfigurer, TsLoginConfigur
@Override
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
// 默认跳转到mobile
to = StrUtil.emptyToDefault(to, "mobile");
bean.setEnvironmentType(to);
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
}
}
@Override
public TsLoginConfigurer configureLogin() {
return this;
}
}

View File

@@ -0,0 +1,15 @@
package com.tiesheng.demo.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
public class DemoWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/mobile/**").addResourceLocations("classpath:/mobile/0.0.13/");
}
}

View File

@@ -0,0 +1,43 @@
//package com.tiesheng.demo.config;
//
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.List;
//
//public class JWTAuthenticationFilter extends OncePerRequestFilter {
//
// public JWTAuthenticationFilter(JwtTokenProvider tokenProvider) {
// this.tokenProvider = tokenProvider;
// }
//
// @Override
// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
// String authHeader = request.getHeader("Authorization");
// if (authHeader != null && authHeader.startsWith("Bearer ")) {
// String token = authHeader.substring(7);
// String username = tokenProvider.getUsername(token);
// if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
// if (tokenProvider.validateToken(token)) {
// List<GrantedAuthority> authorities = new ArrayList<>();
// // 根据你的应用程序需求设置权限
// authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
// UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, null, authorities);
// authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
// SecurityContextHolder.getContext().setAuthentication(authenticationToken);
// }
// }
// }
// filterChain.doFilter(request, response);
// }
//}

View File

@@ -1,6 +1,9 @@
package com.tiesheng.demo.config;
import com.tiesheng.core.service.CoreConfigService;
import com.tiesheng.core.service.CoreJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@@ -11,8 +14,19 @@ import javax.annotation.PostConstruct;
@Component
public class TestJobConfig {
@Autowired
CoreJobService coreJobService;
@Autowired
CoreConfigService coreConfigService;
@PostConstruct
public void init() {
coreConfigService.refreshFunc("230328001", "demo", "辅导员统计", "辅导员责任班级,学生展示");
// 辅导员职位
coreJobService.refresh("class_fdy", "辅导员", "辅导员", 1);
}
}

View File

@@ -0,0 +1,29 @@
//package com.tiesheng.demo.config;
//
//import cn.hutool.extra.spring.SpringUtil;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//import javax.servlet.http.HttpServletResponse;
//
//@Configuration
//@EnableWebSecurity
//public class TieshengSecurityAdapter extends WebSecurityConfigurerAdapter {
//
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// SpringUtil.getBeanFactory().getA
// http.csrf().disable() // JWT 通常与状态无关,因此 CSRF 保护不适用
// .authorizeRequests()
// .antMatchers("/login").permitAll() // 登录接口允许所有人访问
// .anyRequest().authenticated() // 其他所有请求需要认证
// .and()
// .exceptionHandling()
// .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
// .and()
// .addFilterBefore(new JWTAuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class);
// }
//}

View File

@@ -1,49 +1,43 @@
package com.tiesheng.demo.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tiesheng.annotation.role.RoleAuthority;
import com.tiesheng.annotation.operation.OperationLog;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.core.service.CoreLogService;
import com.tiesheng.core.service.CoreMessageService;
import com.tiesheng.core.util.ProcessImportConsumer;
import com.tiesheng.database.config.DbBackupConfig;
import com.tiesheng.demo.pojos.JsonTest;
import com.tiesheng.demo.pojos.PoiBean;
import com.tiesheng.platform.config.ding.PlatformDingConfig;
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
import com.tiesheng.demo.pojos.TestFile;
import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.message.pojos.UserChannel;
import com.tiesheng.util.config.EncryptConfig;
import com.tiesheng.util.config.GlobalConfig;
import com.tiesheng.util.config.Ip2regionConfig;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import com.tiesheng.util.pojos.FileUploadPath;
import com.tiesheng.util.service.TsCacheService;
import com.tiesheng.util.service.http.OkHttpUtil;
import com.tiesheng.web.service.CoreLogService;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.util.function.Consumer;
import java.util.ArrayList;
import java.util.List;
/**
* @author hao
*/
@RestController
@RequestMapping("/test")
@RoleAuthority(value = "test", group = "test")
public class TestController {
@Autowired
@@ -55,88 +49,59 @@ public class TestController {
@Autowired
EncryptConfig encryptConfig;
@Autowired
CoreMessageService coreMessageService;
@Autowired
CoreLogService coreLogService;
@Autowired
DbBackupConfig dbBackupConfig;
@Autowired
TsCacheService tsCacheService;
@Autowired
PlatformDingConfig platformDingConfig;
@RequestMapping("/index")
@TokenIgnore
public void index(HttpServletResponse response) {
globalConfig.redirectWithVer("mobile", "/test", response);
public ApiResp<String> index() {
return ApiResp.respOK("hello world");
}
@RequestMapping("/redirect")
@TokenIgnore
@RoleAuthority("redirect")
public ApiResp<JsonTest> redirect(HttpServletResponse response) {
public void redirect(HttpServletResponse response) {
String s1 = encryptConfig.passwdCreate("qU3?wE3{bX", "");
LogFactory.get().info(s1);
ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
@Override
public int accept(List<String> list) {
LogFactory.get().info("list: " + list.size());
return 0;
}
JsonTest jsonTest = new JsonTest();
jsonTest.setNow(DateUtil.date());
jsonTest.setNow1(DateUtil.date());
@Override
public String getFailFile() {
LogFactory.get().info("getFailFile: " + strings.size());
return null;
}
});
String jsonString = JSON.toJSONString(jsonTest);
LogFactory.get().info(jsonString);
String s = OkHttpUtil.get("http://toolbox.tieshengkeji.com/test/login/23232/3232");
LogFactory.get().info(s);
// ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
// coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
// @Override
// public int accept(List<String> list) {
// LogFactory.get().info("list: " + list.size());
// return 0;
// }
//
// @Override
// public String getFailFile() {
// LogFactory.get().info("getFailFile: " + strings.size());
// return null;
// }
// });
//
// LogFactory.get().info("strings: " + strings.size());
LogFactory.get().info("strings: " + strings.size());
// tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true);
// globalConfig.redirect("mobile", "/test", response);
return ApiResp.respOK(jsonTest);
globalConfig.redirect("mobile", "/test", response);
}
@GetMapping("/send")
@TokenIgnore
public ApiResp<String> sendMessage() {
public ApiResp<MessageReqResp> sendMessage() {
// MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
// JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));
return ApiResp.respOK(null);
return ApiResp.respOK(reqResp);
}
@RequestMapping("/export")
@TokenIgnore
public ApiResp<String> export() {
// tsCacheService.put("fdfhdfd", "fdfdfdfd");
// String s = tsCacheService.get("fdfhdfd");
// LogFactory.get().info("export: " + s);
platformDingConfig.syncDeptUser("", null, new Consumer<DingUserInfo>() {
@Override
public void accept(DingUserInfo dingUserInfo) {
}
});
// List<TestFile> list = new ArrayList<>();
// list.add(new TestFile("11111"));
// list.add(new TestFile("22222"));
@@ -157,7 +122,7 @@ public class TestController {
}
@PostMapping("searchIP")
@RequestMapping("searchIP")
@TokenIgnore
public ApiResp<String> searchIp() {
String search = ip2regionConfig.search("127.0.0.1");
@@ -165,6 +130,17 @@ public class TestController {
}
@RequestMapping("desensitize")
@TokenIgnore
public ApiResp<List<TestFile>> desensitize() {
TestFile file = new TestFile("11111");
file.setTest("111111");
TestFile file1 = new TestFile("22222");
file1.setTest("22222");
return ApiResp.respOK(CollUtil.newArrayList(file, file1));
}
@RequestMapping("passwd")
@TokenIgnore
public ApiResp<String> passwd() {
@@ -201,33 +177,18 @@ public class TestController {
return ApiResp.respOK("");
}
@GetMapping("getwxacode")
@RequestMapping("poiTool")
@TokenIgnore
public ApiResp<String> getwxacode() {
String id = "test_1111111";
FileUploadPath path = FileUploadPath.random("png");
JSONObject paramJson = new JSONObject();
paramJson.put("page", "pages/login/index");
paramJson.put("scene", "no=" + id);
paramJson.put("env_version", "develop");
paramJson.put("width", 430);
paramJson.put("is_hyaline", false);
paramJson.put("auto_color", false);
FileUploadPath file = FileUploadPath.file(id + ".png");
try {
Request request = OkHttpUtil.ofPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" +
"83_7xqG36kdgwuf8zzWLY3jtz7bg4ucziN-0oxbE0X9zBzwbjZ4S4Ss2RM9uHeSIcRp2K-wEp6MLzWhqo2AXj0Jpzd6IiJdUsRxqdHPvEWqAdOgt83vzZwdDf7tZBkGNGeAFASZS",
paramJson);
Response execute1 = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
if (execute1.body() != null) {
FileUtil.writeFromStream(execute1.body().byteStream(), file.getAbsolutePath());
execute1.close();
}
} catch (Exception e) {
throw new ApiException("每分钟最多生成5000个二维码请稍后再试");
}
return ApiResp.respOK(path.getHttpPath());
public ApiResp<String> poiTool() {
TimeInterval timeInterval = new TimeInterval();
FileUploadPath file = FileUploadPath.file("/upload/test.xlsx");
ExcelUtil.getReader(new File(file.getAbsolutePath())).read();
System.out.println("timeInterval: " + timeInterval.interval());
return ApiResp.respOK("");
}
}

View File

@@ -1,60 +0,0 @@
package com.tiesheng.demo.pojos;
import com.alibaba.fastjson.annotation.JSONField;
import java.util.Date;
public class JsonTest {
private Date now;
@JSONField(format = "yyyy-MM-dd")
private Date now1;
private String no;
private String name;
private JsonTest child;
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public Date getNow() {
return now;
}
public void setNow(Date now) {
this.now = now;
}
public Date getNow1() {
return now1;
}
public void setNow1(Date now1) {
this.now1 = now1;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public JsonTest getChild() {
return child;
}
public void setChild(JsonTest child) {
this.child = child;
}
}

View File

@@ -0,0 +1,21 @@
package com.tiesheng.demo.pojos;
import com.tiesheng.poi.pojos.PoiWriteBase;
public class TestFile extends TestParent implements PoiWriteBase {
private String name;
public TestFile(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,33 @@
package com.tiesheng.demo.pojos;
import com.tiesheng.annotation.desensitize.Desensitize;
import com.tiesheng.poi.pojos.PoiWriteBase;
public class TestParent implements PoiWriteBase {
private String id;
@Desensitize()
private String test;
///////////////////////////////////////////////////////////////////////////
// setter、getter
///////////////////////////////////////////////////////////////////////////
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}

View File

@@ -1,9 +1,10 @@
package com.tiesheng.demo.service;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.tiesheng.message.config.aliyun.AliyunSmsHandler;
import com.tiesheng.message.config.aliyun.AliyunTempParam;
import com.tiesheng.message.pojos.AliyunTempParam;
import org.springframework.stereotype.Service;
import java.util.Objects;
@@ -14,17 +15,16 @@ public class DemoSmsHandler implements AliyunSmsHandler {
@Override
public AliyunTempParam handler(JSONObject obj) {
String action = obj.getString("action");
String action = obj.getStr("action");
AliyunTempParam param = new AliyunTempParam();
param.setSignName("智慧校园");
if (Objects.equals(action, "sms-visitor-invite")) {
param.setTemplateCode("SMS_276125463");
JSONObject object = new JSONObject();
object.put("date", DateUtil.today());
param.setTemplateParam(object);
param.setTemplateParam(JSONUtil.createObj()
.putOpt("date", DateUtil.today())
);
}
return param;

View File

@@ -1,39 +0,0 @@
package com.tiesheng.demo.service;
import cn.hutool.core.collection.CollUtil;
import com.tiesheng.util.pojos.TokenBean;
import com.tiesheng.web.pojos.imex.ImportDealDTO;
import com.tiesheng.web.service.imex.TsImportHandler;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserImportHandler implements TsImportHandler<String> {
@Override
public List<String> ready(ImportDealDTO dto, TokenBean token) {
return CollUtil.newArrayList("11111");
}
@Override
public String getTemplateUrl() {
return "/template/xsxxzx_teacher_leader.xlsx";
}
@Override
public String getAction() {
return "user_import";
}
@Override
public int batchHandler(List<String> list) {
return 0;
}
@Override
public String getResultFile() {
return "";
}
}

View File

@@ -7,17 +7,8 @@ spring:
url: jdbc:mysql://47.96.30.85:3306/com_tiesheng_web?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&queryTimeout=5400&allowMultiQueries=true&serverTimezone=GMT%2B8
username: com_tiesheng_web
password: 4Xo$XheGFc
redis:
url: redis://kyF0zUL3011111@47.96.30.85:6234
database: 1
platform:
ding:
global:
corpId: dingebe664cb3baf3a52a39a90f97fcb1e09
agentId: 2474444028
appKey: dingyvf1niiajfaajyo5
appSecret: y6SGZ4fvPbdbj4RVbDWLeMBkGgplaOdnTA_9wN5TDdOV_Y47alYc1LDlIHjsBJE1
wxmp:
global:
app-id: wxa0343fe519824651
@@ -27,14 +18,12 @@ tiesheng:
token:
test-map:
"1111":
id: "1"
role-id: "1822829641023524865"
id: "1111"
global:
version: 2
host: http://localhost:8100
service: yrx
aliyun:
access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf
access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG
encrypt:
body: false
body: true

View File

@@ -13,9 +13,16 @@ spring:
web:
resources:
static-locations: classpath:/static/,file:static/
mvc:
pathmatch:
matching-strategy: ant_path_matcher
## 日志
logging:
file:
name: runtime/logs/tiesheng.log
tiesheng:
token:
ignore-paths:
- /test/index

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -1,42 +0,0 @@
package com.tiesheng.demo;
import cn.hutool.core.date.DateUtil;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import com.tiesheng.demo.pojos.JsonTest;
import com.tiesheng.login.pojos.RequestUserInfo;
public class MainTest {
public static void main(String[] args) {
MainTest test = new MainTest();
test.testJsonSelf();
}
private void testJsonSelf() {
RequestUserInfo info = new RequestUserInfo();
info.setId("1");
info.setName("name");
info.setData(info);
String jsonStr = JSON.toJSONString(info);
LogFactory.get().info(jsonStr);
}
private void testJsonPath() {
JsonTest jsonTest = new JsonTest();
jsonTest.setNo("1111");
jsonTest.setName("1111");
jsonTest.setNow(DateUtil.date());
jsonTest.setChild(jsonTest);
JSONPath jsonPath = JSONPath.compile("child.no");
String eval = jsonPath.eval(jsonTest, String.class);
LogFactory.get().info(eval);
}
}

Binary file not shown.

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>2.0.17</version>
<version>1.1.6</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,41 +0,0 @@
package com.tiesheng.annotation.role;
import java.lang.annotation.*;
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface RoleAuthority {
/**
* 编号
*
* @return
*/
String value();
/**
* 平台类型
*
* @return
*/
String platform() default "";
/**
* 分组
*
* @return
*/
String[] group() default {};
/**
* 依赖其他权限
*
* @return
*/
String[] deps() default {};
}

View File

@@ -1,9 +0,0 @@
package com.tiesheng.annotation.role;
import java.lang.annotation.*;
@Target({ElementType.METHOD})
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface RoleIgnore {
}

Binary file not shown.

View File

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

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-parent</artifactId>
<version>1.1.6</version>
</parent>
<artifactId>springboot-encrypt</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-util</artifactId>
</dependency>
<dependency>
<groupId>com.tiesheng.springboot-parent</groupId>
<artifactId>springboot-annotation</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,10 @@
package com.tiesheng.encrypt;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan({
"com.tiesheng.encrypt.**.*",
})
public class EncryptAutoConfigurer {
}

View File

@@ -1,9 +1,9 @@
package com.tiesheng.web.config.encrypt;
package com.tiesheng.encrypt.config;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import cn.hutool.json.JSONUtil;
import com.tiesheng.util.config.EncryptConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
@@ -66,7 +66,7 @@ public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
DecryptHttpInputMessage(HttpInputMessage inputMessage, EncryptConfig encryptConfig) throws Exception {
this.headers = inputMessage.getHeaders();
String bodyStr = IoUtil.read(inputMessage.getBody(), CharsetUtil.CHARSET_UTF_8);
String encryptData = JSON.parseObject(bodyStr).getString("encryptData");
String encryptData = JSONUtil.parseObj(bodyStr).getStr("encryptData");
if (!StrUtil.isEmpty(encryptData)) {
String decrypt = encryptConfig.decrypt(encryptData);
this.body = IoUtil.toStream(decrypt, Charset.defaultCharset());

View File

@@ -1,8 +1,8 @@
package com.tiesheng.web.config.encrypt;
package com.tiesheng.encrypt.config;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.JSON;
import com.tiesheng.util.CommonUtil;
import com.tiesheng.util.config.EncryptConfig;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,7 +42,7 @@ public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<ApiResp> {
}
body.setEncrypt(true);
body.setData(encryptConfig.encrypt(JSON.toJSONString(data)));
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>2.0.17</version>
<version>1.1.6</version>
</parent>
<artifactId>springboot-login</artifactId>

View File

@@ -0,0 +1,16 @@
package com.tiesheng.login;
import com.tiesheng.platform.PlatformAutoConfigurer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
/**
* @author hao
*/
@ComponentScan({
"com.tiesheng.login.**.*",
})
@Import(PlatformAutoConfigurer.class)
public class LoginAutoConfigurer {
}

View File

@@ -1,121 +0,0 @@
package com.tiesheng.login.config;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.login.pojos.RequestUserInfo;
import com.tiesheng.login.service.TsLoginConfigurer;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.TokenBean;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.List;
@Configuration
public class TokenWebMvcConfigurer implements WebMvcConfigurer {
@Resource
TsTokenConfig tsTokenConfig;
@Resource
TsLoginConfigurer tsLoginConfigurer;
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new HandlerMethodArgumentResolver() {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isAssignableFrom(TokenBean.class);
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
String header = webRequest.getHeader(TsTokenConfig.TOKEN_KEY);
boolean thrExp = true;
Method method = parameter.getMethod();
if (method != null) {
TokenIgnore annotation = method.getAnnotation(TokenIgnore.class);
thrExp = annotation == null;
}
return tsTokenConfig.validToken(header, thrExp);
}
});
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// 非接口类直接跳过
if (!(handler instanceof HandlerMethod)) {
return true;
}
String requestURI = request.getRequestURI();
String[] ignorePaths = tsTokenConfig.getIgnorePaths();
if (ObjUtil.isNotEmpty(ignorePaths)) {
for (String path : ignorePaths) {
if (path.contains("/**") &&
StrUtil.startWith(requestURI, path.replace("/**", ""))) {
// 通配路径
return true;
} else if (requestURI.equals(path)) {
// 完整路径
return true;
}
}
}
// 过滤不要需要验证的接口(注解)
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.getBeanType() == BasicErrorController.class) {
return true;
}
TokenIgnore annotation = handlerMethod.getBeanType().getAnnotation(TokenIgnore.class);
if (annotation != null) {
return true;
}
TokenIgnore apiTokenIgnore = handlerMethod.getMethodAnnotation(TokenIgnore.class);
if (apiTokenIgnore != null) {
return true;
}
// 验证TOKEN是否存在
TokenBean tokenBean = tsTokenConfig.validToken(request, true);
// 验证用户是否存在
RequestUserInfo cachedUserInfo = tsLoginConfigurer.getCachedUserInfo(tokenBean, false);
if (cachedUserInfo == null) {
throw new ApiException("非法TOKEN请重新登录");
}
return true;
}
});
}
}

View File

@@ -0,0 +1,87 @@
package com.tiesheng.login.config.token;
import cn.hutool.core.util.ObjUtil;
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;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* @author hao
* @ProjectName CmccSpring
* @Copyright Hangzhou ShuoChuang Technology Co.,Ltd All Right Reserved
* @Description 这里是对文件的描述
* @data 2019-07-15
* @note 这里写文件的详细功能和改动
* @note
*/
@Aspect
@Component
public class TsTokenAspect {
@Autowired
TsTokenConfig tsTokenConfig;
/**
* 切入点
*/
@Pointcut("execution(* com..controller..*.*(..))")
public void methodArgs() {
}
/**
* 获取操作日志说明
*
* @param joinPoint
*/
@Before("methodArgs()")
public void before(JoinPoint joinPoint) {
// 过滤不要需要验证的接口path
String requestURI = ServletKit.getRequest().getRequestURI();
String[] ignorePaths = tsTokenConfig.getIgnorePaths();
if (ObjUtil.isNotEmpty(ignorePaths)) {
for (String path : ignorePaths) {
if (path.contains("/**") &&
StrUtil.startWith(requestURI, path.replace("/**", ""))) {
// 通配路径
return;
} else if (requestURI.equals(path)) {
// 完整路径
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);
if (apiTokenIgnore != null) {
return;
}
// token验证
tsTokenConfig.validToken(true);
}
}

View File

@@ -1,18 +1,18 @@
package com.tiesheng.util.config;
package com.tiesheng.login.config.token;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSON;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTValidator;
import com.tiesheng.login.config.token.bean.TokenBean;
import com.tiesheng.util.ServletKit;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.jwt.JWT;
import com.tiesheng.util.jwt.JWTValidator;
import com.tiesheng.util.pojos.TokenBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@@ -23,22 +23,33 @@ import java.util.Map;
@ConfigurationProperties("tiesheng.token")
public class TsTokenConfig {
/**
* 用户登录的KEY
*/
public static String CACHE_REQUEST_LOGIN_KEY = "CACHE:LOGIN:{}";
/**
* token常量
*/
public static final String TOKEN_KEY = "token";
private Map<String, TokenBean> testMap = MapUtil.newHashMap();
private String encryptKey = "%kIp9frQCu";
private Integer expireHours = 48;
private String[] ignorePaths;
private boolean validLoginSign = false;
private boolean validLoginSign = true;
/**
* 获取当前登录的token
*
* @return
*/
public static TokenBean get() {
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
return tokenConfig.validToken(true);
}
/**
* 获取当前登录的token
*
* @return
*/
public static TokenBean getWithoutThr() {
TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class);
return tokenConfig.validToken(false);
}
/**
@@ -61,21 +72,11 @@ public class TsTokenConfig {
* @param thrExp
* @return
*/
public TokenBean validToken(HttpServletRequest request, boolean thrExp) {
String token = ServletUtil.getHeader(request, TOKEN_KEY, "utf-8");
public TokenBean validToken(boolean thrExp) {
String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8");
return validToken(token, thrExp);
}
/**
* token是否有效
*
* @param token
* @return
*/
public static boolean validToken(TokenBean token) {
return token != null && StrUtil.isNotEmpty(token.getId());
}
/**
* 验证token
@@ -91,11 +92,16 @@ public class TsTokenConfig {
try {
JWT decode = JWT.of(token);
JWTValidator.of(decode).validateDate();
tokenBean = JSON.toJavaObject(decode.getPayloads(), TokenBean.class);
String id = decode.getPayload("id").toString();
String environmentType = decode.getPayload("environmentType").toString();
String service = decode.getPayload("service").toString();
String extra = decode.getPayload("extra").toString();
tokenBean = new TokenBean(id, environmentType, service);
tokenBean.setExtra(extra);
} catch (Exception ignored) {
}
if ((tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) && thrExp) {
if (tokenBean == null && thrExp) {
throw new ApiException(StrUtil.isEmpty(token) ? 110 : 112,
StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆");
}

View File

@@ -1,10 +1,10 @@
package com.tiesheng.util.pojos;
package com.tiesheng.login.config.token.bean;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.jwt.JWT;
import cn.hutool.jwt.JWT;
import com.tiesheng.login.config.token.TsTokenConfig;
/**
* @author hao
@@ -12,15 +12,17 @@ import com.tiesheng.util.jwt.JWT;
public class TokenBean {
private String id;
private String roleId;
private String environmentType;
private String service;
private String extra;
public TokenBean() {
}
public TokenBean(String id, String roleId) {
public TokenBean(String id, String environmentType, String service) {
this.id = id;
this.roleId = roleId;
this.environmentType = environmentType;
this.service = service;
this.extra = "";
}
@@ -33,7 +35,8 @@ public class TokenBean {
return JWT.create()
.setExpiresAt(DateUtil.offsetHour(DateUtil.date(), tsTokenConfig.getExpireHours()))
.setPayload("id", getId())
.setPayload("roleId", StrUtil.emptyToDefault(getRoleId(), ""))
.setPayload("environmentType", StrUtil.emptyToDefault(getEnvironmentType(), ""))
.setPayload("service", StrUtil.emptyToDefault(getService(), ""))
.setPayload("extra", StrUtil.emptyToDefault(getExtra(), ""))
.setKey(tsTokenConfig.getEncryptKey().getBytes())
.sign();
@@ -51,6 +54,22 @@ public class TokenBean {
this.id = id;
}
public String getEnvironmentType() {
return environmentType;
}
public void setEnvironmentType(String environmentType) {
this.environmentType = environmentType;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public String getExtra() {
return extra;
}
@@ -58,12 +77,4 @@ public class TokenBean {
public void setExtra(String extra) {
this.extra = extra;
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
}

View File

@@ -6,11 +6,13 @@ import cn.hutool.core.util.URLUtil;
import com.alibaba.fastjson.JSON;
import com.tiesheng.annotation.operation.OperationIgnore;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.login.config.token.bean.TokenBean;
import com.tiesheng.login.pojos.CodeExtraDTO;
import com.tiesheng.login.pojos.DoLoginInfo;
import com.tiesheng.login.pojos.UniqueIndexDTO;
import com.tiesheng.login.pojos.WxminiLoginVo;
import com.tiesheng.login.service.CorePlatformUniqueService;
import com.tiesheng.login.service.TieshengLoginConfigurer;
import com.tiesheng.platform.config.ding.PlatformDingConfig;
import com.tiesheng.platform.config.ding.bean.DingJsapiSignature;
import com.tiesheng.platform.config.ding.bean.DingUserInfo;
@@ -21,10 +23,8 @@ import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
import com.tiesheng.util.config.GlobalConfig;
import com.tiesheng.util.config.TsTokenConfig;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import com.tiesheng.util.pojos.TokenBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -49,7 +49,7 @@ public class LoginController {
@Autowired
PlatformWxminiConfig platformWxminiConfig;
@Autowired
CorePlatformUniqueService corePlatformUniqueService;
TieshengLoginConfigurer tieshengLoginConfigurer;
@Autowired
GlobalConfig globalConfig;
@Autowired
@@ -65,13 +65,13 @@ public class LoginController {
@OperationIgnore
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
if (tsTokenConfig.isValidLoginSign() && !dto.validSign()) {
corePlatformUniqueService.redirect(null, dto.getTo(), dto.getExtra(), response);
tieshengLoginConfigurer.onSignError(response);
return;
}
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo("web_unique_redirect",
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_redirect",
dto.getNo(), dto.getPlatform(), dto.getInfo()));
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
}
@@ -84,9 +84,9 @@ public class LoginController {
@PostMapping("/unique/index")
@OperationIgnore
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo("web_unique_index",
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_index",
dto.getNo(), dto.getPlatform(), dto.getInfo()));
if (!TsTokenConfig.validToken(tokenBean)) {
if (tokenBean == null || StrUtil.isEmpty(tokenBean.getId())) {
throw new ApiException("登录失败");
}
return ApiResp.respOK(tokenBean.toToken());
@@ -134,9 +134,9 @@ public class LoginController {
public void dingOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
DingUserSimple userSimple = platformDingConfig.getUserIdByCode(service, dto.getCode());
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, userSimple.getUserid());
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(dingUserInfo.getAppId(),
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
dingUserInfo.getUserid(), "ding", JSON.toJSONString(dingUserInfo)));
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
}
@@ -170,7 +170,7 @@ public class LoginController {
extra = "";
}
String configUrl = globalConfig.buildPath("/login/wxmp/oauth2/" + service + "?extra=" + extra);
String authorizationUrl = platformWxmpConfig.buildAuthorizationUrl(service, configUrl, "snsapi_base");
String authorizationUrl = platformWxmpConfig.buildAuthorizationUrl(service, configUrl, "snsapi_userinfo");
response.sendRedirect(authorizationUrl);
}
@@ -182,9 +182,9 @@ public class LoginController {
@OperationIgnore
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(wxUserInfo.getAppId(),
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
wxUserInfo.getOpenid(), "wxmp", JSON.toJSONString(wxUserInfo)));
corePlatformUniqueService.redirect(tokenBean, dto.getTo(), dto.getExtra(), response);
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
}
@@ -214,12 +214,12 @@ public class LoginController {
public ApiResp<WxminiLoginVo> wxminiIndex(@PathVariable String service, String code) {
String openid = platformWxminiConfig.jscode2session(service, code);
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);
TokenBean tokenBean = corePlatformUniqueService.login(new DoLoginInfo(configBean.getAppId(),
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(configBean.getAppId(),
openid, "wxmini", "{}"));
WxminiLoginVo loginVo = new WxminiLoginVo();
loginVo.setOpenid(openid);
if (TsTokenConfig.validToken(tokenBean)) {
if (tokenBean != null) {
loginVo.setToken(tokenBean.toToken());
}
return ApiResp.respOK(loginVo);

Some files were not shown because too many files have changed in this diff Show More