fix(客户端凭据): 模块包名 modules.client → modules.clientcredential,避让架构护栏
ArchitectureBoundaryTest.controllersDoNotDependOnExternalClient 用 `..client..` 圈定 「外部系统 Client 细节(ZiniaoClient/LLM Client 等)不得被 Controller 直接依赖」; 本模块是"桌面客户端凭据"的领域包,名字撞上该模式后规则把 Controller 依赖自身 VO 也 判成违规(7 处)。让位的是包名而不是护栏:护栏保持零豁免,领域名改为 clientcredential。
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
package com.nanri.aiimage.modules.clientcredential.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.config.ClientCredentialProperties;
|
||||
import com.nanri.aiimage.modules.clientcredential.model.vo.ClientCredentialVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 桌面客户端启动后的凭据领取口。
|
||||
*
|
||||
* <p>客户端 exe 与升级包都不再携带这些凭据(此前内置在 config.py 默认值里,反编译即得;
|
||||
* 随包 .env 也是公开可下载的),改为运行时按登录态 JWT 领取、只驻进程内存。</p>
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/client")
|
||||
@Tag(name = "客户端引导", description = "桌面客户端领取运行期凭据")
|
||||
public class ClientCredentialController {
|
||||
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
private final ClientCredentialProperties clientCredentialProperties;
|
||||
|
||||
@GetMapping("/credentials")
|
||||
@Operation(summary = "领取运行期凭据",
|
||||
description = "以登录态 JWT 换取内部令牌与紫鸟自动化账号;客户端不得落盘。"
|
||||
+ "服务端未配置紫鸟账号时返回 500 并点名配置项,不返回空值让客户端自行猜。")
|
||||
public ApiResponse<ClientCredentialVo> credentials(HttpServletRequest request) {
|
||||
AdminUserEntity user = adminAuthSupport.requireUser(request);
|
||||
String company = blankToEmpty(clientCredentialProperties.getZiniaoCompany());
|
||||
String username = blankToEmpty(clientCredentialProperties.getZiniaoUsername());
|
||||
String password = blankToEmpty(clientCredentialProperties.getZiniaoPassword());
|
||||
if (company.isEmpty() || username.isEmpty() || password.isEmpty()) {
|
||||
// 空值必须显式失败:客户端拿空口令去登录紫鸟,会被紫鸟回一句「账号密码错误」,
|
||||
// 把服务端配置缺项伪装成账号问题(这正是本次改造要消灭的形态)。
|
||||
throw new BusinessException(500, "服务端未配置紫鸟自动化账号:aiimage.client-credentials.ziniao-company/username/password");
|
||||
}
|
||||
ClientCredentialVo vo = new ClientCredentialVo();
|
||||
vo.setInternalToken(adminAuthSupport.currentInternalToken());
|
||||
vo.setZiniaoCompany(company);
|
||||
vo.setZiniaoUsername(username);
|
||||
vo.setZiniaoPassword(password);
|
||||
// MySQL 口令是次要路径,缺席不下发空串即可:客户端用到时才显式失败并点名配置项
|
||||
vo.setMysqlPassword(blankToEmpty(clientCredentialProperties.getMysqlPassword()));
|
||||
// 只记身份不记值:便于事后回答"哪个账号在哪台机器上领过紫鸟口令"
|
||||
log.info("[client-credentials] 下发凭据 userId={} username={} deviceId={}",
|
||||
user.getId(), user.getUsername(), adminAuthSupport.currentDeviceId(request));
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
private static String blankToEmpty(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.nanri.aiimage.modules.clientcredential.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "桌面客户端运行期凭据(登录后领取,仅驻客户端进程内存)")
|
||||
public class ClientCredentialVo {
|
||||
|
||||
@Schema(description = "内部接口令牌(结果回传/心跳/店铺凭据查询用);服务端未配置时为空串")
|
||||
private String internalToken;
|
||||
|
||||
@Schema(description = "紫鸟自动化账号所属公司")
|
||||
private String ziniaoCompany;
|
||||
|
||||
@Schema(description = "紫鸟自动化账号用户名")
|
||||
private String ziniaoUsername;
|
||||
|
||||
@Schema(description = "紫鸟自动化账号口令")
|
||||
private String ziniaoPassword;
|
||||
|
||||
@Schema(description = "MySQL 业务账号口令(客户端直连库用);服务端未配置时为空串")
|
||||
private String mysqlPassword;
|
||||
}
|
||||
Reference in New Issue
Block a user