Please provide the code changes or file diffs you would like me to summarize.

This commit is contained in:
liumangmang
2026-05-07 14:12:54 +08:00
parent 3f0ebe24e0
commit 2d9011b606
17 changed files with 375 additions and 379 deletions
@@ -1,5 +1,5 @@
package com.sshmanager.service;
package com.sshmanager.service;
import com.sshmanager.dto.ConnectionCreateRequest;
import com.sshmanager.dto.ConnectionDto;
import com.sshmanager.entity.Connection;
@@ -9,14 +9,15 @@ import com.sshmanager.exception.NotFoundException;
import com.sshmanager.repository.ConnectionRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ConnectionService {
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
@Service
@SuppressWarnings("null")
public class ConnectionService {
private final ConnectionRepository connectionRepository;
private final EncryptionService encryptionService;
private final SshService sshService;
@@ -31,13 +32,13 @@ public class ConnectionService {
this.sshService = sshService;
this.sshBootstrapService = sshBootstrapService;
}
public List<ConnectionDto> listByUserId(Long userId) {
return connectionRepository.findByUserIdOrderByUpdatedAtDesc(userId).stream()
.map(ConnectionDto::fromEntity)
.collect(Collectors.toList());
}
public List<ConnectionDto> listByUserId(Long userId) {
return connectionRepository.findByUserIdOrderByUpdatedAtDesc(userId).stream()
.map(ConnectionDto::fromEntity)
.collect(Collectors.toList());
}
public ConnectionDto getById(Long id, Long userId) {
Connection conn = connectionRepository.findById(id).orElseThrow(
() -> new NotFoundException("Connection not found: " + id));
@@ -101,7 +102,7 @@ public class ConnectionService {
conn = connectionRepository.save(conn);
return ConnectionDto.fromEntity(conn);
}
@Transactional
public void delete(Long id, Long userId) {
Connection conn = connectionRepository.findById(id).orElse(null);
@@ -122,30 +123,30 @@ public class ConnectionService {
}
return conn;
}
public String getDecryptedPassword(Connection conn) {
return conn.getEncryptedPassword() != null ?
encryptionService.decrypt(conn.getEncryptedPassword()) : null;
}
public String getDecryptedPrivateKey(Connection conn) {
return conn.getEncryptedPrivateKey() != null ?
encryptionService.decrypt(conn.getEncryptedPrivateKey()) : null;
}
public String getDecryptedPassphrase(Connection conn) {
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 {
public String getDecryptedPassword(Connection conn) {
return conn.getEncryptedPassword() != null ?
encryptionService.decrypt(conn.getEncryptedPassword()) : null;
}
public String getDecryptedPrivateKey(Connection conn) {
return conn.getEncryptedPrivateKey() != null ?
encryptionService.decrypt(conn.getEncryptedPrivateKey()) : null;
}
public String getDecryptedPassphrase(Connection conn) {
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();
}