mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] AuthDetails support
This commit is contained in:
parent
40e4949c47
commit
d1e671a935
12 changed files with 118 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
|||
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
||||
import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
||||
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import pro.gravit.launchserver.auth.protect.ProtectHandler;
|
||||
import pro.gravit.launchserver.auth.protect.hwid.HWIDProvider;
|
||||
|
@ -233,6 +234,7 @@ public static void registerAll() {
|
|||
WebSocketService.registerResponses();
|
||||
DaoProvider.registerProviders();
|
||||
AuthRequest.registerProviders();
|
||||
GetAvailabilityAuthRequest.registerProviders();
|
||||
HWIDProvider.registerProviders();
|
||||
OptionalAction.registerProviders();
|
||||
SessionStorage.registerProviders();
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.details.AuthPasswordDetails;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.utils.ProviderMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AuthProvider implements AutoCloseable {
|
||||
public static final ProviderMap<AuthProvider> providers = new ProviderMap<>("AuthProvider");
|
||||
|
@ -31,14 +34,20 @@ public static void registerProviders() {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getFirstAuthType() {
|
||||
return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.PASSWORD;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getSecondAuthType() {
|
||||
return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.NONE;
|
||||
}
|
||||
|
||||
public List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> getDetails(Client client) {
|
||||
return List.of(new AuthPasswordDetails());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the username and password
|
||||
*
|
||||
|
|
|
@ -19,7 +19,7 @@ public String getType() {
|
|||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
|
||||
for (AuthProviderPair pair : server.config.auth.values()) {
|
||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType()));
|
||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getDetails(client)));
|
||||
}
|
||||
sendResult(new GetAvailabilityAuthRequestEvent(list));
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestException;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
||||
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
|
||||
import pro.gravit.launcher.request.websockets.StdWebSocketService;
|
||||
import pro.gravit.launcher.utils.NativeJVMHalt;
|
||||
|
@ -116,6 +117,7 @@ public static void main(String... args) throws Throwable {
|
|||
|
||||
public static void initGson(ClientModuleManager modulesManager) {
|
||||
AuthRequest.registerProviders();
|
||||
GetAvailabilityAuthRequest.registerProviders();
|
||||
OptionalAction.registerProviders();
|
||||
Launcher.gsonManager = new ClientGsonManager(modulesManager);
|
||||
Launcher.gsonManager.initGson();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestException;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
||||
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
|
||||
import pro.gravit.launcher.serialize.HInput;
|
||||
import pro.gravit.launcher.utils.DirWatcher;
|
||||
|
@ -183,6 +184,7 @@ public static void main(String[] args) throws Throwable {
|
|||
|
||||
private static void initGson(ClientModuleManager moduleManager) {
|
||||
AuthRequest.registerProviders();
|
||||
GetAvailabilityAuthRequest.registerProviders();
|
||||
OptionalAction.registerProviders();
|
||||
Launcher.gsonManager = new ClientGsonManager(moduleManager);
|
||||
Launcher.gsonManager.initGson();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.events.RequestEvent;
|
||||
import pro.gravit.utils.TypeSerializeInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -37,22 +38,34 @@ public enum ServerFeature {
|
|||
|
||||
public static class AuthAvailability {
|
||||
@LauncherNetworkAPI
|
||||
public final String name;
|
||||
public String name;
|
||||
@LauncherNetworkAPI
|
||||
public final String displayName;
|
||||
public String displayName;
|
||||
@Deprecated
|
||||
@LauncherNetworkAPI
|
||||
public final AuthType firstType;
|
||||
public AuthType firstType;
|
||||
@Deprecated
|
||||
@LauncherNetworkAPI
|
||||
public final AuthType secondType;
|
||||
public AuthType secondType;
|
||||
|
||||
public final List<AuthAvailabilityDetails> details;
|
||||
|
||||
@Deprecated
|
||||
public AuthAvailability(String name, String displayName, AuthType firstType, AuthType secondType) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.firstType = firstType;
|
||||
this.secondType = secondType;
|
||||
this.details = null;
|
||||
}
|
||||
|
||||
public AuthAvailability(String name, String displayName, List<AuthAvailabilityDetails> details) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public enum AuthType {
|
||||
@LauncherNetworkAPI
|
||||
PASSWORD,
|
||||
|
@ -68,4 +81,6 @@ public enum AuthType {
|
|||
OTHER
|
||||
}
|
||||
}
|
||||
public interface AuthAvailabilityDetails extends TypeSerializeInterface {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.auth.details.AuthPasswordDetails;
|
||||
import pro.gravit.launcher.request.auth.details.AuthWebViewDetails;
|
||||
import pro.gravit.launcher.request.auth.password.*;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.ProviderMap;
|
||||
|
|
|
@ -2,10 +2,26 @@
|
|||
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.auth.details.AuthPasswordDetails;
|
||||
import pro.gravit.launcher.request.auth.details.AuthTotpDetails;
|
||||
import pro.gravit.launcher.request.auth.details.AuthWebViewDetails;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.ProviderMap;
|
||||
|
||||
public class GetAvailabilityAuthRequest extends Request<GetAvailabilityAuthRequestEvent> implements WebSocketRequest {
|
||||
|
||||
public static final ProviderMap<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> providers = new ProviderMap<>();
|
||||
private static boolean registeredProviders = false;
|
||||
|
||||
public static void registerProviders() {
|
||||
if(!registeredProviders) {
|
||||
providers.register("password", AuthPasswordDetails.class);
|
||||
providers.register("webview", AuthWebViewDetails.class);
|
||||
providers.register("totp", AuthTotpDetails.class);
|
||||
registeredProviders = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "getAvailabilityAuth";
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package pro.gravit.launcher.request.auth.details;
|
||||
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
|
||||
public class AuthPasswordDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "password";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package pro.gravit.launcher.request.auth.details;
|
||||
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
|
||||
public class AuthTotpDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails {
|
||||
public final String alg;
|
||||
public final int maxKeyLength;
|
||||
|
||||
public AuthTotpDetails(String alg, int maxKeyLength) {
|
||||
this.alg = alg;
|
||||
this.maxKeyLength = maxKeyLength;
|
||||
}
|
||||
|
||||
public AuthTotpDetails(String alg) {
|
||||
this.alg = alg;
|
||||
this.maxKeyLength = 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "totp";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package pro.gravit.launcher.request.auth.details;
|
||||
|
||||
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
|
||||
|
||||
public class AuthWebViewDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails {
|
||||
public final String url;
|
||||
public final String redirectUrl;
|
||||
public final boolean canBrowser;
|
||||
public final boolean onlyBrowser;
|
||||
|
||||
public AuthWebViewDetails(String url, String redirectUrl, boolean canBrowser, boolean onlyBrowser) {
|
||||
this.url = url;
|
||||
this.redirectUrl = redirectUrl;
|
||||
this.canBrowser = canBrowser;
|
||||
this.onlyBrowser = onlyBrowser;
|
||||
}
|
||||
|
||||
public AuthWebViewDetails(String url, String redirectUrl) {
|
||||
this.url = url;
|
||||
this.redirectUrl = redirectUrl;
|
||||
this.canBrowser = true;
|
||||
this.onlyBrowser = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "webview";
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestException;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
||||
import pro.gravit.launcher.request.update.ProfilesRequest;
|
||||
import pro.gravit.launcher.server.setup.ServerWrapperSetup;
|
||||
import pro.gravit.utils.PublicURLClassLoader;
|
||||
|
@ -127,6 +128,7 @@ public boolean loopAuth(int count, int sleeptime) {
|
|||
public void run(String... args) throws Throwable {
|
||||
initGson(modulesManager);
|
||||
AuthRequest.registerProviders();
|
||||
GetAvailabilityAuthRequest.registerProviders();
|
||||
OptionalAction.registerProviders();
|
||||
if (args.length > 0 && args[0].equals("setup") && !disableSetup) {
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
|
|
Loading…
Reference in a new issue