mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-04 15:31:53 +03:00
RequestAuthHandler 3/5
This commit is contained in:
parent
b7938d6bd6
commit
49d84cc405
2 changed files with 38 additions and 9 deletions
|
@ -42,6 +42,7 @@ public static void registerHandlers() {
|
|||
registerHandler("null", NullAuthHandler.class);
|
||||
registerHandler("memory", MemoryAuthHandler.class);
|
||||
registerHandler("mysql", MySQLAuthHandler.class);
|
||||
registerHandler("request", RequestAuthHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.gravit.launchserver.auth.handler;
|
||||
|
||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -15,8 +16,8 @@
|
|||
|
||||
public final class RequestAuthHandler extends AuthHandler {
|
||||
// Из конфига строки
|
||||
private String url;
|
||||
private String urlGetUUID;
|
||||
private String urlGetAll;
|
||||
private String urlGetUsername;
|
||||
private String urlUpdateAccessToken;
|
||||
private String urlUpdateServerID;
|
||||
|
@ -32,6 +33,11 @@ public void init() {
|
|||
pattern = Pattern.compile(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID auth(AuthProviderResult authResult) throws IOException {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID checkServer(String username, String serverID) throws IOException {
|
||||
//TODO
|
||||
|
@ -39,11 +45,6 @@ public UUID checkServer(String username, String serverID) throws IOException {
|
|||
|
||||
@Override
|
||||
public boolean joinServer(String username, String accessToken, String serverID) throws IOException {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID usernameToUUID(String username) throws IOException {
|
||||
URL url;
|
||||
HttpURLConnection conn;
|
||||
BufferedReader rd;
|
||||
|
@ -59,10 +60,37 @@ public UUID usernameToUUID(String username) throws IOException {
|
|||
}
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error("[Request AuthHandler] Error get UUID by username");
|
||||
LogHelper.error("[Request AuthHandler] Error joinserver");
|
||||
}
|
||||
//TODO конвертирование string в uuid
|
||||
return result;
|
||||
String[] uas = result.split(":");
|
||||
if (uas[0] == username && uas[1] == accessToken && uas[2] == serverID) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID usernameToUUID(String username) throws IOException {
|
||||
URL url;
|
||||
HttpURLConnection conn;
|
||||
BufferedReader rd;
|
||||
String line;
|
||||
String result = "";
|
||||
try {
|
||||
url = new URL(format("%s?username=%s",urlGetUUID,username));
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
while ((line = rd.readLine()) != null) {
|
||||
result += line;
|
||||
}
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error("[Request AuthHandler] Error get UUID by username");
|
||||
}
|
||||
//TODO конвертирование string в uuid
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue