diff --git a/LaunchServer/source/auth/provider/AuthProvider.java b/LaunchServer/source/auth/provider/AuthProvider.java index c8eee41..26dbedf 100644 --- a/LaunchServer/source/auth/provider/AuthProvider.java +++ b/LaunchServer/source/auth/provider/AuthProvider.java @@ -9,6 +9,7 @@ import launcher.helper.VerifyHelper; import launcher.serialize.config.ConfigObject; import launcher.serialize.config.entry.BlockConfigEntry; +import launchserver.auth.AuthException; public abstract class AuthProvider extends ConfigObject implements Flushable { private static final Map> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); @@ -22,6 +23,11 @@ public abstract String auth(String login, String password) throws Exception; @LauncherAPI + public static String authError(String message) throws AuthException { + throw new AuthException(message); + } + + @LauncherAPI public static AuthProvider newProvider(String name, BlockConfigEntry block) { VerifyHelper.verifyIDName(name); Adapter authHandlerAdapter = VerifyHelper.getMapValue(AUTH_PROVIDERS, name, diff --git a/LaunchServer/source/auth/provider/DigestAuthProvider.java b/LaunchServer/source/auth/provider/DigestAuthProvider.java index e5d5d6d..fab94bf 100644 --- a/LaunchServer/source/auth/provider/DigestAuthProvider.java +++ b/LaunchServer/source/auth/provider/DigestAuthProvider.java @@ -41,7 +41,7 @@ // Verify is valid if (!valid) { - throw new AuthException("Incorrect username or password"); + authError("Incorrect username or password"); } } } diff --git a/LaunchServer/source/auth/provider/HTTPAuthProvider.java b/LaunchServer/source/auth/provider/HTTPAuthProvider.java index 7e7ce0f..8e5f978 100644 --- a/LaunchServer/source/auth/provider/HTTPAuthProvider.java +++ b/LaunchServer/source/auth/provider/HTTPAuthProvider.java @@ -9,7 +9,6 @@ import launcher.helper.IOHelper; import launcher.serialize.config.entry.BlockConfigEntry; import launcher.serialize.config.entry.StringConfigEntry; -import launchserver.auth.AuthException; public final class HTTPAuthProvider extends AuthProvider { private final String url; @@ -24,11 +23,11 @@ @Override public String auth(String login, String password) throws IOException { String currentResponse = IOHelper.request(new URL(getFormattedURL(login, password))); + + // Match username Matcher matcher = response.matcher(currentResponse); - if (!matcher.matches() || matcher.groupCount() < 1) { - throw new AuthException(currentResponse); - } - return matcher.group("username"); + return matcher.matches() && matcher.groupCount() >= 1 ? + matcher.group("username") : authError(currentResponse); } @Override diff --git a/LaunchServer/source/auth/provider/MySQLAuthProvider.java b/LaunchServer/source/auth/provider/MySQLAuthProvider.java index e19f9cc..236f89c 100644 --- a/LaunchServer/source/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/source/auth/provider/MySQLAuthProvider.java @@ -36,12 +36,8 @@ // Execute SQL query try (ResultSet set = statement.executeQuery()) { - if (!set.next()) { - throw new AuthException("Incorrect username or password"); - } - - // Get username - return set.getString(1); + return set.next() ? set.getString(1) : + authError("Incorrect username or password"); } } } diff --git a/LaunchServer/source/auth/provider/RejectAuthProvider.java b/LaunchServer/source/auth/provider/RejectAuthProvider.java index 6773ebd..23ee57b 100644 --- a/LaunchServer/source/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/source/auth/provider/RejectAuthProvider.java @@ -15,7 +15,7 @@ @Override public String auth(String login, String password) throws AuthException { - throw new AuthException(message); + return authError(message); } @Override diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index 8bf0159..a42c7ea 100755 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -62,7 +62,10 @@ var VerifyHelper = VerifyHelperClass.static; // Helper JS class API imports -var JSApplication = JSApplicationClass.static; +var JSApplication = null; +if(typeof JSApplicationClass !== 'undefined') { + JSApplication = JSApplicationClass.static; +} // API wrapper function tryWithResources(closeable, f) {