[FEATURE] JsonAuthHandler

This commit is contained in:
Gravit 2019-04-12 04:11:33 +07:00
parent cfe6c6c2ac
commit ab57e7d2d7
2 changed files with 81 additions and 0 deletions

View file

@ -40,6 +40,7 @@ public static String getHandlerName(Class<AuthHandler> clazz) {
public static void registerHandlers() { public static void registerHandlers() {
if (!registredHandl) { if (!registredHandl) {
registerHandler("null", NullAuthHandler.class); registerHandler("null", NullAuthHandler.class);
registerHandler("json", JsonAuthHandler.class);
registerHandler("memory", MemoryAuthHandler.class); registerHandler("memory", MemoryAuthHandler.class);
registerHandler("mysql", MySQLAuthHandler.class); registerHandler("mysql", MySQLAuthHandler.class);
registredHandl = true; registredHandl = true;

View file

@ -0,0 +1,80 @@
package ru.gravit.launchserver.auth.handler;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.HTTPRequest;
import java.io.IOException;
import java.net.URL;
import java.util.UUID;
public class JsonAuthHandler extends CachedAuthHandler {
public URL getUrl;
public URL updateAuthUrl;
public URL updateServerIdUrl;
public class EntryRequestByUsername
{
public String username;
public EntryRequestByUsername(String username) {
this.username = username;
}
}
public class EntryRequestByUUID
{
public UUID uuid;
public EntryRequestByUUID(UUID uuid) {
this.uuid = uuid;
}
}
public class UpdateAuthRequest
{
public UUID uuid;
public String username;
public String accessToken;
public UpdateAuthRequest(UUID uuid, String username, String accessToken) {
this.uuid = uuid;
this.username = username;
this.accessToken = accessToken;
}
}
public class UpdateServerIDRequest
{
public UUID uuid;
public String serverID;
public UpdateServerIDRequest(UUID uuid, String serverID) {
this.uuid = uuid;
this.serverID = serverID;
}
}
public class SuccessResponse
{
public boolean success;
}
@Override
protected Entry fetchEntry(String username) throws IOException {
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new EntryRequestByUsername(username)), getUrl), Entry.class);
}
@Override
protected Entry fetchEntry(UUID uuid) throws IOException {
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new EntryRequestByUUID(uuid)), getUrl), Entry.class);
}
@Override
protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException {
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new UpdateAuthRequest(uuid, username, accessToken)), updateAuthUrl), SuccessResponse.class).success;
}
@Override
protected boolean updateServerID(UUID uuid, String serverID) throws IOException {
return LaunchServer.gson.fromJson(HTTPRequest.jsonRequest(LaunchServer.gson.toJsonTree(new UpdateServerIDRequest(uuid, serverID)), updateServerIdUrl), SuccessResponse.class).success;
}
@Override
public void close() throws IOException {
}
}