diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 6950b88f..4028feeb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -14,6 +14,7 @@ import pro.gravit.launchserver.auth.password.PasswordVerifier; import pro.gravit.launchserver.helper.LegacySessionHelper; import pro.gravit.launchserver.manangers.AuthManager; +import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.utils.helper.SecurityHelper; @@ -162,6 +163,25 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c } } + @Override + public User checkServer(Client client, String username, String serverID) throws IOException { + SQLUser user = (SQLUser) getUserByUsername(username); + if (user == null) { + return null; + } + if (user.getUsername().equals(username) && user.getServerId().equals(serverID)) { + return user; + } + return null; + } + + @Override + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { + SQLUser user = (SQLUser) client.getUser(); + if (user == null) return false; + return user.getUsername().equals(username) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID); + } + @Override public void init(LaunchServer server) { this.server = server; @@ -225,7 +245,6 @@ protected void updateAuth(User user, String accessToken) throws IOException { } } - @Override protected boolean updateServerID(User user, String serverID) throws IOException { try (Connection c = getSQLConfig().getConnection()) { SQLUser SQLUser = (SQLUser) user; @@ -328,12 +347,10 @@ public UUID getUUID() { return uuid; } - @Override public String getServerId() { return serverId; } - @Override public String getAccessToken() { return accessToken; } @@ -372,6 +389,11 @@ public User getUser() { return user; } + @Override + public String getMinecraftAccessToken() { + return user.getAccessToken(); + } + @Override public long getExpireIn() { return 0; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index a6c210b0..4e90b516 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -75,11 +75,6 @@ public AuthManager.AuthReport authorize(User user, AuthResponse.AuthContext cont public abstract void init(LaunchServer server); - // Auth Handler methods - protected boolean updateServerID(User user, String serverID) throws IOException { - throw new UnsupportedOperationException(); - } - public List getDetails(Client client) { return List.of(new AuthPasswordDetails()); } @@ -292,22 +287,9 @@ public void invoke(String... args) throws Exception { return map; } - public User checkServer(Client client, String username, String serverID) throws IOException { - User user = getUserByUsername(username); - if (user == null) { - return null; - } - if (user.getUsername().equals(username) && user.getServerId().equals(serverID)) { - return user; - } - return null; - } + public abstract User checkServer(Client client, String username, String serverID) throws IOException; - public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException { - User user = client.getUser(); - if (user == null) return false; - return user.getUsername().equals(username) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID); - } + public abstract boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException; @SuppressWarnings("unchecked") public T isSupport(Class clazz) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java index ffb9bfb8..42b114bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java @@ -281,21 +281,14 @@ public List getClientApiFeatures() { return apiFeatures; } - @Override - protected boolean updateServerID(User user, String serverID) throws IOException { - var result = requester.send(requester.post(updateServerIdUrl, new UpdateServerIdRequest(user.getUsername(), user.getUUID(), serverID), - null), Void.class); - return result.isSuccessful(); - } - @Override public User checkServer(Client client, String username, String serverID) throws IOException { return requester.send(requester.post(checkServerUrl, new CheckServerRequest(username, serverID), bearerToken), HttpUser.class).getOrThrow(); } @Override - public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException { - var result = requester.send(requester.post(joinServerUrl, new JoinServerRequest(username, accessToken, serverID), bearerToken), Void.class); + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { + var result = requester.send(requester.post(joinServerUrl, new JoinServerRequest(username, uuid, accessToken, serverID), bearerToken), Void.class); return result.isSuccessful(); } @@ -361,11 +354,13 @@ public static class GetHardwareListResponse { public static class JoinServerRequest { public String username; + public UUID uuid; public String accessToken; public String serverId; - public JoinServerRequest(String username, String accessToken, String serverId) { + public JoinServerRequest(String username, UUID uuid, String accessToken, String serverId) { this.username = username; + this.uuid = uuid; this.accessToken = accessToken; this.serverId = serverId; } @@ -421,14 +416,16 @@ public HardwareRequest(byte[] key) { public static class HttpUserSession implements UserSession { private String id; private HttpUser user; + private String minecraftAccessToken; private long expireIn; public HttpUserSession() { } - public HttpUserSession(String id, HttpUser user, long expireIn) { + public HttpUserSession(String id, HttpUser user, String minecraftAccessToken, long expireIn) { this.id = id; this.user = user; + this.minecraftAccessToken = minecraftAccessToken; this.expireIn = expireIn; } @@ -442,6 +439,11 @@ public User getUser() { return user; } + @Override + public String getMinecraftAccessToken() { + return minecraftAccessToken; + } + @Override public long getExpireIn() { return expireIn; @@ -452,6 +454,7 @@ public String toString() { return "HttpUserSession{" + "id='" + id + '\'' + ", user=" + user + + ", minecraftAccessToken='" + minecraftAccessToken + '\'' + ", expireIn=" + expireIn + '}'; } @@ -581,16 +584,6 @@ public UUID getUUID() { return uuid; } - @Override - public String getServerId() { - return serverId; - } - - @Override - public String getAccessToken() { - return accessToken; - } - @Override public ClientPermissions getPermissions() { return permissions; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java index 62c3391c..01dc17ad 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java @@ -94,13 +94,6 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c } } - @Override - protected boolean updateServerID(User user, String serverID) { - MemoryUser memoryUser = (MemoryUser) user; - memoryUser.serverId = serverID; - return true; - } - @Override public User checkServer(Client client, String username, String serverID) { synchronized (memory) { @@ -116,7 +109,7 @@ public User checkServer(Client client, String username, String serverID) { } @Override - public boolean joinServer(Client client, String username, String accessToken, String serverID) { + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) { return true; } @@ -158,16 +151,6 @@ public UUID getUUID() { return uuid; } - @Override - public String getServerId() { - return serverId; - } - - @Override - public String getAccessToken() { - return accessToken; - } - @Override public ClientPermissions getPermissions() { return permissions; @@ -208,6 +191,11 @@ public User getUser() { return user; } + @Override + public String getMinecraftAccessToken() { + return "IGNORED"; + } + @Override public long getExpireIn() { return expireIn; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java index 1989b942..fe0a26cc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java @@ -67,7 +67,7 @@ public User checkServer(Client client, String username, String serverID) throws } @Override - public boolean joinServer(Client client, String username, String accessToken, String serverID) { + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) { return false; // Authorization not supported } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java index 69697c7e..0a95d12f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java @@ -4,6 +4,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.manangers.AuthManager; +import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; import java.io.IOException; @@ -46,7 +47,12 @@ public void init(LaunchServer server) { } @Override - protected boolean updateServerID(User user, String serverID) { + public User checkServer(Client client, String username, String serverID) throws IOException { + return null; + } + + @Override + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { return false; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java index ead51933..acf69db6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java @@ -9,10 +9,6 @@ public interface User { UUID getUUID(); - String getServerId(); - - String getAccessToken(); - ClientPermissions getPermissions(); default boolean isBanned() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/UserSession.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/UserSession.java index 97763e0f..031b627d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/UserSession.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/UserSession.java @@ -5,5 +5,7 @@ public interface UserSession { User getUser(); + String getMinecraftAccessToken(); + long getExpireIn(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java index 23726f37..1899292a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -20,6 +20,7 @@ import java.util.Base64; import java.util.Date; +import java.util.UUID; import static java.util.concurrent.TimeUnit.SECONDS; @@ -93,7 +94,7 @@ public VerifySecureLevelKeyRequestEvent onSuccessVerify(Client client) { } @Override - public boolean onJoinServer(String serverID, String username, Client client) { + public boolean onJoinServer(String serverID, String username, UUID uuid, Client client) { return !enableHardwareFeature || (client.trustLevel != null && client.trustLevel.hardwareInfo != null); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java index e33a9e11..1d152980 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java @@ -2,8 +2,10 @@ import pro.gravit.launchserver.socket.Client; +import java.util.UUID; + public interface JoinServerProtectHandler { - default boolean onJoinServer(String serverID, String username, Client client) { + default boolean onJoinServer(String serverID, String username, UUID uuid, Client client) { return true; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java index 6fec80e5..8c24e6d6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java @@ -115,7 +115,7 @@ public AuthReport auth(AuthResponse.AuthContext context, AuthRequest.AuthPasswor context.client.sessionObject = session; internalAuth(context.client, context.authType, context.pair, user.getUsername(), user.getUUID(), user.getPermissions(), true); if (context.authType == AuthResponse.ConnectTypes.CLIENT && server.config.protectHandler.allowGetAccessToken(context)) { - return AuthReport.ofMinecraftAccessToken(user.getAccessToken(), session); + return AuthReport.ofMinecraftAccessToken(session.getMinecraftAccessToken(), session); } return AuthReport.ofMinecraftAccessToken(null, session); } @@ -166,9 +166,9 @@ public CheckServerReport checkServer(Client client, String username, String serv else return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user)); } - public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException { + public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { if (client.auth == null) return false; - return client.auth.core.joinServer(client, username, accessToken, serverID); + return client.auth.core.joinServer(client, username, uuid, accessToken, serverID); } public PlayerProfile getPlayerProfile(Client client) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index 1a9c3851..82e9d4a2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -10,11 +10,14 @@ import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.HookException; +import java.util.UUID; + public class JoinServerResponse extends SimpleResponse { private transient final Logger logger = LogManager.getLogger(); public String serverID; public String accessToken; public String username; + public UUID uuid; @Override public String getType() { @@ -27,7 +30,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Permissions denied"); return; } - if (username == null || accessToken == null || serverID == null) { + if ((username == null && uuid == null) || accessToken == null || serverID == null) { sendError("Invalid request"); return; } @@ -35,13 +38,13 @@ public void execute(ChannelHandlerContext ctx, Client client) { try { server.authHookManager.joinServerHook.hook(this, client); if (server.config.protectHandler instanceof JoinServerProtectHandler joinServerProtectHandler) { - success = joinServerProtectHandler.onJoinServer(serverID, username, client); + success = joinServerProtectHandler.onJoinServer(serverID, username, uuid, client); if (!success) { sendResult(new JoinServerRequestEvent(false)); return; } } - success = server.authManager.joinServer(client, username, accessToken, serverID); + success = server.authManager.joinServer(client, username, uuid, accessToken, serverID); if (success) { logger.debug("joinServer: {} accessToken: {} serverID: {}", username, accessToken, serverID); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java index ef038715..7d44b68d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java @@ -16,4 +16,5 @@ private ClientProfileVersions() { public static final ClientProfile.Version MINECRAFT_1_18 = ClientProfile.Version.of("1.18"); public static final ClientProfile.Version MINECRAFT_1_19 = ClientProfile.Version.of("1.19"); public static final ClientProfile.Version MINECRAFT_1_20 = ClientProfile.Version.of("1.20"); + public static final ClientProfile.Version MINECRAFT_1_20_2 = ClientProfile.Version.of("1.20.2"); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java index 6a3cf1ab..54c8df02 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java @@ -6,12 +6,16 @@ import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; +import java.util.UUID; + public final class JoinServerRequest extends Request implements WebSocketRequest { // Instance @LauncherNetworkAPI public final String username; @LauncherNetworkAPI + public final UUID uuid; + @LauncherNetworkAPI public final String accessToken; @LauncherNetworkAPI public final String serverID; @@ -19,10 +23,18 @@ public final class JoinServerRequest extends Request imp public JoinServerRequest(String username, String accessToken, String serverID) { this.username = username; + this.uuid = null; this.accessToken = accessToken; this.serverID = VerifyHelper.verifyServerID(serverID); } + public JoinServerRequest(UUID uuid, String accessToken, String serverID) { + this.username = null; + this.uuid = uuid; + this.accessToken = accessToken; + this.serverID = serverID; + } + @Override public String getType() { return "joinServer";