增强 SSH/SFTP 稳定性并完善安全校验与前端交互

This commit is contained in:
liumangmang
2026-03-11 23:14:39 +08:00
parent 8845847ce2
commit 085123697e
34 changed files with 1433 additions and 605 deletions

View File

@@ -16,11 +16,14 @@ public class ConnectionService {
private final ConnectionRepository connectionRepository;
private final EncryptionService encryptionService;
private final SshService sshService;
public ConnectionService(ConnectionRepository connectionRepository,
EncryptionService encryptionService) {
EncryptionService encryptionService,
SshService sshService) {
this.connectionRepository = connectionRepository;
this.encryptionService = encryptionService;
this.sshService = sshService;
}
public List<ConnectionDto> listByUserId(Long userId) {
@@ -130,4 +133,18 @@ public class ConnectionService {
return conn.getPassphrase() != null ?
encryptionService.decrypt(conn.getPassphrase()) : null;
}
public Connection testConnection(Connection conn, String password, String privateKey, String passphrase) {
SshService.SshSession session = null;
try {
session = sshService.createShellSession(conn, password, privateKey, passphrase);
return conn;
} catch (Exception e) {
throw new RuntimeException("Connection test failed: " + e.getMessage(), e);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}