优化
This commit is contained in:
+13
-2
@@ -15,6 +15,8 @@ import java.security.MessageDigest;
|
||||
@RestController
|
||||
@RequestMapping("/internal/warehouses")
|
||||
public class InternalWarehouseController {
|
||||
private static final long PLATFORM_TENANT_ID = 0L;
|
||||
|
||||
@Resource
|
||||
private WarehouseApplicationService service;
|
||||
|
||||
@@ -30,8 +32,17 @@ public class InternalWarehouseController {
|
||||
public ApiResponse<WarehouseDetailResponse> active(
|
||||
@RequestHeader(value="X-Internal-Service-Token", required=false) String token,
|
||||
@PathVariable long tenantId, @PathVariable long id) {
|
||||
if (token == null || !MessageDigest.isEqual(expected, token.getBytes(StandardCharsets.UTF_8)))
|
||||
verifyToken(token);
|
||||
if (tenantId != PLATFORM_TENANT_ID) {
|
||||
throw new BizException(ResultCode.BAD_REQUEST, "平台公共仓库作用域必须为0");
|
||||
}
|
||||
return ApiResponse.success(service.activeDetail(PLATFORM_TENANT_ID, id));
|
||||
}
|
||||
|
||||
private void verifyToken(String token) {
|
||||
byte[] supplied = token == null ? new byte[0] : token.getBytes(StandardCharsets.UTF_8);
|
||||
if (!MessageDigest.isEqual(expected, supplied)) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "内部服务凭证无效");
|
||||
return ApiResponse.success(service.activeDetail(tenantId, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user