SHA256
Сервер: локальный роутинг и relay DM по access servers
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
package shine.db.dao;
|
||||
|
||||
import shine.db.DbController;
|
||||
import shine.db.KeyEncodingUtil;
|
||||
import shine.db.entities.UserAccessServerRouteEntry;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DAO локальной routing-проекции access servers пользователей.
|
||||
*/
|
||||
public final class UserAccessServersCurrentDAO {
|
||||
|
||||
private static volatile UserAccessServersCurrentDAO instance;
|
||||
private final DbController db = DbController.getInstance();
|
||||
|
||||
private UserAccessServersCurrentDAO() {}
|
||||
|
||||
public static UserAccessServersCurrentDAO getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (UserAccessServersCurrentDAO.class) {
|
||||
if (instance == null) instance = new UserAccessServersCurrentDAO();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public List<UserAccessServerRouteEntry> listByUserLogin(String userLogin) throws SQLException {
|
||||
try (Connection c = db.getConnection()) {
|
||||
return listByUserLogin(c, userLogin);
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserAccessServerRouteEntry> listByUserLogin(Connection c, String userLogin) throws SQLException {
|
||||
String sql = """
|
||||
SELECT user_login, server_login, server_url, server_client_key
|
||||
FROM user_access_servers_current
|
||||
WHERE LOWER(user_login) = LOWER(?)
|
||||
ORDER BY server_login
|
||||
""";
|
||||
List<UserAccessServerRouteEntry> result = new ArrayList<>();
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, userLogin);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
result.add(mapRow(rs));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private UserAccessServerRouteEntry mapRow(ResultSet rs) throws SQLException {
|
||||
UserAccessServerRouteEntry entry = new UserAccessServerRouteEntry();
|
||||
entry.setUserLogin(rs.getString("user_login"));
|
||||
entry.setServerLogin(rs.getString("server_login"));
|
||||
entry.setServerUrl(rs.getString("server_url"));
|
||||
entry.setServerClientKey(KeyEncodingUtil.normalizeKeyToBase64_32(rs.getString("server_client_key")));
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package shine.db.entities;
|
||||
|
||||
/**
|
||||
* Локальная routing-проекция access server пользователя.
|
||||
*
|
||||
* Источник:
|
||||
* - user_access_servers_current
|
||||
*/
|
||||
public class UserAccessServerRouteEntry {
|
||||
|
||||
private String userLogin;
|
||||
private String serverLogin;
|
||||
private String serverUrl;
|
||||
private String serverClientKey;
|
||||
|
||||
public String getUserLogin() { return userLogin; }
|
||||
public void setUserLogin(String userLogin) { this.userLogin = userLogin; }
|
||||
|
||||
public String getServerLogin() { return serverLogin; }
|
||||
public void setServerLogin(String serverLogin) { this.serverLogin = serverLogin; }
|
||||
|
||||
public String getServerUrl() { return serverUrl; }
|
||||
public void setServerUrl(String serverUrl) { this.serverUrl = serverUrl; }
|
||||
|
||||
public String getServerClientKey() { return serverClientKey; }
|
||||
public void setServerClientKey(String serverClientKey) { this.serverClientKey = serverClientKey; }
|
||||
}
|
||||
Reference in New Issue
Block a user