views/rental/nodeDetail 租赁地址,添加可以删除待验证的地址功能

This commit is contained in:
lu7213 committed 2026-10-30 19:32:11 -04:00
1 parent dafa5261bd
commit 624110e43c
4 files changed
+76

No files matched your search

@@ -184,6 +184,14 @@ public class RentalController {
return AjaxResult.success(); return AjaxResult.success();
} }
/** 删除本人尚未完成所有权验证的待审核地址。 */
@DeleteMapping("/wallet/{id}")
@PreAuthorize("@ss.hasPermi('rent:wallet:bind')")
public AjaxResult removeWallet(@PathVariable long id) {
provisioning.deletePendingWallet(id, user());
return AjaxResult.success();
}
@PostMapping("/wallet/{id}/challenge") @PostMapping("/wallet/{id}/challenge")
@PreAuthorize("@ss.hasPermi('rent:wallet:bind')") @PreAuthorize("@ss.hasPermi('rent:wallet:bind')")
public AjaxResult challenge(@PathVariable long id) { public AjaxResult challenge(@PathVariable long id) {
@@ -120,6 +120,12 @@ public class RentalIdentity {
require("APP".equals(type) || "NODE".equals(type), "凭证主体非法"); require("APP".equals(type) || "NODE".equals(type), "凭证主体非法");
Map<String, Object> row = store.get(type.toLowerCase(Locale.ROOT), owner, true); Map<String, Object> row = store.get(type.toLowerCase(Locale.ROOT), owner, true);
require(number(row, "user_id") == actor, "无主体权限"); require(number(row, "user_id") == actor, "无主体权限");
if ("NODE".equals(type)) {
// 与 Agent 建连共用节点行锁:检查必须在旧凭证降级之前完成,
// 防止过期页面或其他签发入口轮换在线节点的凭证,造成 Agent 认证中断。
require(!Arrays.asList("ONLINE", "SYNCING").contains(text(row, "connection_status")),
"节点在线或正在恢复连接,禁止重新签发凭证,请先停止Agent并确认节点离线");
}
String secret = RentalCrypto.random(); String secret = RentalCrypto.random();
String encrypted = crypto.encrypt(secret); String encrypted = crypto.encrypt(secret);
String key = id("RK"); String key = id("RK");
@@ -157,6 +157,24 @@ public class RentalProvisioning {
return wallet; return wallet;
} }
/**
* 仅清理误添加的待验证地址,不删除已验证或已产生业务关联的钱包。
* 与所有权验证共用钱包行锁,保证验证与删除不能同时成功;审计独立保留。
*/
@Transactional(rollbackFor = Exception.class)
public void deletePendingWallet(long id, long actor) {
Map<String, Object> wallet = ownedWallet(id, actor, true);
require(wallet.get("ownership_verified_at") == null && "PENDING".equals(text(wallet, "status")),
"仅允许删除待验证的租赁地址");
require(store.one("SELECT id FROM rent_order WHERE wallet_id=? LIMIT 1 FOR UPDATE", id) == null,
"地址存在关联订单,不能删除");
require(store.one("SELECT id FROM rent_task WHERE wallet_id=? LIMIT 1 FOR UPDATE", id) == null,
"地址存在关联任务,不能删除");
require(store.execute("DELETE FROM rent_wallet WHERE id=? AND status='PENDING' AND ownership_verified_at IS NULL", id) == 1,
"地址状态已变化,请刷新后重试");
store.event("WALLET", id, "DELETE", actor, "删除待验证且无业务关联的租赁地址");
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map<String, Object> challenge(long id, long actor) { public Map<String, Object> challenge(long id, long actor) {
Map<String, Object> wallet = ownedWallet(id, actor, true); Map<String, Object> wallet = ownedWallet(id, actor, true);
@@ -43,6 +43,45 @@ public class RentalBusinessTest {
private static final String OWNER = "TR7NHqjeKQxGTCi8q8ZY4pL8otgjLj6t"; private static final String OWNER = "TR7NHqjeKQxGTCi8q8ZY4pL8otgjLj6t";
private final ObjectMapper json = new ObjectMapper(); private final ObjectMapper json = new ObjectMapper();
/** 待验证地址仅本人可删除,验证后或状态变化后必须保留。 */
@Test
public void pendingWalletDeletionChecksOwnershipAndVerification() {
long pending = store.insert("wallet", map("node_id", node, "network", "NILE",
"address", "pending-delete", "status", "PENDING"));
expectFailure(() -> tx.execute(status -> {
rentalDeletion().deletePendingWallet(pending, 10); return null;
}));
store.update("wallet", pending, map("ownership_verified_at", now()));
expectFailure(() -> tx.execute(status -> {
rentalDeletion().deletePendingWallet(pending, 20); return null;
}));
store.update("wallet", pending, map("ownership_verified_at", null, "status", "PAUSED"));
expectFailure(() -> tx.execute(status -> {
rentalDeletion().deletePendingWallet(pending, 20); return null;
}));
store.update("wallet", pending, map("status", "PENDING"));
tx.execute(status -> { rentalDeletion().deletePendingWallet(pending, 20); return null; });
assertNull(store.one("SELECT id FROM rent_wallet WHERE id=?", pending));
assertEquals(1, store.rows("SELECT id FROM rent_event WHERE object_type='WALLET' AND object_id=? AND action='DELETE'", pending).size());
}
/** 在线和恢复连接时拒绝轮换且保留原凭证,离线后允许正常轮换。 */
@Test
public void nodeCredentialRotationRequiresOffline() {
Map<String, Object> original = store.one(
"SELECT id FROM rent_credential WHERE owner_type='NODE' AND owner_id=? AND status='ACTIVE'", node);
for (String connection : Arrays.asList("ONLINE", "SYNCING")) {
store.update("node", node, map("connection_status", connection));
expectFailure(() -> tx.execute(status -> identity.issue("NODE", node, 20)));
assertEquals("ACTIVE", text(store.get("credential", number(original, "id"), false), "status"));
assertEquals(1, store.rows("SELECT id FROM rent_credential WHERE owner_type='NODE' AND owner_id=?", node).size());
}
store.update("node", node, map("connection_status", "OFFLINE"));
Map<String, Object> issued = tx.execute(status -> identity.issue("NODE", node, 20));
assertEquals("ACTIVE", text(store.get("credential", number(issued, "id"), false), "status"));
assertEquals("VERIFY_ONLY", text(store.get("credential", number(original, "id"), false), "status"));
}
/** 真实查询验证应用隔离、节点凭证隔离与 Secret 不外泄。 */ /** 真实查询验证应用隔离、节点凭证隔离与 Secret 不外泄。 */
@Test @Test
public void appDetailIsOwnedAndNeverReturnsSecrets() { public void appDetailIsOwnedAndNeverReturnsSecrets() {
@@ -56,6 +95,7 @@ public class RentalBusinessTest {
login, null, Collections.emptyList())); login, null, Collections.emptyList()));
try { try {
tx.execute(status -> identity.issue("APP", app, 10)); tx.execute(status -> identity.issue("APP", app, 10));
store.update("node", node, map("connection_status", "OFFLINE"));
tx.execute(status -> identity.issue("NODE", node, 20)); tx.execute(status -> identity.issue("NODE", node, 20));
RentalController controller = new RentalController( RentalController controller = new RentalController(
store, null, identity, orders, funds, reviews, tasks, null, null); store, null, identity, orders, funds, reviews, tasks, null, null);
@@ -132,6 +172,7 @@ public class RentalBusinessTest {
map("package_id", product, "merchant_order_no", "credential-delete", "receiver_address", ADDRESS))); map("package_id", product, "merchant_order_no", "credential-delete", "receiver_address", ADDRESS)));
tx.execute(status -> { orders.cancel(number(order, "id"), 10); return null; }); tx.execute(status -> { orders.cancel(number(order, "id"), 10); return null; });
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(historical, "id"), 10))); expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(historical, "id"), 10)));
store.update("node", node, map("connection_status", "OFFLINE"));
Map<String, Object> nodeKey = tx.execute(status -> identity.issue("NODE", node, 20)); Map<String, Object> nodeKey = tx.execute(status -> identity.issue("NODE", node, 20));
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(nodeKey, "id"), 20))); expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(nodeKey, "id"), 20)));
} }
@@ -454,7 +495,10 @@ public class RentalBusinessTest {
"ONLINE", "ONLINE",
"heartbeat_expires_at", "heartbeat_expires_at",
after(60))); after(60)));
// 先离线签发,再模拟 Agent 上线,遵循实际节点生命周期。
store.update("node", node, map("connection_status", "OFFLINE"));
identity.issue("NODE", node, 20); identity.issue("NODE", node, 20);
store.update("node", node, map("connection_status", "ONLINE"));
product = product =
store.insert( store.insert(
"package", "package",