mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
AuthHookManager
This commit is contained in:
parent
726bcff1b4
commit
fe2177151e
3 changed files with 71 additions and 1 deletions
|
@ -277,6 +277,8 @@ public static void main(String... args) throws Throwable {
|
|||
public final SessionManager sessionManager;
|
||||
|
||||
public final SocketHookManager socketHookManager;
|
||||
|
||||
public final AuthHookManager authHookManager;
|
||||
// Server
|
||||
|
||||
public final ModulesManager modulesManager;
|
||||
|
@ -393,6 +395,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
|
|||
reloadManager = new ReloadManager();
|
||||
reconfigurableManager = new ReconfigurableManager();
|
||||
socketHookManager = new SocketHookManager();
|
||||
authHookManager = new AuthHookManager();
|
||||
|
||||
GarbageManager.registerNeedGC(sessionManager);
|
||||
GarbageManager.registerNeedGC(limiter);
|
||||
|
@ -538,11 +541,13 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
newConfig.launch4j = new ExeConf();
|
||||
newConfig.launch4j.copyright = "© GravitLauncher Team";
|
||||
newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString());
|
||||
newConfig.launch4j.fileVer = Launcher.getVersion().getVersionString();
|
||||
newConfig.launch4j.fileVer = Launcher.getVersion().getVersionString().concat(".").concat(String.valueOf(Launcher.getVersion().patch));
|
||||
newConfig.launch4j.internalName = "Launcher";
|
||||
newConfig.launch4j.trademarks = "This product is licensed under GPLv3";
|
||||
newConfig.launch4j.txtFileVersion = "%s, build %d";
|
||||
newConfig.launch4j.txtProductVersion = "%s, build %d";
|
||||
newConfig.launch4j.productName = "GravitLauncher";
|
||||
newConfig.launch4j.productVer = newConfig.launch4j.fileVer;
|
||||
newConfig.buildPostTransform = new PostBuildTransformConf();
|
||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||
newConfig.authHandler = new MemoryAuthHandler();
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package ru.gravit.launchserver.manangers;
|
||||
|
||||
import ru.gravit.launchserver.response.auth.AuthResponse;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AuthHookManager {
|
||||
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
|
||||
private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
|
||||
@FunctionalInterface
|
||||
public interface AuthPreHook
|
||||
{
|
||||
void preAuthHook(AuthResponse.AuthContext context, Client client);
|
||||
}
|
||||
public interface AuthPostHook
|
||||
{
|
||||
void postAuthHook(AuthResponse.AuthContext context, Client client);
|
||||
}
|
||||
public void registerPostHook(AuthPostHook hook)
|
||||
{
|
||||
if(POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
||||
POST_HOOKS.add(hook);
|
||||
}
|
||||
public void registerPreHook(AuthPreHook hook)
|
||||
{
|
||||
if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>();
|
||||
PRE_HOOKS.add(hook);
|
||||
}
|
||||
public void preHook(AuthResponse.AuthContext context, Client client)
|
||||
{
|
||||
for(AuthPreHook preHook : PRE_HOOKS)
|
||||
{
|
||||
preHook.preAuthHook(context,client);
|
||||
}
|
||||
}
|
||||
public void postHook(AuthResponse.AuthContext context, Client client)
|
||||
{
|
||||
for(AuthPostHook postHook : POST_HOOKS)
|
||||
{
|
||||
postHook.postAuthHook(context, client);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,24 @@ private static String echo(int length) {
|
|||
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
||||
super(server, session, input, output, ip);
|
||||
}
|
||||
public static class AuthContext
|
||||
{
|
||||
public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) {
|
||||
this.session = session;
|
||||
this.login = login;
|
||||
this.password_lenght = password_lenght;
|
||||
this.client = client;
|
||||
this.hwid = hwid;
|
||||
this.isServerAuth = isServerAuth;
|
||||
}
|
||||
|
||||
public long session;
|
||||
public String login;
|
||||
public int password_lenght; //Use AuthProvider for get password
|
||||
public String client;
|
||||
public String hwid;
|
||||
public boolean isServerAuth;
|
||||
}
|
||||
@Override
|
||||
public void reply() throws Exception {
|
||||
String login = input.readString(SerializeLimits.MAX_LOGIN);
|
||||
|
@ -63,7 +80,9 @@ public void reply() throws Exception {
|
|||
AuthProvider provider = server.config.authProvider[auth_id];
|
||||
Client clientData = server.sessionManager.getClient(session);
|
||||
clientData.type = Client.Type.USER;
|
||||
AuthContext context = new AuthContext(session,login,password.length(),client,hwid_str,false);
|
||||
try {
|
||||
server.authHookManager.preHook(context,clientData);
|
||||
if (server.limiter.isLimit(ip)) {
|
||||
AuthProvider.authError(server.config.authRejectString);
|
||||
return;
|
||||
|
@ -91,6 +110,7 @@ public void reply() throws Exception {
|
|||
}
|
||||
}
|
||||
server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username);
|
||||
server.authHookManager.postHook(context,clientData);
|
||||
} catch (AuthException | HWIDException e) {
|
||||
if(e.getMessage() == null) LogHelper.error(e);
|
||||
requestError(e.getMessage());
|
||||
|
|
Loading…
Reference in a new issue