From 716ab46fb071ed48bc75d10fabed66bd8fcae6f1 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 22 七月 2024 15:45:11 +0800
Subject: [PATCH] 代码提交
---
server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java | 32 ++++++++++++++++----------------
server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java | 2 +-
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java b/server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
index 43272e3..f7d6ad6 100644
--- a/server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
+++ b/server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java
@@ -66,8 +66,14 @@
Class<?> beanType = handlerMethod.getBeanType();
Boolean checkFlag = false;
+ if(!(
+ beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class)
+ || beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))
+ ){
+ return true;
+ }
// 鏈� @LoginRequired 娉ㄨВ锛岄渶瑕佺櫥褰曡璇� 瀹㈡埛绔娇鐢�
- if ((beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) {
+ if (!checkFlag && (beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class))) {
String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
if(StringUtils.isBlank(token)){
throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
@@ -75,9 +81,8 @@
if (StringUtils.isNotBlank(token)) {
checkFlag = checkLogin(request,response,token);
}
- // 鏈� @UserLoginRequired 娉ㄨВ锛岄渶瑕佺櫥褰曡璇� 鍐呴儴浜哄憳浣跨敤
}
- if(beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)){
+ if(!checkFlag && (beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class))){
String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
if(StringUtils.isBlank(token)){
throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
@@ -85,6 +90,9 @@
if (StringUtils.isNotBlank(token)) {
checkFlag = checkPersonnelLogin(request,response,token);
}
+ }
+ if(!checkFlag){
+ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
}
return true;
}
@@ -96,12 +104,8 @@
public Boolean checkLogin(HttpServletRequest request, HttpServletResponse response,String token){
try {
String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.CUSTOMER+"_"+token);
- if(StringUtils.isNotBlank(tokenRedis)){
- if(!tokenRedis.equals(token)){
- throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"闀挎椂闂存湭鎿嶄綔,璇烽噸鏂扮櫥褰�");
- }
- }else{
- throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"闀挎椂闂存湭鎿嶄綔,璇烽噸鏂扮櫥褰�");
+ if(StringUtils.isBlank(tokenRedis)){
+ return false;
}
Long memberId = getTokenId(token);
Member member = dao.queryForObject(" select * from `member` where id = ? limit 1 ", new BeanPropertyRowMapper<>(Member.class),memberId);
@@ -125,12 +129,8 @@
public Boolean checkPersonnelLogin(HttpServletRequest request, HttpServletResponse response,String token){
try {
String tokenRedis = (String) redisTemplate.opsForValue().get(ZTConstants.BUSINESS+"_"+token);
- if(StringUtils.isNotBlank(tokenRedis)){
- if(!tokenRedis.equals(token)){
- throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"闀挎椂闂存湭鎿嶄綔,璇烽噸鏂扮櫥褰�");
- }
- }else{
- throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"闀挎椂闂存湭鎿嶄綔,璇烽噸鏂扮櫥褰�");
+ if(StringUtils.isBlank(tokenRedis)){
+ return false;
}
Long userId = getTokenId(token);
Users users = dao.queryForObject(" select * from `users` where id = ? limit 1 ", new BeanPropertyRowMapper<>(Users.class),userId);
@@ -159,7 +159,7 @@
public Long getTokenId(String token){
try {
Integer lastIndex = token.lastIndexOf("_")+1;
- Long tokenId = Long.valueOf(token.substring(0,lastIndex));
+ Long tokenId = Long.valueOf(token.substring(lastIndex));
return tokenId;
}catch (Exception e){
throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�");
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
index e5f5dc6..226d393 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
@@ -367,7 +367,7 @@
// JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE);
// String token = JwtTokenUtil.generateToken(payLoad);
// redisTemplate.opsForValue().set(ZTConstants.BUSINESS+"_"+users.getId(),token);
- String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,"",redisTemplate);
+ String token = JwtTokenUtil.generateTokenForZb(users.getId(),ZTConstants.BUSINESS,users.getId()+"",redisTemplate);
AccountResponse accountResponse = new AccountResponse();
accountResponse.setToken(token);
accountResponse.setUsers(users);
--
Gitblit v1.9.3