diff --git a/ant-design-vue-jeecg/src/views/user/LoginAccount.vue b/ant-design-vue-jeecg/src/views/user/LoginAccount.vue index 8b73ced..fc7429c 100644 --- a/ant-design-vue-jeecg/src/views/user/LoginAccount.vue +++ b/ant-design-vue-jeecg/src/views/user/LoginAccount.vue @@ -18,7 +18,6 @@ show-search placeholder="请选择仓库!" option-filter-prop="label" - :filter-option="filterOption" v-model="model.warehouseCode"> <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{ item.name @@ -62,7 +61,7 @@ export default { required: true, message: '请输入密码!', validator: 'click' }], warehouseCode: [{ - required: true, message: '请选择仓库!', validator: 'click' + required: true, message: '请选择仓库!', trigger: "change" ,validator: 'click' }], } } @@ -98,7 +97,9 @@ export default { let obj = getWarehouseByUserCode(that.querySource); obj.then((res) => { that.warehouseList = res.result; - this.model.warehouseCode = this.warehouseList[0].code; + if (this.warehouseList != null) { + this.model.warehouseCode = this.warehouseList[0].code; + } }) }, diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java index 1eb399d..a02b72c 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/acs/controller/AcsController.java +++ b/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; import org.jeecg.modules.wms.api.acs.entity.AcsStatus; import org.jeecg.modules.wms.api.acs.service.IAcsService; import org.jeecg.modules.wms.config.address.service.IAddressService; +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication; +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication.ApiAuthenticationBuild; import org.jeecg.modules.wms.framework.aspectj.lang.annotation.ApiLogger; import org.jeecg.modules.wms.framework.controller.HuahengBaseController; import org.jeecg.modules.wms.task.agvTask.service.IAgvTaskService; @@ -18,6 +20,7 @@ import org.jeecg.utils.constant.QuantityConstant; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @@ -44,6 +47,7 @@ public class AcsController extends HuahengBaseController { @ResponseBody @PostMapping(value = "/testTokenCheck") public Result<?> testTokenCheck(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { + String audience = ApiAuthentication.getInstance().getAudience(); String url = "http://127.0.0.1:8080/wms/api/wms/acs/testTokenCheck"; String body = OkHttpUtils.sendPostByJsonStr(url, JSON.toJSONString(paramMap)); // String url = addressService.getUrlByParam(QuantityConstant.ADDRESS_AGV_TASK_ASSIGN); diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java index 3086f1e..8afe603 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/ApiAuthenticationAspect.java @@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.bouncycastle.crypto.RuntimeCryptoException; +import org.jeecg.modules.wms.framework.aspectj.dto.ApiAuthentication; import org.jeecg.modules.wms.framework.aspectj.dto.RSA256Key; import org.jeecg.utils.HuahengJwtUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -78,7 +79,9 @@ public class ApiAuthenticationAspect { try { Algorithm algorithm = Algorithm.RSA256(rsa256Key.getPublicKey(), rsa256Key.getPrivateKey()); JWTVerifier verifier = JWT.require(algorithm).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); - verifier.verify(token); + DecodedJWT jwt = verifier.verify(token); + new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer()) + .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid();; } catch (JWTVerificationException e) { log.error(e.getMessage()); throw e; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java index f97c017..1be5037 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/aspectj/dto/ApiAuthentication.java +++ b/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; import lombok.Data; /** - * 接口认证Token生成对象 + * 接口认证Token对象 * @author TanYibin * @createDate 2023年2月14日 */ @Data public class ApiAuthentication { + private static final ThreadLocal<ApiAuthentication> REQUEST_HEADER_CONTEXT_THREAD_LOCAL = new ThreadLocal<>(); + /** Token提供方 */ private String operator; @@ -25,7 +27,80 @@ public class ApiAuthentication { /** Token签发方(WMS) */ private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; + /** 签发时间 */ + private Date issuedAt; + /** 失效时间 */ private Date expireDateTime; + public ApiAuthentication() {} + + public static ApiAuthentication getInstance() { + return REQUEST_HEADER_CONTEXT_THREAD_LOCAL.get(); + } + + public void setContext(ApiAuthentication context) { + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.set(context); + } + + public static void clean() { + REQUEST_HEADER_CONTEXT_THREAD_LOCAL.remove(); + } + + private ApiAuthentication(ApiAuthenticationBuild apiAuthenticationBuild) { + this.operator = apiAuthenticationBuild.operator; + this.audience = apiAuthenticationBuild.audience; + this.issuer = apiAuthenticationBuild.issuer; + this.issuedAt = apiAuthenticationBuild.issuedAt; + this.expireDateTime = apiAuthenticationBuild.expireDateTime; + setContext(this); + } + + public static class ApiAuthenticationBuild { + + /** Token提供方 */ + private String operator; + + /** Token使用方 */ + private String audience; // 观众,相当于接受者 + + /** Token签发方(WMS) */ + private String issuer = HuahengJwtUtil.HUAHENG_SYSTEM_ID; + + /** 签发时间 */ + private Date issuedAt; + + /** 失效时间 */ + private Date expireDateTime; + + public ApiAuthenticationBuild operator(String operator) { + this.operator = operator; + return this; + } + + public ApiAuthenticationBuild audience(String audience) { + this.audience = audience; + return this; + } + + public ApiAuthenticationBuild issuer(String issuer) { + this.issuer = issuer; + return this; + } + + public ApiAuthenticationBuild issuedAt(Date issuedAt) { + this.issuedAt = issuedAt; + return this; + } + + public ApiAuthenticationBuild expireDateTime(Date expireDateTime) { + this.expireDateTime = expireDateTime; + return this; + } + + public ApiAuthentication bulid() { + return new ApiAuthentication(this); + } + } + }