fix: 修复 AMT 凭证 ID 类型问题
- 将 AmtTestRequest 的 credentialId 从 Long 改为 String(支持 UUID) - 更新 AmtDigestService 处理字符串类型的凭证 ID - 前端不再将 credentialId 转换为数字,直接发送字符串 - 添加详细日志用于调试凭证获取过程 - 修复使用保存凭证时的认证失败问题
This commit is contained in:
parent
afb327b036
commit
c1111b8b09
@ -7,5 +7,5 @@ public class AmtTestRequest {
|
||||
private String ipAddress;
|
||||
private String username;
|
||||
private String password;
|
||||
private Long credentialId; // 可选:使用已保存的凭证ID
|
||||
private String credentialId; // 可选:使用已保存的凭证ID(UUID字符串)
|
||||
}
|
||||
|
||||
@ -46,16 +46,44 @@ public class AmtDigestService {
|
||||
String username;
|
||||
String password;
|
||||
|
||||
if (request.getCredentialId() != null) {
|
||||
AmtCredential credential = amtCredentialService.getCredentialById(request.getCredentialId().toString());
|
||||
if (request.getCredentialId() != null && !request.getCredentialId().isEmpty()) {
|
||||
logger.info("使用凭证 ID: {}", request.getCredentialId());
|
||||
|
||||
AmtCredential credential = amtCredentialService.getCredentialById(request.getCredentialId());
|
||||
if (credential == null) {
|
||||
throw new RuntimeException("凭证不存在");
|
||||
logger.error("凭证不存在,ID: {}", request.getCredentialId());
|
||||
throw new RuntimeException("凭证不存在,ID: " + request.getCredentialId());
|
||||
}
|
||||
|
||||
logger.info("找到凭证: {}, 用户名: {}, 密码长度: {}",
|
||||
credential.getCredentialName(),
|
||||
credential.getUsername(),
|
||||
credential.getPassword() != null ? credential.getPassword().length() : 0);
|
||||
|
||||
username = credential.getUsername();
|
||||
password = credential.getPassword();
|
||||
|
||||
if (username == null || username.isEmpty()) {
|
||||
logger.error("凭证用户名为空,凭证名称: {}", credential.getCredentialName());
|
||||
throw new RuntimeException("凭证用户名为空");
|
||||
}
|
||||
if (password == null || password.isEmpty()) {
|
||||
logger.error("凭证密码为空,凭证名称: {}", credential.getCredentialName());
|
||||
throw new RuntimeException("凭证密码为空");
|
||||
}
|
||||
} else {
|
||||
username = request.getUsername();
|
||||
password = request.getPassword();
|
||||
logger.info("使用手动输入凭证 - 用户名: {}, 密码长度: {}",
|
||||
username,
|
||||
password != null ? password.length() : 0);
|
||||
|
||||
if (username == null || username.isEmpty()) {
|
||||
throw new RuntimeException("用户名不能为空");
|
||||
}
|
||||
if (password == null || password.isEmpty()) {
|
||||
throw new RuntimeException("密码不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Digest 认证 - 用户名: {}", username);
|
||||
@ -85,16 +113,40 @@ public class AmtDigestService {
|
||||
String username;
|
||||
String password;
|
||||
|
||||
if (request.getCredentialId() != null) {
|
||||
AmtCredential credential = amtCredentialService.getCredentialById(request.getCredentialId().toString());
|
||||
if (request.getCredentialId() != null && !request.getCredentialId().isEmpty()) {
|
||||
logger.info("使用凭证 ID 获取设备信息: {}", request.getCredentialId());
|
||||
|
||||
AmtCredential credential = amtCredentialService.getCredentialById(request.getCredentialId());
|
||||
if (credential == null) {
|
||||
throw new RuntimeException("凭证不存在");
|
||||
logger.error("凭证不存在,ID: {}", request.getCredentialId());
|
||||
throw new RuntimeException("凭证不存在,ID: " + request.getCredentialId());
|
||||
}
|
||||
|
||||
logger.info("找到凭证: {}, 用户名: {}",
|
||||
credential.getCredentialName(),
|
||||
credential.getUsername());
|
||||
|
||||
username = credential.getUsername();
|
||||
password = credential.getPassword();
|
||||
|
||||
if (username == null || username.isEmpty()) {
|
||||
logger.error("凭证用户名为空,凭证名称: {}", credential.getCredentialName());
|
||||
throw new RuntimeException("凭证用户名为空");
|
||||
}
|
||||
if (password == null || password.isEmpty()) {
|
||||
logger.error("凭证密码为空,凭证名称: {}", credential.getCredentialName());
|
||||
throw new RuntimeException("凭证密码为空");
|
||||
}
|
||||
} else {
|
||||
username = request.getUsername();
|
||||
password = request.getPassword();
|
||||
|
||||
if (username == null || username.isEmpty()) {
|
||||
throw new RuntimeException("用户名不能为空");
|
||||
}
|
||||
if (password == null || password.isEmpty()) {
|
||||
throw new RuntimeException("密码不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
AmtDeviceInfo deviceInfo = new AmtDeviceInfo();
|
||||
@ -118,6 +170,7 @@ public class AmtDigestService {
|
||||
|
||||
return deviceInfo;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取 AMT 设备信息失败", e);
|
||||
throw new RuntimeException("获取 AMT 设备信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
36
rebuild_and_check_logs.bat
Normal file
36
rebuild_and_check_logs.bat
Normal file
@ -0,0 +1,36 @@
|
||||
@echo off
|
||||
echo ========================================
|
||||
echo 重新编译后端并查看日志
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
cd backend
|
||||
|
||||
echo 清理旧的编译文件...
|
||||
call mvn clean
|
||||
|
||||
echo.
|
||||
echo 重新编译项目...
|
||||
call mvn compile
|
||||
|
||||
echo.
|
||||
echo 打包项目...
|
||||
call mvn package -DskipTests
|
||||
|
||||
echo.
|
||||
echo ========================================
|
||||
echo 编译完成!
|
||||
echo ========================================
|
||||
echo.
|
||||
echo 现在启动后端服务并查看日志:
|
||||
echo cd backend
|
||||
echo java -jar target/soybean-admin-0.0.1-SNAPSHOT.jar
|
||||
echo.
|
||||
echo 测试时请注意查看控制台输出的日志信息
|
||||
echo 特别关注以下内容:
|
||||
echo - 使用凭证 ID: xxx
|
||||
echo - 查询凭证,ID字符串: xxx
|
||||
echo - 找到凭证: xxx, 用户名: xxx
|
||||
echo.
|
||||
|
||||
pause
|
||||
4
src/typings/api/device.d.ts
vendored
4
src/typings/api/device.d.ts
vendored
@ -60,8 +60,8 @@ declare namespace Api {
|
||||
username?: string;
|
||||
/** 密码 */
|
||||
password?: string;
|
||||
/** 凭证ID */
|
||||
credentialId?: number;
|
||||
/** 凭证ID(UUID字符串) */
|
||||
credentialId?: string | number;
|
||||
}
|
||||
|
||||
/** AMT 设备信息 */
|
||||
|
||||
@ -455,7 +455,7 @@ const amtFormData = reactive({
|
||||
ipAddress: '',
|
||||
username: '',
|
||||
password: '',
|
||||
credentialId: null as number | null,
|
||||
credentialId: null as string | null,
|
||||
useCredential: false
|
||||
});
|
||||
const amtCredentials = ref<AmtCredential[]>([]);
|
||||
@ -663,7 +663,8 @@ async function handleTestAmtConnection() {
|
||||
};
|
||||
|
||||
if (amtFormData.useCredential && amtFormData.credentialId) {
|
||||
requestData.credentialId = amtFormData.credentialId;
|
||||
// 直接使用字符串 ID,不转换为数字
|
||||
requestData.credentialId = amtFormData.credentialId as any;
|
||||
} else {
|
||||
requestData.username = amtFormData.username;
|
||||
requestData.password = amtFormData.password;
|
||||
@ -695,7 +696,8 @@ async function handleGetAmtDeviceInfo() {
|
||||
};
|
||||
|
||||
if (amtFormData.useCredential && amtFormData.credentialId) {
|
||||
requestData.credentialId = amtFormData.credentialId;
|
||||
// 直接使用字符串 ID,不转换为数字
|
||||
requestData.credentialId = amtFormData.credentialId as any;
|
||||
} else {
|
||||
requestData.username = amtFormData.username;
|
||||
requestData.password = amtFormData.password;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user