mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] MergeAuthCoreProvider
This commit is contained in:
parent
1ffd36fc82
commit
b0fba84fbb
6 changed files with 102 additions and 5 deletions
|
@ -22,6 +22,7 @@ public final class AuthProviderPair {
|
|||
public transient String name;
|
||||
public transient Set<String> features;
|
||||
public String displayName;
|
||||
public boolean visible = true;
|
||||
private transient boolean warnOAuthShow = false;
|
||||
|
||||
public AuthProviderPair() {
|
||||
|
|
|
@ -46,6 +46,7 @@ public static void registerProviders() {
|
|||
providers.register("postgresql", PostgresSQLCoreProvider.class);
|
||||
providers.register("memory", MemoryAuthCoreProvider.class);
|
||||
providers.register("http", HttpAuthCoreProvider.class);
|
||||
providers.register("merge", MergeAuthCoreProvider.class);
|
||||
registredProviders = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package pro.gravit.launchserver.auth.core;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MergeAuthCoreProvider extends AuthCoreProvider {
|
||||
private transient final Logger logger = LogManager.getLogger(MergeAuthCoreProvider.class);
|
||||
public List<String> list = new ArrayList<>();
|
||||
private transient List<AuthCoreProvider> providers = new ArrayList<>();
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
for(var core : providers) {
|
||||
var result = core.getUserByUsername(username);
|
||||
if(result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUUID(UUID uuid) {
|
||||
for(var core : providers) {
|
||||
var result = core.getUserByUUID(uuid);
|
||||
if(result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||
throw new OAuthAccessTokenExpired(); // Authorization not supported
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException {
|
||||
throw new AuthException("Authorization not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public User checkServer(Client client, String username, String serverID) throws IOException {
|
||||
for(var core : providers) {
|
||||
var result = core.checkServer(client, username, serverID);
|
||||
if(result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException {
|
||||
return false; // Authorization not supported
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
for(var e : list) {
|
||||
var pair = server.config.auth.get(e);
|
||||
if(pair != null) {
|
||||
providers.add(pair.core);
|
||||
} else {
|
||||
logger.warn("Provider {} not found", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// Providers closed automatically
|
||||
}
|
||||
}
|
|
@ -23,10 +23,10 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
|||
var rca = pair.isSupport(AuthSupportRemoteClientAccess.class);
|
||||
if (rca != null) {
|
||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName,
|
||||
pair.core.getDetails(client), rca.getClientApiUrl(), rca.getClientApiFeatures()));
|
||||
pair.visible, pair.core.getDetails(client), rca.getClientApiUrl(), rca.getClientApiFeatures()));
|
||||
} else {
|
||||
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName,
|
||||
pair.core.getDetails(client)));
|
||||
pair.visible, pair.core.getDetails(client)));
|
||||
}
|
||||
}
|
||||
sendResult(new GetAvailabilityAuthRequestEvent(list));
|
||||
|
|
|
@ -179,7 +179,7 @@ public static void applyBasicOfflineProcessors(OfflineRequestService service) {
|
|||
service.registerRequestProcessor(GetAvailabilityAuthRequest.class, (r) -> {
|
||||
List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> details = new ArrayList<>();
|
||||
details.add(new AuthLoginOnlyDetails());
|
||||
GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability("offline", "Offline Mode", details);
|
||||
GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability("offline", "Offline Mode", true, details);
|
||||
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>(1);
|
||||
list.add(authAvailability);
|
||||
return new GetAvailabilityAuthRequestEvent(list);
|
||||
|
|
|
@ -45,18 +45,23 @@ public static class AuthAvailability {
|
|||
public String name;
|
||||
@LauncherNetworkAPI
|
||||
public String displayName;
|
||||
|
||||
@LauncherNetworkAPI
|
||||
public boolean visible;
|
||||
@LauncherNetworkAPI
|
||||
public String apiUrl;
|
||||
@LauncherNetworkAPI
|
||||
public List<String> apiFeatures;
|
||||
|
||||
public AuthAvailability(String name, String displayName, List<AuthAvailabilityDetails> details) {
|
||||
public AuthAvailability(String name, String displayName, boolean visible, List<AuthAvailabilityDetails> details) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.visible = visible;
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public AuthAvailability(String name, String displayName, List<AuthAvailabilityDetails> details, String apiUrl, List<String> apiFeatures) {
|
||||
public AuthAvailability(String name, String displayName, boolean visible, List<AuthAvailabilityDetails> details, String apiUrl, List<String> apiFeatures) {
|
||||
this.visible = visible;
|
||||
this.details = details;
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
|
|
Loading…
Reference in a new issue