[FEATURE] Support auth features in API

This commit is contained in:
Gravita 2023-09-24 00:13:32 +07:00
parent e12f2ef897
commit aff254a875
6 changed files with 19 additions and 26 deletions

View file

@ -38,6 +38,10 @@ public static Set<String> getFeatures(Class<?> clazz) {
return list; return list;
} }
public Set<String> getFeatures() {
return features;
}
public static void getFeatures(Class<?> clazz, Set<String> list) { public static void getFeatures(Class<?> clazz, Set<String> list) {
Features features = clazz.getAnnotation(Features.class); Features features = clazz.getAnnotation(Features.class);
if (features != null) { if (features != null) {
@ -73,13 +77,14 @@ public final void init(LaunchServer srv, String name) {
this.name = name; this.name = name;
if (links != null) link(srv); if (links != null) link(srv);
core.init(srv); core.init(srv);
features = new HashSet<>();
getFeatures(core.getClass(), features);
if(mixes != null) { if(mixes != null) {
for(var m : mixes.values()) { for(var m : mixes.values()) {
m.init(srv, core); m.init(srv, core);
getFeatures(m.getClass(), features);
} }
} }
features = new HashSet<>();
getFeatures(core.getClass(), features);
} }
public final void link(LaunchServer srv) { public final void link(LaunchServer srv) {

View file

@ -1,10 +1,11 @@
package pro.gravit.launchserver.auth.core.interfaces.provider; package pro.gravit.launchserver.auth.core.interfaces.provider;
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.events.request.GetAssetUploadInfoRequestEvent;
import pro.gravit.launchserver.auth.Feature; import pro.gravit.launchserver.auth.Feature;
import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.User;
@Feature("assetupload") @Feature(GetAssetUploadInfoRequestEvent.FEATURE_NAME)
public interface AuthSupportAssetUpload { public interface AuthSupportAssetUpload {
String getAssetUploadUrl(String name, User user); String getAssetUploadUrl(String name, User user);

View file

@ -20,14 +20,8 @@ public String getType() {
public void execute(ChannelHandlerContext ctx, Client client) { public void execute(ChannelHandlerContext ctx, Client client) {
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>(); List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
for (AuthProviderPair pair : server.config.auth.values()) { for (AuthProviderPair pair : server.config.auth.values()) {
var rca = pair.isSupport(AuthSupportRemoteClientAccess.class); list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.core.getDetails(client), pair.name, pair.displayName,
if (rca != null) { pair.visible, pair.getFeatures()));
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName,
pair.visible, pair.core.getDetails(client), rca.getClientApiUrl(), rca.getClientApiFeatures()));
} else {
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName,
pair.visible, pair.core.getDetails(client)));
}
} }
sendResult(new GetAvailabilityAuthRequestEvent(list)); sendResult(new GetAvailabilityAuthRequestEvent(list));
} }

View file

@ -3,6 +3,7 @@
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
public class GetAssetUploadInfoRequestEvent extends RequestEvent { public class GetAssetUploadInfoRequestEvent extends RequestEvent {
public static final String FEATURE_NAME = "assetupload";
public String url; public String url;
public AuthRequestEvent.OAuthRequestEvent token; public AuthRequestEvent.OAuthRequestEvent token;

View file

@ -5,6 +5,7 @@
import pro.gravit.utils.TypeSerializeInterface; import pro.gravit.utils.TypeSerializeInterface;
import java.util.List; import java.util.List;
import java.util.Set;
public class GetAvailabilityAuthRequestEvent extends RequestEvent { public class GetAvailabilityAuthRequestEvent extends RequestEvent {
@LauncherNetworkAPI @LauncherNetworkAPI
@ -49,24 +50,14 @@ public static class AuthAvailability {
@LauncherNetworkAPI @LauncherNetworkAPI
public boolean visible; public boolean visible;
@LauncherNetworkAPI @LauncherNetworkAPI
public String apiUrl; public Set<String> features;
@LauncherNetworkAPI
public List<String> apiFeatures;
public AuthAvailability(String name, String displayName, boolean visible, List<AuthAvailabilityDetails> details) { public AuthAvailability(List<AuthAvailabilityDetails> details, String name, String displayName, boolean visible, Set<String> features) {
this.name = name;
this.displayName = displayName;
this.visible = visible;
this.details = details;
}
public AuthAvailability(String name, String displayName, boolean visible, List<AuthAvailabilityDetails> details, String apiUrl, List<String> apiFeatures) {
this.visible = visible;
this.details = details; this.details = details;
this.name = name; this.name = name;
this.displayName = displayName; this.displayName = displayName;
this.apiUrl = apiUrl; this.visible = visible;
this.apiFeatures = apiFeatures; this.features = features;
} }
} }
} }

View file

@ -27,6 +27,7 @@
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
public class ClientLauncherMethods { public class ClientLauncherMethods {
@ -123,7 +124,7 @@ public static void applyBasicOfflineProcessors(OfflineRequestService service) {
service.registerRequestProcessor(GetAvailabilityAuthRequest.class, (r) -> { service.registerRequestProcessor(GetAvailabilityAuthRequest.class, (r) -> {
List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> details = new ArrayList<>(); List<GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails> details = new ArrayList<>();
details.add(new AuthLoginOnlyDetails()); details.add(new AuthLoginOnlyDetails());
GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability("offline", "Offline Mode", true, details); GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability(details, "offline", "Offline Mode", true, new HashSet<>());
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>(1); List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>(1);
list.add(authAvailability); list.add(authAvailability);
return new GetAvailabilityAuthRequestEvent(list); return new GetAvailabilityAuthRequestEvent(list);