Commit d43a3e4971792f043cfbe0d32a7d5d0f0e841be8

Authored by 谭毅彬
1 parent 51711336

修正定时任务获取操作人错误

Signed-off-by: TanYibin <5491541@qq.com>
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java
... ... @@ -43,6 +43,9 @@ public class HuahengJwtUtil {
43 43  
44 44 /** 全仓CODE */
45 45 public static final String ALL_WAREHOUSE_CODE = "ALL_WAREHOUSE";
  46 +
  47 + /** 定时任务操作人 */
  48 + public static final String TASK_AUDIENCE_NAME = "SYSTEM_TASK";
46 49  
47 50 public static final String SYSTEM_ACTIVATION_CODE_FILE_NAME = "ActivationCode.txt";
48 51  
... ... @@ -230,7 +233,12 @@ public class HuahengJwtUtil {
230 233 * @return
231 234 */
232 235 public static String getCurrentOperator() {
233   - LoginUser loginUser = SecurityUtils.getSubject().getPrincipal() != null ? (LoginUser)SecurityUtils.getSubject().getPrincipal() : null;
  236 + LoginUser loginUser = null;
  237 + try {
  238 + loginUser = SecurityUtils.getSubject().getPrincipal() != null ? (LoginUser)SecurityUtils.getSubject().getPrincipal() : null;
  239 + } catch (Exception e) {
  240 + loginUser = null;
  241 + }
234 242 if (loginUser != null) {
235 243 return loginUser.getRealname();
236 244 }
... ... @@ -253,3 +261,4 @@ public class HuahengJwtUtil {
253 261 }
254 262 }
255 263 }
  264 +
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/aspect/TaskBuildAudienceAspect.java 0 → 100644
  1 +package org.jeecg.utils.aspect;
  2 +
  3 +import java.lang.reflect.Method;
  4 +
  5 +import javax.servlet.http.HttpServletRequest;
  6 +
  7 +import org.aspectj.lang.JoinPoint;
  8 +import org.aspectj.lang.annotation.Aspect;
  9 +import org.aspectj.lang.annotation.Before;
  10 +import org.aspectj.lang.annotation.Pointcut;
  11 +import org.aspectj.lang.reflect.MethodSignature;
  12 +import org.jeecg.utils.HuahengJwtUtil;
  13 +import org.jeecg.utils.config.ApplicationConfig;
  14 +import org.jeecg.utils.support.ApiAuthentication;
  15 +import org.jeecg.utils.support.PassApiAuthentication;
  16 +import org.jeecg.utils.support.RSA256Key;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.scheduling.annotation.EnableAsync;
  19 +import org.springframework.stereotype.Component;
  20 +import org.springframework.web.context.request.RequestContextHolder;
  21 +import org.springframework.web.context.request.ServletRequestAttributes;
  22 +
  23 +import com.auth0.jwt.JWT;
  24 +import com.auth0.jwt.JWTVerifier;
  25 +import com.auth0.jwt.algorithms.Algorithm;
  26 +import com.auth0.jwt.exceptions.JWTVerificationException;
  27 +import com.auth0.jwt.interfaces.DecodedJWT;
  28 +
  29 +import lombok.extern.slf4j.Slf4j;
  30 +
  31 +/**
  32 + * 构建定时任务操作人拦截器
  33 + * @author TanYibin
  34 + * @createDate 2023年4月4日
  35 + */
  36 +@Slf4j
  37 +@Aspect
  38 +@Component
  39 +@EnableAsync
  40 +public class TaskBuildAudienceAspect {
  41 +
  42 + @Pointcut("execution(* org.jeecg.modules.wms.monitor.job.*Task.execute(..))")
  43 + public void executeTask() {}
  44 +
  45 + /**
  46 + * API Token 验证
  47 + * @author TanYibin
  48 + * @createDate 2023年2月14日
  49 + * @param joinPoint
  50 + * @throws NoSuchMethodException
  51 + * @throws Throwable
  52 + */
  53 + @Before("executeTask()")
  54 + public void doBefore(JoinPoint joinPoint) throws NoSuchMethodException, Throwable {
  55 + new ApiAuthentication.ApiAuthenticationBuild().audience(HuahengJwtUtil.TASK_AUDIENCE_NAME).bulid();
  56 + }
  57 +}
... ...