diff --git a/.DS_Store b/.DS_Store index da7ffcb..fb8de5d 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/CHANGELOG.md b/CHANGELOG.md index ac226cb..00778c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,94 +1,7 @@ -## 1.1.0 +## 2.0.0.rc4 -- feat:globalConfig增加ext属性。 -- feat:增加网络请求超时、重定向的配置。 -- perf:更新数据库对比插件。 -- feat(web):增加DaoBase的常量。 -- perf(web):操作日志优化。 +- perf:TsTokenConfig不在提供静态方法 +- perf:移除TsTokenAspect,由TokenWebMvcConfigurer替代,并实现TokenBean参数注入 -## 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 - -- perf:hutool依赖升级:5.8.11 -> 5.8.16 -- perf:fastjson依赖升级:1.2.78 -> 1.2.83 -- perf:mybatis-plus依赖升级:3.5.1 -> 3.5.3 -- perf:**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。 - -从该版本开始,仓库地址改为: - -``` pom - - - kepai-repo - http://git.kepai365.com/tiesheng/repository/raw/master - - -``` - -## 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 - -### 增加 - -> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token; -> 2,PasswordUtils增加密码复杂度校验方法; -> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次; -> - -### 调整 - -> 1,TsTokenConfig中的**ignores**属性调整为**testMap**; diff --git a/CHANGELOG_V1.md b/CHANGELOG_V1.md new file mode 100644 index 0000000..ac226cb --- /dev/null +++ b/CHANGELOG_V1.md @@ -0,0 +1,94 @@ +## 1.1.0 + +- feat:globalConfig增加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 + +- perf:hutool依赖升级:5.8.11 -> 5.8.16 +- perf:fastjson依赖升级:1.2.78 -> 1.2.83 +- perf:mybatis-plus依赖升级:3.5.1 -> 3.5.3 +- perf:**TieshengWebConfigurer** 增加 **configSystemCheck** 方法,可根据情况校验系统配置参数。 + +从该版本开始,仓库地址改为: + +``` pom + + + kepai-repo + http://git.kepai365.com/tiesheng/repository/raw/master + + +``` + +## 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 + +### 增加 + +> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token; +> 2,PasswordUtils增加密码复杂度校验方法; +> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次; +> + +### 调整 + +> 1,TsTokenConfig中的**ignores**属性调整为**testMap**; diff --git a/pom.xml b/pom.xml index 9f34838..fe40445 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 pom springboot-parent 杭州铁晟科技有限公司基础依赖 @@ -58,61 +58,61 @@ com.tiesheng.springboot-parent springboot-database - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-login - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-web - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-util - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-platform - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-message - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-encrypt - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-role - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-annotation - 2.0.0.rc3 + 2.0.0.rc4 com.tiesheng.springboot-parent springboot-poi - 2.0.0.rc3 + 2.0.0.rc4 diff --git a/springboot-ademo/.DS_Store b/springboot-ademo/.DS_Store index 8214f9a..d7f77e0 100644 Binary files a/springboot-ademo/.DS_Store and b/springboot-ademo/.DS_Store differ diff --git a/springboot-ademo/pom.xml b/springboot-ademo/pom.xml index e04a413..6b7dd38 100644 --- a/springboot-ademo/pom.xml +++ b/springboot-ademo/pom.xml @@ -6,11 +6,11 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-ademo - 2.0.0.rc3 + 2.0.0.rc4 8 diff --git a/springboot-ademo/src/main/java/com/tiesheng/.DS_Store b/springboot-ademo/src/main/java/com/tiesheng/.DS_Store new file mode 100644 index 0000000..ba28863 Binary files /dev/null and b/springboot-ademo/src/main/java/com/tiesheng/.DS_Store differ diff --git a/springboot-ademo/src/main/java/com/tiesheng/demo/.DS_Store b/springboot-ademo/src/main/java/com/tiesheng/demo/.DS_Store new file mode 100644 index 0000000..24376e3 Binary files /dev/null and b/springboot-ademo/src/main/java/com/tiesheng/demo/.DS_Store differ diff --git a/springboot-annotation/.DS_Store b/springboot-annotation/.DS_Store new file mode 100644 index 0000000..48a4f58 Binary files /dev/null and b/springboot-annotation/.DS_Store differ diff --git a/springboot-annotation/pom.xml b/springboot-annotation/pom.xml index 8b7a777..a1c42c2 100644 --- a/springboot-annotation/pom.xml +++ b/springboot-annotation/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-annotation diff --git a/springboot-database/.DS_Store b/springboot-database/.DS_Store new file mode 100644 index 0000000..19a2764 Binary files /dev/null and b/springboot-database/.DS_Store differ diff --git a/springboot-database/pom.xml b/springboot-database/pom.xml index 8dd1656..4476aa7 100644 --- a/springboot-database/pom.xml +++ b/springboot-database/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-database diff --git a/springboot-encrypt/.DS_Store b/springboot-encrypt/.DS_Store new file mode 100644 index 0000000..531790e Binary files /dev/null and b/springboot-encrypt/.DS_Store differ diff --git a/springboot-encrypt/pom.xml b/springboot-encrypt/pom.xml index 8c90de2..5e728a2 100644 --- a/springboot-encrypt/pom.xml +++ b/springboot-encrypt/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-encrypt diff --git a/springboot-login/.DS_Store b/springboot-login/.DS_Store new file mode 100644 index 0000000..2c0d7dd Binary files /dev/null and b/springboot-login/.DS_Store differ diff --git a/springboot-login/pom.xml b/springboot-login/pom.xml index 0f8653f..f32ed4f 100644 --- a/springboot-login/pom.xml +++ b/springboot-login/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-login diff --git a/springboot-login/src/main/java/com/tiesheng/login/config/TokenWebMvcConfigurer.java b/springboot-login/src/main/java/com/tiesheng/login/config/TokenWebMvcConfigurer.java new file mode 100644 index 0000000..237ef6e --- /dev/null +++ b/springboot-login/src/main/java/com/tiesheng/login/config/TokenWebMvcConfigurer.java @@ -0,0 +1,92 @@ +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.util.config.TsTokenConfig; +import com.tiesheng.util.pojos.TokenBean; +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.util.List; + + +@Configuration +public class TokenWebMvcConfigurer implements WebMvcConfigurer { + + @Resource + TsTokenConfig tsTokenConfig; + + @Override + public void addArgumentResolvers(List 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); + return tsTokenConfig.validToken(header, true); + } + }); + } + + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new HandlerInterceptor() { + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { + + 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; + TokenIgnore annotation = handlerMethod.getBeanType().getAnnotation(TokenIgnore.class); + if (annotation != null) { + return true; + } + TokenIgnore apiTokenIgnore = handlerMethod.getMethodAnnotation(TokenIgnore.class); + if (apiTokenIgnore != null) { + return true; + } + + // token验证 + tsTokenConfig.validToken(request, true); + + return true; + } + }); + } +} + + + + diff --git a/springboot-login/src/main/java/com/tiesheng/login/config/TsTokenAspect.java b/springboot-login/src/main/java/com/tiesheng/login/config/TsTokenAspect.java deleted file mode 100644 index b892d11..0000000 --- a/springboot-login/src/main/java/com/tiesheng/login/config/TsTokenAspect.java +++ /dev/null @@ -1,88 +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.util.ServletKit; -import com.tiesheng.util.config.TsTokenConfig; -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); - - } - - -} diff --git a/springboot-message/.DS_Store b/springboot-message/.DS_Store new file mode 100644 index 0000000..77447b5 Binary files /dev/null and b/springboot-message/.DS_Store differ diff --git a/springboot-message/pom.xml b/springboot-message/pom.xml index 9559299..55839dd 100644 --- a/springboot-message/pom.xml +++ b/springboot-message/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-message diff --git a/springboot-platform/.DS_Store b/springboot-platform/.DS_Store new file mode 100644 index 0000000..bb85cfd Binary files /dev/null and b/springboot-platform/.DS_Store differ diff --git a/springboot-platform/pom.xml b/springboot-platform/pom.xml index 5d621f4..9fbdd84 100644 --- a/springboot-platform/pom.xml +++ b/springboot-platform/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-platform diff --git a/springboot-poi/.DS_Store b/springboot-poi/.DS_Store new file mode 100644 index 0000000..3758dd9 Binary files /dev/null and b/springboot-poi/.DS_Store differ diff --git a/springboot-poi/pom.xml b/springboot-poi/pom.xml index 88c477c..ca46c32 100644 --- a/springboot-poi/pom.xml +++ b/springboot-poi/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-poi diff --git a/springboot-role/.DS_Store b/springboot-role/.DS_Store new file mode 100644 index 0000000..c964671 Binary files /dev/null and b/springboot-role/.DS_Store differ diff --git a/springboot-role/pom.xml b/springboot-role/pom.xml index 38515d6..497ddd9 100644 --- a/springboot-role/pom.xml +++ b/springboot-role/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-role diff --git a/springboot-role/src/main/java/com/tiesheng/role/controller/RoleController.java b/springboot-role/src/main/java/com/tiesheng/role/controller/RoleController.java index 7d1e916..c52cd88 100644 --- a/springboot-role/src/main/java/com/tiesheng/role/controller/RoleController.java +++ b/springboot-role/src/main/java/com/tiesheng/role/controller/RoleController.java @@ -1,5 +1,6 @@ package com.tiesheng.role.controller; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -12,7 +13,6 @@ import com.tiesheng.role.pojos.vo.GroupTypeDTO; import com.tiesheng.role.pojos.vo.RoleUserPageVO; import com.tiesheng.role.pojos.vo.ServiceMenuVO; import com.tiesheng.role.service.CoreRoleService; -import com.tiesheng.util.config.TsTokenConfig; import com.tiesheng.util.exception.ApiException; import com.tiesheng.util.pojos.ApiResp; import com.tiesheng.util.pojos.IdDTO; @@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -249,15 +250,18 @@ public class RoleController { * @return */ @GetMapping("/owner/server") - public ApiResp> ownerServer() { - TokenBean tokenBean = TsTokenConfig.get(); + public ApiResp> ownerServer(TokenBean tokenBean) { List allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId()); + List list = allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList()); - List roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper() - .in("id", allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList())) - .eq(CoreRoleServer.IS_DELETED, 0) - .eq("is_open", 1) - ); + List roleServerList = new ArrayList<>(); + if (CollUtil.isNotEmpty(list)) { + roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper() + .in("id", list) + .eq(CoreRoleServer.IS_DELETED, 0) + .eq("is_open", 1) + ); + } return ApiResp.respOK(roleServerList); } @@ -269,11 +273,8 @@ public class RoleController { * @return */ @GetMapping("/owner/menu") - public ApiResp> ownerMenu(@Valid OwnerMenuDTO dto) { - - TokenBean tokenBean = TsTokenConfig.get(); + public ApiResp> ownerMenu(TokenBean tokenBean, @Valid OwnerMenuDTO dto) { List ownerMenus = coreRoleService.getOwnerMenus(tokenBean.getId(), tokenBean.getRoleId(), dto); - return ApiResp.respOK(ownerMenus); } @@ -283,9 +284,8 @@ public class RoleController { * @return */ @GetMapping("/owner/point") - public ApiResp> ownerPoint(@Valid OwnerPointDTO dto) { + public ApiResp> ownerPoint(TokenBean tokenBean, @Valid OwnerPointDTO dto) { - TokenBean tokenBean = TsTokenConfig.get(); List allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId()); String parentId; diff --git a/springboot-util/.DS_Store b/springboot-util/.DS_Store new file mode 100644 index 0000000..ebb34b9 Binary files /dev/null and b/springboot-util/.DS_Store differ diff --git a/springboot-util/pom.xml b/springboot-util/pom.xml index a8fbbba..bdbe004 100644 --- a/springboot-util/pom.xml +++ b/springboot-util/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-util diff --git a/springboot-util/src/main/java/com/tiesheng/util/config/TsTokenConfig.java b/springboot-util/src/main/java/com/tiesheng/util/config/TsTokenConfig.java index 648f5b1..8d10d4a 100644 --- a/springboot-util/src/main/java/com/tiesheng/util/config/TsTokenConfig.java +++ b/springboot-util/src/main/java/com/tiesheng/util/config/TsTokenConfig.java @@ -4,15 +4,15 @@ package com.tiesheng.util.config; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; -import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.json.JSONUtil; import cn.hutool.jwt.JWT; import cn.hutool.jwt.JWTValidator; -import com.tiesheng.util.ServletKit; import com.tiesheng.util.exception.ApiException; 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,6 +23,11 @@ import java.util.Map; @ConfigurationProperties("tiesheng.token") public class TsTokenConfig { + /** + * token常量 + */ + public static final String TOKEN_KEY = "token"; + private Map testMap = MapUtil.newHashMap(); private String encryptKey = "%kIp9frQCu"; private Integer expireHours = 48; @@ -30,28 +35,6 @@ public class TsTokenConfig { private boolean validLoginSign = false; - /** - * 获取当前登录的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); - } - - /** * 验证token * @@ -72,8 +55,8 @@ public class TsTokenConfig { * @param thrExp * @return */ - public TokenBean validToken(boolean thrExp) { - String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8"); + public TokenBean validToken(HttpServletRequest request, boolean thrExp) { + String token = ServletUtil.getHeader(request, TOKEN_KEY, "utf-8"); return validToken(token, thrExp); } @@ -92,14 +75,7 @@ public class TsTokenConfig { try { JWT decode = JWT.of(token); JWTValidator.of(decode).validateDate(); - String id = decode.getPayload("id").toString(); - String environmentType = decode.getPayload("environmentType").toString(); - String service = decode.getPayload("service").toString(); - String extra = StrUtil.toStringOrNull(decode.getPayload("extra")); - String roleId = StrUtil.toStringOrNull(decode.getPayload("roleId")); - tokenBean = new TokenBean(id, environmentType, service); - tokenBean.setRoleId(roleId); - tokenBean.setExtra(extra); + tokenBean = JSONUtil.toBean(decode.getPayloads(), TokenBean.class); } catch (Exception ignored) { } diff --git a/springboot-web/.DS_Store b/springboot-web/.DS_Store new file mode 100644 index 0000000..f463405 Binary files /dev/null and b/springboot-web/.DS_Store differ diff --git a/springboot-web/pom.xml b/springboot-web/pom.xml index 49a4d47..3d845f2 100644 --- a/springboot-web/pom.xml +++ b/springboot-web/pom.xml @@ -6,7 +6,7 @@ com.tiesheng.springboot-parent springboot-parent - 2.0.0.rc3 + 2.0.0.rc4 springboot-web diff --git a/springboot-web/src/main/java/com/tiesheng/web/config/operation/OperationAspect.java b/springboot-web/src/main/java/com/tiesheng/web/config/operation/OperationAspect.java index fdaec94..1277a37 100644 --- a/springboot-web/src/main/java/com/tiesheng/web/config/operation/OperationAspect.java +++ b/springboot-web/src/main/java/com/tiesheng/web/config/operation/OperationAspect.java @@ -38,6 +38,8 @@ public class OperationAspect { @Autowired CoreLogService coreLogService; + @Autowired + TsTokenConfig tsTokenConfig; @Pointcut("execution(* com..controller..*.*(..))") @@ -109,7 +111,8 @@ public class OperationAspect { } } - coreLogService.addOperationLog(TsTokenConfig.getWithoutThr(), title, subject, reqMaps); + coreLogService.addOperationLog( + tsTokenConfig.validToken(request, false), title, subject, reqMaps); return response; }