Commit 2ad5752dae5845114f0dd259ed1bbbf5fcce80c2

Authored by 谭毅彬
1 parent a3c9761a

范例 testTokenCheck 添加token获取范例

Signed-off-by: TanYibin <5491541@qq.com>
ant-design-vue-jeecg/src/views/user/LoginAccount.vue
@@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
18 show-search 18 show-search
19 placeholder="请选择仓库!" 19 placeholder="请选择仓库!"
20 option-filter-prop="label" 20 option-filter-prop="label"
21 - :filter-option="filterOption"  
22 v-model="model.warehouseCode"> 21 v-model="model.warehouseCode">
23 <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{ 22 <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{
24 item.name 23 item.name
@@ -62,7 +61,7 @@ export default { @@ -62,7 +61,7 @@ export default {
62 required: true, message: '请输入密码!', validator: 'click' 61 required: true, message: '请输入密码!', validator: 'click'
63 }], 62 }],
64 warehouseCode: [{ 63 warehouseCode: [{
65 - required: true, message: '请选择仓库!', validator: 'click' 64 + required: true, message: '请选择仓库!', trigger: "change" ,validator: 'click'
66 }], 65 }],
67 } 66 }
68 } 67 }
@@ -98,7 +97,9 @@ export default { @@ -98,7 +97,9 @@ export default {
98 let obj = getWarehouseByUserCode(that.querySource); 97 let obj = getWarehouseByUserCode(that.querySource);
99 obj.then((res) => { 98 obj.then((res) => {
100 that.warehouseList = res.result; 99 that.warehouseList = res.result;
101 - this.model.warehouseCode = this.warehouseList[0].code; 100 + if (this.warehouseList != null) {
  101 + this.model.warehouseCode = this.warehouseList[0].code;
  102 + }
102 }) 103 })
103 }, 104 },
104 105
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java
@@ -9,6 +9,8 @@ import org.jeecg.common.api.vo.Result; @@ -9,6 +9,8 @@ import org.jeecg.common.api.vo.Result;
9 import org.jeecg.modules.wms.api.acs.entity.AcsStatus; 9 import org.jeecg.modules.wms.api.acs.entity.AcsStatus;
10 import org.jeecg.modules.wms.api.acs.service.IAcsService; 10 import org.jeecg.modules.wms.api.acs.service.IAcsService;
11 import org.jeecg.modules.wms.config.address.service.IAddressService; 11 import org.jeecg.modules.wms.config.address.service.IAddressService;
  12 +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication;
  13 +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication.ApiAuthenticationBuild;
12 import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; 14 import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger;
13 import org.jeecg.modules.wms.framework.controller.HuahengBaseController; 15 import org.jeecg.modules.wms.framework.controller.HuahengBaseController;
14 import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; 16 import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService;
@@ -18,6 +20,7 @@ import org.jeecg.utils.constant.QuantityConstant; @@ -18,6 +20,7 @@ import org.jeecg.utils.constant.QuantityConstant;
18 import org.springframework.transaction.annotation.Transactional; 20 import org.springframework.transaction.annotation.Transactional;
19 import org.springframework.web.bind.annotation.PostMapping; 21 import org.springframework.web.bind.annotation.PostMapping;
20 import org.springframework.web.bind.annotation.RequestBody; 22 import org.springframework.web.bind.annotation.RequestBody;
  23 +import org.springframework.web.bind.annotation.RequestHeader;
21 import org.springframework.web.bind.annotation.RequestMapping; 24 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.ResponseBody; 25 import org.springframework.web.bind.annotation.ResponseBody;
23 import org.springframework.web.bind.annotation.RestController; 26 import org.springframework.web.bind.annotation.RestController;
@@ -44,6 +47,7 @@ public class AcsController extends HuahengBaseController { @@ -44,6 +47,7 @@ public class AcsController extends HuahengBaseController {
44 @ResponseBody 47 @ResponseBody
45 @PostMapping(value = "/testTokenCheck") 48 @PostMapping(value = "/testTokenCheck")
46 public Result<?> testTokenCheck(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { 49 public Result<?> testTokenCheck(@RequestBody Map<String, String> paramMap, HttpServletRequest request) {
  50 + String audience = ApiAuthentication.getInstance().getAudience();
47 String url = "http://127.0.0.1:8080/wms/api/wms/acs/testTokenCheck"; 51 String url = "http://127.0.0.1:8080/wms/api/wms/acs/testTokenCheck";
48 String body = OkHttpUtils.sendPostByJsonStr(url, JSON.toJSONString(paramMap)); 52 String body = OkHttpUtils.sendPostByJsonStr(url, JSON.toJSONString(paramMap));
49 // String url = addressService.getUrlByParam(QuantityConstant.ADDRESS_AGV_TASK_ASSIGN); 53 // String url = addressService.getUrlByParam(QuantityConstant.ADDRESS_AGV_TASK_ASSIGN);
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java
@@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Before; @@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Before;
11 import org.aspectj.lang.annotation.Pointcut; 11 import org.aspectj.lang.annotation.Pointcut;
12 import org.aspectj.lang.reflect.MethodSignature; 12 import org.aspectj.lang.reflect.MethodSignature;
13 import org.bouncycastle.crypto.RuntimeCryptoException; 13 import org.bouncycastle.crypto.RuntimeCryptoException;
  14 +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication;
14 import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; 15 import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key;
15 import org.jeecg.utils.HuahengJwtUtil; 16 import org.jeecg.utils.HuahengJwtUtil;
16 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
@@ -78,7 +79,9 @@ public class ApiAuthenticationAspect { @@ -78,7 +79,9 @@ public class ApiAuthenticationAspect {
78 try { 79 try {
79 Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); 80 Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey());
80 JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); 81 JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build();
81 - verifier.verify(token); 82 + DecodedJWT jwt = verifier.verify(token);
  83 + new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer())
  84 + .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid();;
82 } catch (JWTVerificationException e) { 85 } catch (JWTVerificationException e) {
83 log.error(e.getMessage()); 86 log.error(e.getMessage());
84 throw e; 87 throw e;
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java
@@ -9,13 +9,15 @@ import cn.hutool.core.date.DateUtil; @@ -9,13 +9,15 @@ import cn.hutool.core.date.DateUtil;
9 import lombok.Data; 9 import lombok.Data;
10 10
11 /** 11 /**
12 - * 接口认证Token生成对象 12 + * 接口认证Token对象
13 * @author TanYibin 13 * @author TanYibin
14 * @createDate 2023年2月14日 14 * @createDate 2023年2月14日
15 */ 15 */
16 @Data 16 @Data
17 public class ApiAuthentication { 17 public class ApiAuthentication {
18 18
  19 + private static final ThreadLocal<ApiAuthentication> REQUEST_HEADER_CONTEXT_THREAD_LOCAL = new ThreadLocal<>();
  20 +
19 /** Token提供方 */ 21 /** Token提供方 */
20 private String operator; 22 private String operator;
21 23
@@ -25,7 +27,80 @@ public class ApiAuthentication { @@ -25,7 +27,80 @@ public class ApiAuthentication {
25 /** Token签发方(WMS) */ 27 /** Token签发方(WMS) */
26 private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; 28 private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID;
27 29
  30 + /** 签发时间 */
  31 + private Date issuedAt;
  32 +
28 /** 失效时间 */ 33 /** 失效时间 */
29 private Date expireDateTime; 34 private Date expireDateTime;
30 35
  36 + public ApiAuthentication() {}
  37 +
  38 + public static ApiAuthentication getInstance() {
  39 + return REQUEST_HEADER_CONTEXT_THREAD_LOCAL.get();
  40 + }
  41 +
  42 + public void setContext(ApiAuthentication context) {
  43 + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.set(context);
  44 + }
  45 +
  46 + public static void clean() {
  47 + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.remove();
  48 + }
  49 +
  50 + private ApiAuthentication(ApiAuthenticationBuild apiAuthenticationBuild) {
  51 + this.operator = apiAuthenticationBuild.operator;
  52 + this.audience = apiAuthenticationBuild.audience;
  53 + this.issuer = apiAuthenticationBuild.issuer;
  54 + this.issuedAt = apiAuthenticationBuild.issuedAt;
  55 + this.expireDateTime = apiAuthenticationBuild.expireDateTime;
  56 + setContext(this);
  57 + }
  58 +
  59 + public static class ApiAuthenticationBuild {
  60 +
  61 + /** Token提供方 */
  62 + private String operator;
  63 +
  64 + /** Token使用方 */
  65 + private String audience; // 观众,相当于接受者
  66 +
  67 + /** Token签发方(WMS) */
  68 + private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID;
  69 +
  70 + /** 签发时间 */
  71 + private Date issuedAt;
  72 +
  73 + /** 失效时间 */
  74 + private Date expireDateTime;
  75 +
  76 + public ApiAuthenticationBuild operator(String operator) {
  77 + this.operator = operator;
  78 + return this;
  79 + }
  80 +
  81 + public ApiAuthenticationBuild audience(String audience) {
  82 + this.audience = audience;
  83 + return this;
  84 + }
  85 +
  86 + public ApiAuthenticationBuild issuer(String issuer) {
  87 + this.issuer = issuer;
  88 + return this;
  89 + }
  90 +
  91 + public ApiAuthenticationBuild issuedAt(Date issuedAt) {
  92 + this.issuedAt = issuedAt;
  93 + return this;
  94 + }
  95 +
  96 + public ApiAuthenticationBuild expireDateTime(Date expireDateTime) {
  97 + this.expireDateTime = expireDateTime;
  98 + return this;
  99 + }
  100 +
  101 + public ApiAuthentication bulid() {
  102 + return new ApiAuthentication(this);
  103 + }
  104 + }
  105 +
31 } 106 }