Add scope flag to GET /dumps/grant to limit the scope of returned grants
This commit is contained in:
parent
96c55ea6c8
commit
256d12c1d4
@ -6,10 +6,9 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import io.vertx.core.Handler;
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
import io.vertx.ext.web.RoutingContext;
|
||||||
import net.frozenorb.apiv3.APIv3;
|
import net.frozenorb.apiv3.APIv3;
|
||||||
import net.frozenorb.apiv3.model.Grant;
|
import net.frozenorb.apiv3.actor.Actor;
|
||||||
import net.frozenorb.apiv3.model.IpBan;
|
import net.frozenorb.apiv3.actor.ActorType;
|
||||||
import net.frozenorb.apiv3.model.IpIntel;
|
import net.frozenorb.apiv3.model.*;
|
||||||
import net.frozenorb.apiv3.model.Punishment;
|
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
import net.frozenorb.apiv3.util.GeoJsonPoint;
|
import net.frozenorb.apiv3.util.GeoJsonPoint;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
|||||||
private static List<UUID> banCache = ImmutableList.of();
|
private static List<UUID> banCache = ImmutableList.of();
|
||||||
private static List<UUID> blacklistCache = ImmutableList.of();
|
private static List<UUID> blacklistCache = ImmutableList.of();
|
||||||
private static List<String> ipBanCache = ImmutableList.of();
|
private static List<String> ipBanCache = ImmutableList.of();
|
||||||
private static Map<String, List<UUID>> grantCache = ImmutableMap.of();
|
private static Map<String, Map<String, List<UUID>>> grantCache = ImmutableMap.of();
|
||||||
private static Map<String, GeoJsonPoint> ipIntelCache = ImmutableMap.of();
|
private static Map<String, GeoJsonPoint> ipIntelCache = ImmutableMap.of();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -66,22 +65,33 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<UUID>> grantCache = new HashMap<>();
|
Map<String, Map<String, List<UUID>>> grantCache = new HashMap<>();
|
||||||
|
|
||||||
|
for (ServerGroup serverGroup : ServerGroup.findAll()) {
|
||||||
|
grantCache.put(serverGroup.getId().toLowerCase(), new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
for (Grant grant : grants) {
|
for (Grant grant : grants) {
|
||||||
if (!grant.isActive()) {
|
if (!grant.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UUID> users = grantCache.get(grant.getRank());
|
for (ServerGroup serverGroup : ServerGroup.findAll()) {
|
||||||
|
if (!serverGroup.getId().equals(ServerGroup.DEFAULT_GROUP_ID) && !grant.appliesOn(serverGroup)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<UUID>> serverGroupGrantDump = grantCache.get(serverGroup.getId().toLowerCase());
|
||||||
|
List<UUID> users = serverGroupGrantDump.get(grant.getRank());
|
||||||
|
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
users = new LinkedList<>();
|
users = new LinkedList<>();
|
||||||
grantCache.put(grant.getRank(), users);
|
serverGroupGrantDump.put(grant.getRank(), users);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.add(grant.getUser());
|
users.add(grant.getUser());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GETDumpsType.grantCache = grantCache;
|
GETDumpsType.grantCache = grantCache;
|
||||||
});
|
});
|
||||||
@ -148,7 +158,26 @@ public final class GETDumpsType implements Handler<RoutingContext> {
|
|||||||
APIv3.respondJson(ctx, 200, ipBanCache);
|
APIv3.respondJson(ctx, 200, ipBanCache);
|
||||||
return;
|
return;
|
||||||
case "grant":
|
case "grant":
|
||||||
APIv3.respondJson(ctx, 200, grantCache);
|
String serverGroup = ServerGroup.DEFAULT_GROUP_ID;
|
||||||
|
String customScope = ctx.request().getParam("scope");
|
||||||
|
|
||||||
|
if (customScope != null) {
|
||||||
|
if (customScope.equalsIgnoreCase("me")) {
|
||||||
|
Actor actor = ctx.get("actor");
|
||||||
|
|
||||||
|
if (actor.getType() != ActorType.SERVER) {
|
||||||
|
ErrorUtils.respondOther(ctx, 403, "This action can only be performed when requested by a server.", "serverOnly", ImmutableMap.of());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server actorServer = Server.findById(actor.getName());
|
||||||
|
serverGroup = actorServer.getServerGroup();
|
||||||
|
} else {
|
||||||
|
serverGroup = customScope;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
APIv3.respondJson(ctx, 200, grantCache.get(serverGroup.toLowerCase()));
|
||||||
return;
|
return;
|
||||||
case "ipintel":
|
case "ipintel":
|
||||||
APIv3.respondJson(ctx, 200, ipIntelCache.values());
|
APIv3.respondJson(ctx, 200, ipIntelCache.values());
|
||||||
|
Loading…
Reference in New Issue
Block a user