- Maked classes final

This commit is contained in:
2025-09-29 17:56:51 +02:00
parent 1fe77f6076
commit f787463efc
27 changed files with 59 additions and 31 deletions

View File

@@ -30,7 +30,7 @@ import java.lang.reflect.InvocationTargetException;
* The main bridge class for the protocol connection. * The main bridge class for the protocol connection.
* It manages the protocol settings, version, and side instances. * It manages the protocol settings, version, and side instances.
*/ */
public class ProtocolBridge { public final class ProtocolBridge {
/** /**
* The singleton instance of the ProtocolBridge class * The singleton instance of the ProtocolBridge class

View File

@@ -7,7 +7,7 @@ import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
/** /**
* Settings for the protocol connection. * Settings for the protocol connection.
*/ */
public class ProtocolSettings extends DefaultMethodsOverrider { public final class ProtocolSettings extends DefaultMethodsOverrider {
/** /**
* The host to connect to. * The host to connect to.

View File

@@ -3,7 +3,7 @@ package org.openautonomousconnection.protocol.exceptions;
/** /**
* Exception thrown when an unsupported protocol is encountered. * Exception thrown when an unsupported protocol is encountered.
*/ */
public class UnsupportedProtocolException extends RuntimeException { public final class UnsupportedProtocolException extends RuntimeException {
public UnsupportedProtocolException() { public UnsupportedProtocolException() {
this("Selected protocol is not supported!"); this("Selected protocol is not supported!");

View File

@@ -15,7 +15,7 @@ import java.io.IOException;
* Listener for client-side events such as connection and disconnection. * Listener for client-side events such as connection and disconnection.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
public class ClientListener extends EventListener { public final class ClientListener extends EventListener {
/** /**
* Handles the event when a client connects. * Handles the event when a client connects.

View File

@@ -13,7 +13,7 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
* Listener for DNS server connection events. * Listener for DNS server connection events.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS)
public class DNSServerListener extends EventListener { public final class DNSServerListener extends EventListener {
/** /**
* Handles the event when a connection handler connects to the DNS server. * Handles the event when a connection handler connects to the DNS server.

View File

@@ -13,7 +13,7 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
* Listener for web server connection events. * Listener for web server connection events.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public class WebServerListener extends EventListener { public final class WebServerListener extends EventListener {
/** /**
* Handles the event when a connection is established. * Handles the event when a connection is established.

View File

@@ -18,7 +18,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public class AuthPacket extends OACPacket { public final class AuthPacket extends OACPacket {
File certificatesFolder = new File("certificates"); File certificatesFolder = new File("certificates");
File publicFolder = new File(certificatesFolder, "public"); File publicFolder = new File(certificatesFolder, "public");

View File

@@ -11,7 +11,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public class GetDestinationPacket extends OACPacket { public final class GetDestinationPacket extends OACPacket {
private Domain domain; private Domain domain;
private int clientID; private int clientID;
private DNSResponseCode validationResponse; private DNSResponseCode validationResponse;

View File

@@ -10,7 +10,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public class UnsupportedClassicPacket extends OACPacket { public final class UnsupportedClassicPacket extends OACPacket {
private Class<? extends OACPacket> unsupportedClassicPacket; private Class<? extends OACPacket> unsupportedClassicPacket;
private Object[] content; private Object[] content;

View File

@@ -10,7 +10,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public class ValidateDomainPacket extends OACPacket { public final class ValidateDomainPacket extends OACPacket {
private Domain domain; private Domain domain;
private int clientID; private int clientID;

View File

@@ -15,7 +15,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.SQLException; import java.sql.SQLException;
public class Classic_DomainPacket extends OACPacket { public final class Classic_DomainPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;

View File

@@ -10,7 +10,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public class Classic_MessagePacket extends OACPacket { public final class Classic_MessagePacket extends OACPacket {
private String message; private String message;
private int clientID; private int clientID;

View File

@@ -16,7 +16,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.sql.SQLException; import java.sql.SQLException;
public class Classic_PingPacket extends OACPacket { public final class Classic_PingPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;

View File

@@ -8,5 +8,5 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
* Event triggered when a client successfully connects to a DNS protocol server. * Event triggered when a client successfully connects to a DNS protocol server.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS)
public class ConnectedToProtocolDNSServerEvent extends Event { public final class ConnectedToProtocolDNSServerEvent extends Event {
} }

View File

@@ -4,6 +4,7 @@ import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
import dev.unlegitdqrk.unlegitlibrary.file.FileUtils; import dev.unlegitdqrk.unlegitlibrary.file.FileUtils;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer; import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer;
import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils; import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
import dev.unlegitdqrk.unlegitlibrary.string.RandomString;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
@@ -19,12 +20,13 @@ import java.io.IOException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* Represents the web server for the protocol. * Represents the web server for the protocol.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public class ProtocolWebServer { public final class ProtocolWebServer {
/** /**
* Folder for web content. * Folder for web content.
*/ */
@@ -76,6 +78,17 @@ public class ProtocolWebServer {
@Getter @Getter
private List<ConnectedWebClient> clients; private List<ConnectedWebClient> clients;
/**
* The configuration file for the web server.
*/
private final File configFile;
/**
* A unique secret for session management.
*/
@Getter
private String uniqueSessionString;
/** /**
* Initializes the web server with the given configuration, authentication, and rules files. * Initializes the web server with the given configuration, authentication, and rules files.
* @param configFile The configuration file. * @param configFile The configuration file.
@@ -87,6 +100,9 @@ public class ProtocolWebServer {
// Initialize the list of connected clients // Initialize the list of connected clients
this.clients = new ArrayList<>(); this.clients = new ArrayList<>();
// Store the configuration file
this.configFile = configFile;
// Set up folder structure for certificates // Set up folder structure for certificates
folderStructure = new ServerCertificateFolderStructure(); folderStructure = new ServerCertificateFolderStructure();
@@ -140,6 +156,8 @@ public class ProtocolWebServer {
} }
// Load authentication and rules // Load authentication and rules
uniqueSessionString = AuthManager.sha256(new RandomString(new Random(System.currentTimeMillis()).nextInt(10, 20)).nextString());
AuthManager.loadAuthFile(authFile); AuthManager.loadAuthFile(authFile);
RuleManager.loadRules(rulesFile); RuleManager.loadRules(rulesFile);
@@ -261,6 +279,15 @@ public class ProtocolWebServer {
if (!found) throw new CertificateException("Missing " + prefix + NetworkUtils.getPublicIPAddress() + extension); if (!found) throw new CertificateException("Missing " + prefix + NetworkUtils.getPublicIPAddress() + extension);
} }
/**
* Retrieves the configuration manager for the web server.
* @return The configuration manager.
* @throws IOException If an I/O error occurs while loading or saving the configuration.
*/
public final ConfigurationManager getConfigurationManager() throws IOException {
return getConfigurationManager(configFile);
}
/** /**
* Loads and initializes the configuration manager with default settings if necessary. * Loads and initializes the configuration manager with default settings if necessary.
* @param configFile The configuration file to load. * @param configFile The configuration file to load.

View File

@@ -16,7 +16,7 @@ import java.util.Map;
* Loads user credentials from a file and verifies login attempts. * Loads user credentials from a file and verifies login attempts.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public class AuthManager { public final class AuthManager {
/** /**
* Map of usernames to their SHA-256 hashed passwords * Map of usernames to their SHA-256 hashed passwords
@@ -67,7 +67,7 @@ public class AuthManager {
* @param input The input string to hash. * @param input The input string to hash.
* @return The hexadecimal representation of the SHA-256 hash. * @return The hexadecimal representation of the SHA-256 hash.
*/ */
private static String sha256(String input) { public static String sha256(String input) {
try { try {
MessageDigest md = MessageDigest.getInstance("SHA-256"); MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8)); byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));

View File

@@ -15,7 +15,7 @@ import java.util.Map;
* Loads allow, deny, and auth rules from a JSON file and provides methods to check access. * Loads allow, deny, and auth rules from a JSON file and provides methods to check access.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public class RuleManager { public final class RuleManager {
/** /**
* Lists of path patterns for allow, deny, and auth rules * Lists of path patterns for allow, deny, and auth rules
*/ */

View File

@@ -1,6 +1,7 @@
package org.openautonomousconnection.protocol.side.web.managers; package org.openautonomousconnection.protocol.side.web.managers;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@@ -15,7 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Provides methods to create, validate, and invalidate sessions. * Provides methods to create, validate, and invalidate sessions.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public class SessionManager { public final class SessionManager {
/** /**
* Map of session IDs to Session objects. * Map of session IDs to Session objects.
@@ -41,7 +42,7 @@ public class SessionManager {
secureRandom.nextBytes(bytes); secureRandom.nextBytes(bytes);
// Encode the bytes to a URL-safe Base64 string // Encode the bytes to a URL-safe Base64 string
String sessionId = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes); String sessionId = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes) + ProtocolBridge.getInstance().getProtocolWebServer().getUniqueSessionString();
// Create and store the new session // Create and store the new session
sessions.put(sessionId, new Session(login, ip, userAgent)); sessions.put(sessionId, new Session(login, ip, userAgent));
@@ -121,7 +122,7 @@ public class SessionManager {
this.login = login; this.login = login;
this.ip = ip; this.ip = ip;
this.userAgent = userAgent; this.userAgent = userAgent;
this.expiresAt = System.currentTimeMillis() + Main.getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000; this.expiresAt = System.currentTimeMillis() + (long) ProtocolBridge.getInstance().getProtocolWebServer().getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000;
} }
/** /**
@@ -147,7 +148,7 @@ public class SessionManager {
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
void refresh() throws IOException { void refresh() throws IOException {
this.expiresAt = System.currentTimeMillis() + Main.getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000; this.expiresAt = System.currentTimeMillis() + (long) ProtocolBridge.getInstance().getProtocolWebServer().getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000;
} }
} }
} }

View File

@@ -12,7 +12,7 @@ import java.util.List;
/** /**
* Class representing a domain with its components such as subname, name, top-level name, path, query, fragment, and protocol. * Class representing a domain with its components such as subname, name, top-level name, path, query, fragment, and protocol.
*/ */
public class Domain implements Serializable { public final class Domain implements Serializable {
/** /**
* The subname of the domain (e.g., "sub" in "sub.example.com"). * The subname of the domain (e.g., "sub" in "sub.example.com").
*/ */

View File

@@ -14,7 +14,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Cla
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_DomainPacketReceivedEvent extends Event { public final class Classic_DomainPacketReceivedEvent extends Event {
public final Classic_ProtocolVersion protocolVersion; public final Classic_ProtocolVersion protocolVersion;
public final Classic_Domain domain; public final Classic_Domain domain;

View File

@@ -13,7 +13,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Cla
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_PingPacketReceivedEvent extends Event { public final class Classic_PingPacketReceivedEvent extends Event {
public final Classic_ProtocolVersion protocolVersion; public final Classic_ProtocolVersion protocolVersion;
public final Classic_Domain domain; public final Classic_Domain domain;
public final Classic_RequestDomain requestDomain; public final Classic_RequestDomain requestDomain;

View File

@@ -11,7 +11,7 @@ import java.io.Serializable;
* This class is deprecated and users are encouraged to use the Domain class instead. * This class is deprecated and users are encouraged to use the Domain class instead.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_Domain implements Serializable { public final class Classic_Domain implements Serializable {
/** /**
* The name of the domain (e.g., "example" in "example.com"). * The name of the domain (e.g., "example" in "example.com").

View File

@@ -5,7 +5,7 @@ package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
* This class extends Classic_Domain and is used for local domain representation. * This class extends Classic_Domain and is used for local domain representation.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_LocalDomain extends Classic_Domain { public final class Classic_LocalDomain extends Classic_Domain {
public Classic_LocalDomain(String name, String endName, String path) { public Classic_LocalDomain(String name, String endName, String path) {
super(name, endName, null, path); super(name, endName, null, path);
} }

View File

@@ -7,7 +7,7 @@ import java.io.Serializable;
* This class extends Classic_Domain and is used for requesting domain information. * This class extends Classic_Domain and is used for requesting domain information.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_RequestDomain extends Classic_Domain implements Serializable { public final class Classic_RequestDomain extends Classic_Domain implements Serializable {
public Classic_RequestDomain(String name, String topLevelDomain, String path) { public Classic_RequestDomain(String name, String topLevelDomain, String path) {
super(name, topLevelDomain, null, path); super(name, topLevelDomain, null, path);

View File

@@ -6,7 +6,7 @@ import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
* This class contains predefined HTML content for various website responses in the Classic protocol. * This class contains predefined HTML content for various website responses in the Classic protocol.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_WebsitesContent extends DefaultMethodsOverrider { public final class Classic_WebsitesContent extends DefaultMethodsOverrider {
public static final String DOMAIN_NOT_FOUND = """ public static final String DOMAIN_NOT_FOUND = """
<html> <html>

View File

@@ -7,7 +7,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Cla
/** /**
* Utility class for converting between Classic protocol objects and new protocol objects. * Utility class for converting between Classic protocol objects and new protocol objects.
*/ */
public class ClassicConverter { public final class ClassicConverter {
/** /**
* Converts a Classic_Domain object to a Domain object. * Converts a Classic_Domain object to a Domain object.

View File

@@ -22,7 +22,7 @@ import java.net.URL;
* and web content retrieval. * and web content retrieval.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_ClientListener extends EventListener { public final class Classic_ClientListener extends EventListener {
/** /**
* Handles the event when a domain packet is received. * Handles the event when a domain packet is received.