From 678115e978e2eac37874363d89d6db1d9a12f4ec Mon Sep 17 00:00:00 2001 From: k94314517 <8417338+k94314517@user.noreply.gitee.com> Date: 星期一, 22 七月 2024 18:29:31 +0800 Subject: [PATCH] 代码提交 --- server/service/src/main/java/com/doumee/config/Jwt/WebMvcConfig.java | 31 ++++++++++++------------------- 1 files changed, 12 insertions(+), 19 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 f7d6ad6..c5872f9 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,30 +66,19 @@ Class<?> beanType = handlerMethod.getBeanType(); Boolean checkFlag = false; - if(!( - beanType.isAnnotationPresent(LoginRequired.class) || handlerMethod.hasMethodAnnotation(LoginRequired.class) - || beanType.isAnnotationPresent(UserLoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)) + if(!( handlerMethod.hasMethodAnnotation(LoginRequired.class) || handlerMethod.hasMethodAnnotation(UserLoginRequired.class)) ){ return true; } - // 鏈� @LoginRequired 娉ㄨВ锛岄渶瑕佺櫥褰曡璇� 瀹㈡埛绔娇鐢� - 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(),"鏈櫥褰�"); - } - if (StringUtils.isNotBlank(token)) { - checkFlag = checkLogin(request,response,token); - } + String token = request.getHeader(JwtTokenUtil.HEADER_KEY); + if(StringUtils.isBlank(token)){ + throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); } - 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(),"鏈櫥褰�"); - } - if (StringUtils.isNotBlank(token)) { + if (handlerMethod.hasMethodAnnotation(LoginRequired.class)) { + checkFlag = checkLogin(request,response,token); + } + if(!checkFlag && handlerMethod.hasMethodAnnotation(UserLoginRequired.class)){ checkFlag = checkPersonnelLogin(request,response,token); - } } if(!checkFlag){ throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); @@ -120,6 +109,8 @@ } request.setAttribute(JwtTokenUtil.UserId_Name, memberId); request.setAttribute(JwtTokenUtil.UserType, ZTConstants.CUSTOMER); + request.setAttribute(JwtTokenUtil.HEADER_KEY, ZTConstants.CUSTOMER+"_"+token); + request.setAttribute(JwtTokenUtil.UserInfo, tokenRedis); return true; } catch (IllegalArgumentException | JwtException e) { throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); @@ -145,6 +136,8 @@ } request.setAttribute(JwtTokenUtil.UserId_Name, userId); request.setAttribute(JwtTokenUtil.UserType, ZTConstants.BUSINESS); + request.setAttribute(JwtTokenUtil.HEADER_KEY, ZTConstants.CUSTOMER+"_"+token); + request.setAttribute(JwtTokenUtil.UserInfo, tokenRedis); return true; } catch (IllegalArgumentException | JwtException e) { throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); -- Gitblit v1.9.3