1.租赁应用详情创建凭证,第一次没有显示api Secret ,使用密码框,请修正 2. 提供凭证删除功能。
This commit is contained in:
1 parent
6321cde4c0
commit
a83e1fef40
5 files changed
+94
-2
No files matched your search
@@ -31,6 +31,16 @@
|
||||
|
||||
本轮验证:JDK8 Rental*Test 56项通过;ESLint、Vue模板编译、`node tests/rental-app-time.mjs` 时间回归通过。未执行数据库授权SQL及真实浏览器联调。
|
||||
|
||||
## Secret 展示与凭证删除
|
||||
|
||||
- 一次性 Secret 保持只读密码框,使用独立“显示/隐藏”按钮;修复 Element UI readonly 导致内置显隐按钮被隐藏的问题。每次签发重置为隐藏,关闭清空。
|
||||
- 凭证列表提供删除与二次确认,DELETE /rental/credential/{id} 复用 rent:credential:issue,无新增权限 SQL。
|
||||
- 仅允许本人 APP 凭证删除;有关联任务、回调或未过期 nonce 时拒绝。由于订单不记录请求凭证版本,有任何应用订单(包括已取消历史订单)也拒绝删除,应保留历史凭证、按需吊销。
|
||||
- 节点凭证禁止删除,继续使用吊销,避免丢失历史任务验签依据。旧生成器凭证删除入口同样复用业务校验。
|
||||
- 删除不清理审计,也不恢复原先已转 VERIFY_ONLY 的其他版本;删除后若无 ACTIVE 凭证,需主动重新签发。
|
||||
|
||||
本轮验证:后端 Rental*Test 57项通过,前端 ESLint 与模板编译通过;未进行实际登录浏览器验收。
|
||||
|
||||
验收:空列表引导、创建失败保留输入、创建后打开详情、取消轮换不签发、重复点击防重、一次性密钥确认、跨用户详情拒绝、窄屏布局。构建及隔离测试不替代真实登录浏览器联调。
|
||||
|
||||
## 本次验证
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+17
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user