1.租赁应用详情创建凭证,第一次没有显示api Secret ,使用密码框,请修正 2. 提供凭证删除功能。

This commit is contained in:
lu7213 committed 2026-10-25 10:31:57 -04:00
1 parent 6321cde4c0
commit a83e1fef40
5 files changed
+94 -2

No files matched your search

@@ -131,6 +131,14 @@ public class RentalController {
return AjaxResult.success();
}
/** 删除未使用的本人应用凭证,不能绕过历史引用保护。 */
@DeleteMapping("/credential/{id}")
@PreAuthorize("@ss.hasPermi('rent:credential:issue')")
public AjaxResult removeCredential(@PathVariable long id) {
identity.deleteAppCredential(id, user());
return AjaxResult.success();
}
@PostMapping("/wallet/{id}/challenge")
@PreAuthorize("@ss.hasPermi('rent:wallet:bind')")
public AjaxResult challenge(@PathVariable long id) {
@@ -130,4 +130,32 @@ public class RentalIdentity {
actor,
"主动吊销凭证");
}
/**
* 仅物理删除未产生业务引用的 APP 凭证。节点凭证必须保留用于原任务验签。
* 先锁应用再锁凭证,与签发、下单及应用删除保持一致锁顺序。
* 订单未保存请求凭证版本,因此存在任意应用订单时保守拒绝,不猜测密钥是否使用过。
*/
@Transactional(rollbackFor = Exception.class)
public int deleteAppCredential(long id, long actor) {
Map<String, Object> snapshot = store.get("credential", id, false);
require("APP".equals(text(snapshot, "owner_type")), "节点凭证请使用吊销,不能删除");
long appId = number(snapshot, "owner_id");
Map<String, Object> app = store.get("app", appId, true);
require(number(app, "user_id") == actor, "无应用凭证删除权限");
Map<String, Object> credential = store.get("credential", id, true);
require("APP".equals(text(credential, "owner_type")) && number(credential, "owner_id") == appId,
"凭证归属发生变化,请刷新重试");
require(store.one("SELECT id FROM rent_order WHERE app_id=? LIMIT 1 FOR UPDATE", appId) == null,
"应用存在历史或在途订单,请保留凭证或使用吊销");
require(store.one("SELECT id FROM rent_task WHERE credential_id=? LIMIT 1 FOR UPDATE", id) == null,
"凭证存在关联任务,不能删除");
require(store.one("SELECT id FROM rent_webhook WHERE credential_id=? LIMIT 1 FOR UPDATE", id) == null,
"凭证存在关联回调,不能删除");
require(store.one("SELECT id FROM rent_nonce WHERE api_key=? AND expires_at>? LIMIT 1 FOR UPDATE",
text(credential, "api_key"), now()) == null, "凭证近期仍在使用,请停止调用并等待认证记录过期后重试");
require(store.execute("DELETE FROM rent_credential WHERE id=?", id) == 1, "凭证删除失败");
store.event("APP", appId, "DELETE_CREDENTIAL", actor, "删除无业务引用的凭证,凭证ID=" + id);
return 1;
}
}
@@ -30,6 +30,9 @@ public class RentCredentialServiceImpl extends ServiceImpl<RentCredentialMapper,
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private com.ruoyi.system.rental.RentalIdentity rentalIdentity;
@Override
public List<RentCredentialPlus> getByIds(List<Long> ids, SFunction<RentCredentialPlus, ?>... columns) {
LambdaQueryWrapper<RentCredentialPlus> lambdaQueryWrapper = new LambdaQueryWrapper<RentCredentialPlus>()
@@ -191,9 +194,21 @@ public class RentCredentialServiceImpl extends ServiceImpl<RentCredentialMapper,
* @return 结果
*/
@Override
@org.springframework.transaction.annotation.Transactional(rollbackFor = Exception.class)
public int deleteRentCredentialByIds(Long[] ids)
{
return rentCredentialMapper.deleteRentCredentialByIds(ids);
if (ids == null || ids.length == 0) {
return 0;
}
Long actor = com.ruoyi.common.utils.SecurityUtils.getUserId();
if (actor == null) {
throw new IllegalArgumentException("请先登录");
}
int count = 0;
for (Long id : new TreeSet<>(Arrays.asList(ids))) {
count += rentalIdentity.deleteAppCredential(id, actor);
}
return count;
}
/**
@@ -205,6 +220,6 @@ public class RentCredentialServiceImpl extends ServiceImpl<RentCredentialMapper,
@Override
public int deleteRentCredentialById(Long id)
{
return rentCredentialMapper.deleteRentCredentialById(id);
return deleteRentCredentialByIds(new Long[] {id});
}
}
@@ -102,6 +102,37 @@ public class RentalBusinessTest {
}
}
/** 签发响应可用,未使用凭证可删除;有历史或近期调用时拒绝且不影响节点凭证。 */
@Test
public void unusedAppCredentialCanBeDeletedButHistoryIsProtected() {
Map<String, Object> issued = tx.execute(status -> identity.issue("APP", app, 10));
assertFalse(text(issued, "api_secret").isEmpty());
assertEquals(text(issued, "api_secret"), identity.secret(store.get("credential", number(issued, "id"), false)));
long credentialId = number(issued, "id");
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(credentialId, 20)));
assertEquals(Integer.valueOf(1), tx.execute(status -> identity.deleteAppCredential(credentialId, 10)));
assertNull(store.one("SELECT id FROM rent_credential WHERE id=?", credentialId));
tx.execute(status -> { rentalDeletion().deleteApp(app, 10L); return null; });
assertNull(store.one("SELECT id FROM rent_app WHERE id=?", app));
long recentApp = store.insert("app", map("user_id", 10, "name", "recent", "status", "ACTIVE"));
Map<String, Object> recent = tx.execute(status -> identity.issue("APP", recentApp, 10));
long recentId = number(recent, "id");
store.insert("nonce", map("api_key", text(recent, "api_key"), "scope", "APP", "nonce", "test-nonce", "expires_at", after(180)));
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(recentId, 10)));
store.execute("UPDATE rent_nonce SET expires_at=? WHERE api_key=?", after(-1), text(recent, "api_key"));
assertEquals(Integer.valueOf(1), tx.execute(status -> identity.deleteAppCredential(recentId, 10)));
long historicalApp = store.insert("app", map("user_id", 10, "name", "history", "status", "ACTIVE"));
Map<String, Object> historical = tx.execute(status -> identity.issue("APP", historicalApp, 10));
Map<String, Object> order = tx.execute(status -> orders.create(historicalApp, 10,
map("package_id", product, "merchant_order_no", "credential-delete", "receiver_address", ADDRESS)));
tx.execute(status -> { orders.cancel(number(order, "id"), 10); return null; });
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(historical, "id"), 10)));
Map<String, Object> nodeKey = tx.execute(status -> identity.issue("NODE", node, 20));
expectFailure(() -> tx.execute(status -> identity.deleteAppCredential(number(nodeKey, "id"), 20)));
}
private RentalProvisioning rentalDeletion() { return new RentalProvisioning(store, orders); }
@Before