Refactor package names, add ip bans

This commit is contained in:
Colin McDonald 2016-06-16 10:29:33 -04:00
parent 7018a3c5e2
commit 78762262c7
107 changed files with 630 additions and 538 deletions

View File

@ -10,4 +10,4 @@ http.port=80
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
bugsnag.apiKey=0e47fba8b825416b7cbc839066184509
auth.websiteApiKey=RVbp4hY6sCFVaf
auth.bungeeCordApiKey=6d9cf76dc9f0d23
auth.bungeeApiKey=6d9cf76dc9f0d23

View File

@ -33,34 +33,35 @@ import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.handlers.ActorAttributeHandler;
import net.frozenorb.apiv3.handlers.AuthorizationHandler;
import net.frozenorb.apiv3.routes.GETDump;
import net.frozenorb.apiv3.routes.GETWhoAmI;
import net.frozenorb.apiv3.routes.POSTMetrics;
import net.frozenorb.apiv3.routes.announcements.GETAnnouncements;
import net.frozenorb.apiv3.routes.announcements.PUTAnnouncements;
import net.frozenorb.apiv3.routes.auditLog.GETAuditLog;
import net.frozenorb.apiv3.routes.auditLog.POSTUserAuditLogEntry;
import net.frozenorb.apiv3.routes.chatFilterList.GETChatFilterList;
import net.frozenorb.apiv3.routes.grants.*;
import net.frozenorb.apiv3.routes.ipBans.*;
import net.frozenorb.apiv3.routes.ipLog.GETUserIpLog;
import net.frozenorb.apiv3.routes.notificationTemplates.DELETENotificationTemplate;
import net.frozenorb.apiv3.routes.notificationTemplates.GETNotificationTemplate;
import net.frozenorb.apiv3.routes.notificationTemplates.GETNotificationTemplates;
import net.frozenorb.apiv3.routes.notificationTemplates.POSTNotificationTemplate;
import net.frozenorb.apiv3.routes.punishments.*;
import net.frozenorb.apiv3.routes.ranks.DELETERank;
import net.frozenorb.apiv3.routes.ranks.GETRank;
import net.frozenorb.apiv3.routes.ranks.GETRanks;
import net.frozenorb.apiv3.routes.ranks.POSTRank;
import net.frozenorb.apiv3.routes.serverGroups.DELETEServerGroup;
import net.frozenorb.apiv3.routes.serverGroups.GETServerGroup;
import net.frozenorb.apiv3.routes.serverGroups.GETServerGroups;
import net.frozenorb.apiv3.routes.serverGroups.POSTServerGroup;
import net.frozenorb.apiv3.routes.servers.*;
import net.frozenorb.apiv3.routes.users.*;
import net.frozenorb.apiv3.dataImport.V2Importer;
import net.frozenorb.apiv3.handler.ActorAttributeHandler;
import net.frozenorb.apiv3.handler.AuthorizationHandler;
import net.frozenorb.apiv3.route.GETDump;
import net.frozenorb.apiv3.route.GETWhoAmI;
import net.frozenorb.apiv3.route.POSTMetrics;
import net.frozenorb.apiv3.route.announcements.GETAnnouncements;
import net.frozenorb.apiv3.route.announcements.PUTAnnouncements;
import net.frozenorb.apiv3.route.auditLog.GETAuditLog;
import net.frozenorb.apiv3.route.auditLog.POSTUserAuditLogEntry;
import net.frozenorb.apiv3.route.chatFilterList.GETChatFilterList;
import net.frozenorb.apiv3.route.grants.*;
import net.frozenorb.apiv3.route.ipBans.*;
import net.frozenorb.apiv3.route.ipLog.GETUserIpLog;
import net.frozenorb.apiv3.route.notificationTemplates.DELETENotificationTemplate;
import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplate;
import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplates;
import net.frozenorb.apiv3.route.notificationTemplates.POSTNotificationTemplate;
import net.frozenorb.apiv3.route.punishments.*;
import net.frozenorb.apiv3.route.ranks.DELETERank;
import net.frozenorb.apiv3.route.ranks.GETRank;
import net.frozenorb.apiv3.route.ranks.GETRanks;
import net.frozenorb.apiv3.route.ranks.POSTRank;
import net.frozenorb.apiv3.route.serverGroups.DELETEServerGroup;
import net.frozenorb.apiv3.route.serverGroups.GETServerGroup;
import net.frozenorb.apiv3.route.serverGroups.GETServerGroups;
import net.frozenorb.apiv3.route.serverGroups.POSTServerGroup;
import net.frozenorb.apiv3.route.servers.*;
import net.frozenorb.apiv3.route.users.*;
import net.frozenorb.apiv3.serialization.gson.DateTypeAdapter;
import net.frozenorb.apiv3.serialization.gson.FollowAnnotationExclusionStrategy;
import net.frozenorb.apiv3.serialization.jackson.UUIDJsonDeserializer;
@ -100,9 +101,9 @@ public final class APIv3 extends AbstractVerticle {
setupHttpServer();
setupHttpClient();
/*V2Converter converter = new V2Converter("mongodb://158.69.126.126", "minehq");
/*V2Importer converter = new V2Importer("mongodb://158.69.126.126", "minehq");
converter.startConversion((ignored, error) -> {
converter.startImport((ignored, error) -> {
if (error != null) {
error.printStackTrace();
}

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.actors;
package net.frozenorb.apiv3.actor;
public interface Actor {

View File

@ -0,0 +1,7 @@
package net.frozenorb.apiv3.actor;
public enum ActorType {
WEBSITE, BUNGEE, SERVER, USER, UNKNOWN
}

View File

@ -0,0 +1,23 @@
package net.frozenorb.apiv3.actor.actors;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
public final class BungeeActor implements Actor {
@Override
public boolean isAuthorized() {
return true;
}
@Override
public String getName() {
return "Bungee";
}
@Override
public ActorType getType() {
return ActorType.BUNGEE;
}
}

View File

@ -1,7 +1,9 @@
package net.frozenorb.apiv3.actors;
package net.frozenorb.apiv3.actor.actors;
import lombok.Getter;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.Server;
public final class ServerActor implements Actor {

View File

@ -1,4 +1,7 @@
package net.frozenorb.apiv3.actors;
package net.frozenorb.apiv3.actor.actors;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
public final class UnknownActor implements Actor {

View File

@ -1,7 +1,9 @@
package net.frozenorb.apiv3.actors;
package net.frozenorb.apiv3.actor.actors;
import lombok.Getter;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.Permissions;
public final class UserActor implements Actor {

View File

@ -1,4 +1,7 @@
package net.frozenorb.apiv3.actors;
package net.frozenorb.apiv3.actor.actors;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
public final class WebsiteActor implements Actor {

View File

@ -1,7 +0,0 @@
package net.frozenorb.apiv3.actors;
public enum ActorType {
WEBSITE, BUNGEECORD, SERVER, USER, UNKNOWN
}

View File

@ -1,20 +0,0 @@
package net.frozenorb.apiv3.actors;
public final class BungeeCordActor implements Actor {
@Override
public boolean isAuthorized() {
return true;
}
@Override
public String getName() {
return "BungeeCord";
}
@Override
public ActorType getType() {
return ActorType.BUNGEECORD;
}
}

View File

@ -3,9 +3,9 @@ package net.frozenorb.apiv3.auditLog;
import com.google.common.collect.ImmutableMap;
import com.mongodb.async.SingleResultCallback;
import lombok.experimental.UtilityClass;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.User;
import java.util.Map;

View File

@ -1,7 +1,7 @@
package net.frozenorb.apiv3.auditLog;
import com.mongodb.async.SingleResultCallback;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.model.AuditLogEntry;
public enum AuditLogActionType {

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.conversion;
package net.frozenorb.apiv3.dataImport;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoClients;
@ -6,6 +6,10 @@ import com.mongodb.async.client.MongoDatabase;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.dataImport.converters.GrantConverter;
import net.frozenorb.apiv3.dataImport.converters.IpLogConverter;
import net.frozenorb.apiv3.dataImport.converters.PunishmentConverter;
import net.frozenorb.apiv3.dataImport.converters.UserConverter;
import org.bson.types.ObjectId;
import java.util.HashMap;
@ -13,18 +17,18 @@ import java.util.Map;
import java.util.UUID;
@Slf4j
public final class V2Converter {
public final class V2Importer {
private MongoDatabase importFrom;
private final MongoDatabase importFrom;
public V2Converter(String mongoIp, String database) {
public V2Importer(String mongoIp, String database) {
importFrom = MongoClients.create(mongoIp).getDatabase(database);
}
public void startConversion(SingleResultCallback<Void> callback) {
Map<ObjectId, UUID> mongoIdToUUID = new HashMap<>();
public void startImport(SingleResultCallback<Void> callback) {
Map<ObjectId, UUID> oidToUniqueId = new HashMap<>();
importFrom.getCollection("user").find().forEach(new UserConverter(mongoIdToUUID), (ignored, error) -> {
importFrom.getCollection("user").find().forEach(new UserConverter(oidToUniqueId), (ignored, error) -> {
if (error != null) {
callback.onResult(null, error);
return;
@ -34,9 +38,9 @@ public final class V2Converter {
Future<Void> grantsFuture = Future.future();
Future<Void> ipLogFuture = Future.future();
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(mongoIdToUUID), new FutureCompatibilityCallback<>(punishmentsFuture));
importFrom.getCollection("grant").find().forEach(new GrantConverter(mongoIdToUUID), new FutureCompatibilityCallback<>(grantsFuture));
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(mongoIdToUUID), new FutureCompatibilityCallback<>(ipLogFuture));
importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new FutureCompatibilityCallback<>(punishmentsFuture));
importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new FutureCompatibilityCallback<>(grantsFuture));
importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new FutureCompatibilityCallback<>(ipLogFuture));
CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> {
if (result.succeeded()) {
@ -50,7 +54,7 @@ public final class V2Converter {
private static class FutureCompatibilityCallback<T> implements SingleResultCallback<T> {
private Future<T> future;
private final Future<T> future;
public FutureCompatibilityCallback(Future<T> future) {
this.future = future;

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.conversion;
package net.frozenorb.apiv3.dataImport.converters;
import com.google.common.collect.ImmutableSet;
import com.mongodb.Block;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.model.Grant;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -15,15 +15,15 @@ import java.util.UUID;
@Slf4j
public final class GrantConverter implements Block<Document> {
private Map<ObjectId, UUID> mongoIdToUUID;
private final Map<ObjectId, UUID> oidToUniqueId;
public GrantConverter(Map<ObjectId, UUID> mongoIdToUUID) {
this.mongoIdToUUID = mongoIdToUUID;
public GrantConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@Override
public void apply(Document grant) {
UUID target = mongoIdToUUID.get(((Map<String, Object>) grant.get("target")).get("$id"));
UUID target = oidToUniqueId.get(((Map<String, Object>) grant.get("target")).get("$id"));
if (target == null) {
return;
@ -46,7 +46,7 @@ public final class GrantConverter implements Block<Document> {
grant.containsKey("scope") ? ImmutableSet.copyOf((Collection<String>) grant.get("scope")) : ImmutableSet.of(),
rank,
grant.getDate("expires"),
grant.containsKey("addedBy") ? mongoIdToUUID.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
grant.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
grant.containsKey("created") ? grant.getDate("created") : new Date(),
null,
null,

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.conversion;
package net.frozenorb.apiv3.dataImport.converters;
import com.mongodb.Block;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.models.IpLogEntry;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.model.IpLogEntry;
import net.frozenorb.apiv3.util.IpUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -14,15 +14,15 @@ import java.util.UUID;
@Slf4j
public final class IpLogConverter implements Block<Document> {
private Map<ObjectId, UUID> mongoIdToUUID;
private final Map<ObjectId, UUID> oidToUniqueId;
public IpLogConverter(Map<ObjectId, UUID> mongoIdToUUID) {
this.mongoIdToUUID = mongoIdToUUID;
public IpLogConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@Override
public void apply(Document ipLogEntry) {
UUID user = mongoIdToUUID.get(((Map<String, Object>) ipLogEntry.get("user")).get("$id"));
UUID user = oidToUniqueId.get(((Map<String, Object>) ipLogEntry.get("user")).get("$id"));
if (user == null || ipLogEntry.getString("ip") == null) {
return;

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.conversion;
package net.frozenorb.apiv3.dataImport.converters;
import com.google.common.collect.ImmutableMap;
import com.mongodb.Block;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.Punishment;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -16,15 +16,15 @@ import java.util.UUID;
@Slf4j
public final class PunishmentConverter implements Block<Document> {
private Map<ObjectId, UUID> mongoIdToUUID;
private final Map<ObjectId, UUID> oidToUniqueId;
public PunishmentConverter(Map<ObjectId, UUID> mongoIdToUUID) {
this.mongoIdToUUID = mongoIdToUUID;
public PunishmentConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@Override
public void apply(Document punishment) {
UUID target = mongoIdToUUID.get(((Map<String, Object>) punishment.get("user")).get("$id"));
UUID target = oidToUniqueId.get(((Map<String, Object>) punishment.get("user")).get("$id"));
if (target == null) {
return;
@ -43,11 +43,11 @@ public final class PunishmentConverter implements Block<Document> {
punishment.getDate("expires"),
punishment.containsKey("meta") ? (punishment.get("meta") instanceof List ? ImmutableMap.of() : (Document) punishment.get("meta")) : ImmutableMap.of(),
null,
punishment.containsKey("addedBy") ? mongoIdToUUID.get(((Map<String, Object>) punishment.get("addedBy")).get("$id")) : null,
punishment.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("addedBy")).get("$id")) : null,
(Date) punishment.getDate("created").clone(),
punishment.containsKey("createdOn") ? String.valueOf(((Map<String, Object>) punishment.get("createdOn")).get("$id")) : "Website",
punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE,
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? mongoIdToUUID.get(((Map<String, Object>) punishment.get("removedBy")).get("$id")) : null) : null,
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map<String, Object>) punishment.get("removedBy")).get("$id")) : null) : null,
punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")) : null,
punishment.containsKey("removedBy") ? punishment.getString("removalReason").toString() : null
);

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.conversion;
package net.frozenorb.apiv3.dataImport.converters;
import com.google.common.collect.ImmutableMap;
import com.mongodb.Block;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.UUIDUtils;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.UUIDUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -14,10 +14,10 @@ import java.util.UUID;
@Slf4j
public final class UserConverter implements Block<Document> {
private Map<ObjectId, UUID> mongoIdToUUID;
private final Map<ObjectId, UUID> oidToUniqueId;
public UserConverter(Map<ObjectId, UUID> mongoIdToUUID) {
this.mongoIdToUUID = mongoIdToUUID;
public UserConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@Override
@ -34,7 +34,7 @@ public final class UserConverter implements Block<Document> {
return;
}
mongoIdToUUID.put(user.getObjectId("_id"), uuid);
oidToUniqueId.put(user.getObjectId("_id"), uuid);
User created = new User(
uuid,

View File

@ -0,0 +1,123 @@
package net.frozenorb.apiv3.handler;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actor.actors.*;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.Base64;
public final class ActorAttributeHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext ctx) {
String authorizationHeader = ctx.request().getHeader("Authorization");
String mhqAuthorizationHeader = ctx.request().getHeader("MHQ-Authorization");
if (authorizationHeader != null) {
processBasicAuthorization(authorizationHeader, ctx);
} else if (mhqAuthorizationHeader != null) {
processMHQAuthorization(mhqAuthorizationHeader, ctx);
} else {
processNoAuthorization(ctx);
}
}
private void processBasicAuthorization(String authHeader, RoutingContext ctx) {
String encodedHeader = authHeader.substring("Basic ".length());
String decodedHeader = new String(Base64.getDecoder().decode(encodedHeader.getBytes()));
String[] splitHeader = decodedHeader.split(":");
if (splitHeader.length != 2) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize.");
return;
}
String username = splitHeader[0];
String password = splitHeader[1];
User.findByLastUsername(username, (user, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
return;
}
if (user != null && user.checkPassword(password)) {
ctx.put("actor", new UserActor(user));
ctx.next();
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + username + ".");
}
});
}
private void processMHQAuthorization(String authHeader, RoutingContext ctx) {
String[] splitHeader = authHeader.split(" ");
if (splitHeader.length < 2) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize.");
return;
}
String type = splitHeader[0];
switch (type.toLowerCase()) {
case "website":
String givenWebsiteKey = splitHeader[1];
String properWebsiteKey = APIv3.getConfig().getProperty("auth.websiteApiKey");
if (givenWebsiteKey.equals(properWebsiteKey)) {
ctx.put("actor", new WebsiteActor());
ctx.next();
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as website.");
}
break;
case "server":
Server server = Server.findById(splitHeader[1]);
if (server == null) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize: Server " + splitHeader[1] + " not found");
return;
}
if (splitHeader.length != 3) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize: Key not provided");
return;
}
String givenServerKey = splitHeader[2];
if (givenServerKey.equals(server.getApiKey())) {
ctx.put("actor", new ServerActor(server));
ctx.next();
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + server.getId() + ".");
}
break;
case "bungee":
String givenBungeeKey = splitHeader[1];
String properBungeeKey = APIv3.getConfig().getProperty("auth.bungeeApiKey");
if (givenBungeeKey.equals(properBungeeKey)) {
ctx.put("actor", new BungeeActor());
ctx.next();
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as bungee.");
}
break;
}
}
public void processNoAuthorization(RoutingContext ctx) {
ctx.put("actor", new UnknownActor());
ctx.next();
}
}

View File

@ -0,0 +1,37 @@
package net.frozenorb.apiv3.handler;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.actor.actors.ServerActor;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class AuthorizationHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext ctx) {
Actor actor = ctx.get("actor");
if (!actor.isAuthorized()) {
ErrorUtils.respondGeneric(ctx, 403, "Please authorize as an approved actor. You're currently authorized as " + actor.getName() + " (" + actor.getType() + ")");
return;
}
if (actor.getType() == ActorType.SERVER) {
Server server = ((ServerActor) actor).getServer();
String[] serverAddress = server.getServerIp().split(":");
String expectedHost = serverAddress[0];
String remoteHost = ctx.request().remoteAddress().host();
if (!expectedHost.equals(remoteHost)) {
ErrorUtils.respondGeneric(ctx, 403, "Failed to authorize: Cannot authorize as " + server.getId() + " from given ip.");
return;
}
}
ctx.next();
}
}

View File

@ -1,110 +0,0 @@
package net.frozenorb.apiv3.handlers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.*;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import java.util.Base64;
public final class ActorAttributeHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext ctx) {
String authorizationHeader = ctx.request().getHeader("Authorization");
String mhqAuthorizationHeader = ctx.request().getHeader("MHQ-Authorization");
if (authorizationHeader != null) {
processBasicAuthorization(authorizationHeader, ctx);
} else if (mhqAuthorizationHeader != null) {
processMHQAuthorization(mhqAuthorizationHeader, ctx);
} else {
processNoAuthorization(ctx);
}
}
// TODO: Cleanup
private void processBasicAuthorization(String authHeader, RoutingContext ctx) {
String encodedHeader = authHeader.substring("Basic ".length());
String decodedHeader = new String(Base64.getDecoder().decode(encodedHeader.getBytes()));
String[] credentials = decodedHeader.split(":");
if (credentials.length == 2) {
User.findByLastUsername(credentials[0], (user, error) -> {
if (error != null) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + credentials[0] + ".");
return;
}
String password = credentials[1];
if (user != null && user.getPassword() != null && user.checkPassword(password)) {
ctx.put("actor", new UserActor(user));
ctx.next();
return;
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + credentials[0] + ".");
return;
}
});
} else {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize as " + credentials[0] + ".");
}
}
// TODO: Cleanup
private void processMHQAuthorization(String authHeader, RoutingContext ctx) {
String[] split = authHeader.split(" ");
if (split.length >= 2) {
String type = split[0];
if (type.equals("Website") && split.length == 2) {
String givenKey = split[1];
String properKey = APIv3.getConfig().getProperty("auth.websiteApiKey");
if (givenKey.equals(properKey)) {
ctx.put("actor", new WebsiteActor());
ctx.next();
return;
}
} else if (type.equals("Server") && split.length == 3) {
Server server = Server.findById(split[1]);
if (server == null) {
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize: Server " + split[1] + " not found");
return;
}
String givenKey = split[2];
String properKey = server.getApiKey();
if (givenKey.equals(properKey)) {
ctx.put("actor", new ServerActor(server));
ctx.next();
return;
}
} else if (type.equals("BungeeCord") && split.length == 2) {
String givenKey = split[1];
String properKey = APIv3.getConfig().getProperty("auth.bungeeCordApiKey");
if (givenKey.equals(properKey)) {
ctx.put("actor", new BungeeCordActor());
ctx.next();
return;
}
}
}
ErrorUtils.respondGeneric(ctx, 401, "Failed to authorize.");
}
public void processNoAuthorization(RoutingContext ctx) {
ctx.put("actor", new UnknownActor());
ctx.next();
}
}

View File

@ -1,21 +0,0 @@
package net.frozenorb.apiv3.handlers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.utils.ErrorUtils;
public final class AuthorizationHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext ctx) {
Actor actor = ctx.get("actor");
if (!actor.isAuthorized()) {
ErrorUtils.respondGeneric(ctx, 403, "Please authorize as an approved actor. You're currently authorized as " + actor.getName() + " (" + actor.getType() + ")");
} else {
ctx.next();
}
}
}

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.google.common.collect.ImmutableMap;
import com.mongodb.async.SingleResultCallback;
@ -7,10 +7,10 @@ import fr.javatic.mongo.jacksonCodec.Entity;
import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import org.bson.types.ObjectId;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.google.common.collect.Collections2;
import com.mongodb.async.SingleResultCallback;
@ -10,7 +10,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import org.bson.types.ObjectId;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
@ -8,11 +8,11 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.utils.TimeUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import net.frozenorb.apiv3.util.TimeUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -158,14 +158,4 @@ public final class IpBan {
callback.get();
}
public void delete(Punishment linkedPunishment) {
this.removedBy = linkedPunishment.getRemovedBy();
this.removedAt = new Date();
this.removalReason = "Linked punishment removed: " + linkedPunishment.getRemovalReason();
BlockingCallback<UpdateResult> callback = new BlockingCallback<>();
ipBansCollection.replaceOne(new Document("_id", id), this, callback);
callback.get();
}
}

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
@ -9,7 +9,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import org.bson.types.ObjectId;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
@ -10,7 +10,7 @@ import lombok.Getter;
import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
@ -8,11 +8,11 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.utils.TimeUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import net.frozenorb.apiv3.util.TimeUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
@ -195,6 +195,14 @@ public final class Punishment {
this.removedAt = new Date();
this.removalReason = reason;
if (linkedIpBanId != null) {
IpBan ipBan = IpBan.findByIdSync(linkedIpBanId);
if (ipBan != null && ipBan.isActive()) {
ipBan.delete(removedBy, "Linked punishment removed: " + reason);
}
}
BlockingCallback<UpdateResult> callback = new BlockingCallback<>();
punishmentsCollection.replaceOne(new Document("_id", id), this, callback);
callback.get();

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
@ -10,7 +10,7 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.Getter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.google.common.collect.ImmutableSet;
import com.mongodb.async.client.MongoCollection;
@ -11,7 +11,7 @@ import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import java.util.*;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.mongodb.async.client.MongoCollection;
import com.mongodb.client.result.DeleteResult;
@ -10,8 +10,8 @@ import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.PermissionUtils;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.PermissionUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import java.util.*;

View File

@ -1,6 +1,5 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Charsets;
@ -22,13 +21,12 @@ import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
import net.frozenorb.apiv3.serialization.jackson.UUIDJsonDeserializer;
import net.frozenorb.apiv3.serialization.jackson.UUIDJsonSerializer;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.MojangUtils;
import net.frozenorb.apiv3.utils.PermissionUtils;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.utils.UUIDUtils;
import net.frozenorb.apiv3.util.MojangUtils;
import net.frozenorb.apiv3.util.PermissionUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import net.frozenorb.apiv3.util.UUIDUtils;
import org.bson.Document;
import java.io.IOException;
import java.util.*;
@Entity
@ -229,7 +227,7 @@ public final class User {
.hashString(input + "$" + id.toString(), Charsets.UTF_8)
.toString();
return hashed.equals(password);
return password != null && hashed.equals(password);
}
public Rank getHighestRankAnywhere() {
@ -291,8 +289,9 @@ public final class User {
return highestRanks;
}
public void getLoginInfo(Server server, SingleResultCallback<Map<String, Object>> callback) {
public void getLoginInfo(Server server, String userIp, SingleResultCallback<Map<String, Object>> callback) {
Future<Iterable<Punishment>> punishmentsFuture = Future.future();
Future<Iterable<IpBan>> ipBansFuture = Future.future();
Future<Iterable<Grant>> grantsFuture = Future.future();
Punishment.findByUserAndType(this, ImmutableSet.of(
@ -307,6 +306,18 @@ public final class User {
}
});
if (userIp != null) {
IpBan.findByIp(userIp, (ipBans, error) -> {
if (error != null) {
ipBansFuture.fail(error);
} else {
ipBansFuture.complete(ipBans);
}
});
} else {
ipBansFuture.complete(ImmutableSet.of());
}
Grant.findByUser(this, (grants, error) -> {
if (error != null) {
grantsFuture.fail(error);
@ -315,12 +326,13 @@ public final class User {
}
});
CompositeFuture.all(punishmentsFuture, grantsFuture).setHandler((result) -> {
CompositeFuture.all(punishmentsFuture, ipBansFuture, grantsFuture).setHandler((result) -> {
if (result.succeeded()) {
Iterable<Punishment> punishments = result.result().result(0);
Iterable<Grant> grants = result.result().result(1);
Iterable<IpBan> ipBans = result.result().result(1);
Iterable<Grant> grants = result.result().result(2);
callback.onResult(createLoginInfo(server, punishments, grants), null);
callback.onResult(createLoginInfo(server, punishments, ipBans, grants), null);
} else {
callback.onResult(null, result.cause());
}
@ -328,9 +340,10 @@ public final class User {
}
// This is only used to help batch requests to mongo
public Map<String, Object> createLoginInfo(Server server, Iterable<Punishment> punishments, Iterable<Grant> grants) {
public Map<String, Object> createLoginInfo(Server server, Iterable<Punishment> punishments, Iterable<IpBan> ipBans, Iterable<Grant> grants) {
Punishment activeMute = null;
Punishment activeBan = null;
IpBan activeIpBan = null;
for (Punishment punishment : punishments) {
if (!punishment.isActive()) {
@ -344,16 +357,37 @@ public final class User {
}
}
for (IpBan ipBan : ipBans) {
if (ipBan.isActive()) {
activeIpBan = ipBan;
break;
}
}
Rank highestRank = getHighestRankScoped(ServerGroup.findById(server.getServerGroup()), grants);
Map<String, Object> access = ImmutableMap.of(
"allowed", true,
"message", "Public server"
);
if (activeBan != null) {
access = ImmutableMap.of(
"allowed", false,
"message", activeBan.getAccessDenialReason(),
"activeBanId", activeBan.getId()
);
} else if (activeIpBan != null) {
access = ImmutableMap.of(
"allowed", false,
"message", activeIpBan.getAccessDenialReason(),
"activeIpBanId", activeIpBan.getId()
);
}
// Generics are weird, yes we have to do this.
ImmutableMap.Builder<String, Object> result = ImmutableMap.<String, Object>builder()
.put("user", this)
.put("access", ImmutableMap.of(
"allowed", activeBan == null,
"message", activeBan == null ? "Public server" : activeBan.getAccessDenialReason(),
"activeBanId", activeBan == null ? "" : activeBan.getId()
))
.put("access", access)
.put("rank", highestRank.getId())
.put("totpSetup", getTotpSecret() != null);

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.models;
package net.frozenorb.apiv3.model;
import com.google.common.collect.ImmutableMap;
import com.mongodb.async.SingleResultCallback;
@ -11,7 +11,7 @@ import lombok.Getter;
import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.SyncUtils;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document;
import org.bson.types.ObjectId;

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes;
package net.frozenorb.apiv3.route;
import com.google.common.collect.ImmutableSet;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.*;
import java.util.concurrent.TimeUnit;

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes;
package net.frozenorb.apiv3.route;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actor.Actor;
public final class GETWhoAmI implements Handler<RoutingContext> {

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes;
package net.frozenorb.apiv3.route;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.announcements;
package net.frozenorb.apiv3.route.announcements;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETAnnouncements implements Handler<RoutingContext> {

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.announcements;
package net.frozenorb.apiv3.route.announcements;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.HashSet;
import java.util.Set;

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.auditLog;
package net.frozenorb.apiv3.route.auditLog;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETAuditLog implements Handler<RoutingContext> {

View File

@ -1,15 +1,15 @@
package net.frozenorb.apiv3.routes.auditLog;
package net.frozenorb.apiv3.route.auditLog;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import org.bson.Document;
public final class POSTUserAuditLogEntry implements Handler<RoutingContext> {

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes.chatFilterList;
package net.frozenorb.apiv3.route.chatFilterList;
import com.google.common.collect.ImmutableList;
import io.vertx.core.Handler;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes.grants;
package net.frozenorb.apiv3.route.grants;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
@ -6,11 +6,11 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEGrant implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.grants;
package net.frozenorb.apiv3.route.grants;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.model.Grant;
public final class GETGrant implements Handler<RoutingContext> {

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.grants;
package net.frozenorb.apiv3.route.grants;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETGrants implements Handler<RoutingContext> {

View File

@ -1,11 +1,11 @@
package net.frozenorb.apiv3.routes.grants;
package net.frozenorb.apiv3.route.grants;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserGrants implements Handler<RoutingContext> {

View File

@ -1,13 +1,13 @@
package net.frozenorb.apiv3.routes.grants;
package net.frozenorb.apiv3.route.grants;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.Rank;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.Date;
import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes.ipBans;
package net.frozenorb.apiv3.route.ipBans;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
@ -6,11 +6,11 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.IpBan;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEIpBan implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.ipBans;
package net.frozenorb.apiv3.route.ipBans;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.IpBan;
import net.frozenorb.apiv3.model.IpBan;
public final class GETIpBan implements Handler<RoutingContext> {

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.ipBans;
package net.frozenorb.apiv3.route.ipBans;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.IpBan;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETIpBans implements Handler<RoutingContext> {

View File

@ -1,12 +1,11 @@
package net.frozenorb.apiv3.routes.ipBans;
package net.frozenorb.apiv3.route.ipBans;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.IpBan;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
public final class GETIpIpBans implements Handler<RoutingContext> {

View File

@ -1,19 +1,14 @@
package net.frozenorb.apiv3.routes.ipBans;
package net.frozenorb.apiv3.route.ipBans;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.IpBan;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.unsorted.Permissions;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import org.bson.Document;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import java.util.Date;
import java.util.Map;
public final class POSTIpIpBan implements Handler<RoutingContext> {

View File

@ -1,11 +1,11 @@
package net.frozenorb.apiv3.routes.ipLog;
package net.frozenorb.apiv3.route.ipLog;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.IpLogEntry;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.IpLogEntry;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserIpLog implements Handler<RoutingContext> {

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.notificationTemplates;
package net.frozenorb.apiv3.route.notificationTemplates;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.NotificationTemplate;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETENotificationTemplate implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.notificationTemplates;
package net.frozenorb.apiv3.route.notificationTemplates;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.model.NotificationTemplate;
public final class GETNotificationTemplate implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.notificationTemplates;
package net.frozenorb.apiv3.route.notificationTemplates;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.model.NotificationTemplate;
public final class GETNotificationTemplates implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.notificationTemplates;
package net.frozenorb.apiv3.route.notificationTemplates;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.model.NotificationTemplate;
public final class POSTNotificationTemplate implements Handler<RoutingContext> {

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.route.notificationTemplates;
public class PUTNotificationTemplate {
}

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
@ -6,11 +6,11 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEPunishment implements Handler<RoutingContext> {

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -7,11 +7,11 @@ import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType;
import net.frozenorb.apiv3.models.AuditLogEntry;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.AuditLogEntry;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEUserPunishment implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.model.Punishment;
public final class GETPunishment implements Handler<RoutingContext> {

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETPunishments implements Handler<RoutingContext> {

View File

@ -1,11 +1,11 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserPunishments implements Handler<RoutingContext> {

View File

@ -1,14 +1,15 @@
package net.frozenorb.apiv3.routes.punishments;
package net.frozenorb.apiv3.route.punishments;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.IpBan;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.Permissions;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document;
import java.util.Date;
@ -72,6 +73,15 @@ public final class POSTUserPunish implements Handler<RoutingContext> {
Punishment punishment = new Punishment(target, reason, type, expiresAt, addedBy, ctx.get("actor"), meta);
String accessDenialReason = punishment.getAccessDenialReason();
String userIp = ctx.request().getParam("userIp");
if (userIp != null) {
IpBan ipBan = new IpBan(userIp, punishment);
ipBan.insert();
punishment.linkIpBan(ipBan);
}
punishment.insert();
APIv3.respondJson(ctx, ImmutableMap.of(

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.ranks;
package net.frozenorb.apiv3.route.ranks;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Rank;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETERank implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.ranks;
package net.frozenorb.apiv3.route.ranks;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.model.Rank;
public final class GETRank implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.ranks;
package net.frozenorb.apiv3.route.ranks;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.model.Rank;
public final class GETRanks implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.ranks;
package net.frozenorb.apiv3.route.ranks;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.model.Rank;
public final class POSTRank implements Handler<RoutingContext> {

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.route.ranks;
public class PUTRank {
}

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.serverGroups;
package net.frozenorb.apiv3.route.serverGroups;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEServerGroup implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.serverGroups;
package net.frozenorb.apiv3.route.serverGroups;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.model.ServerGroup;
public final class GETServerGroup implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.serverGroups;
package net.frozenorb.apiv3.route.serverGroups;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.model.ServerGroup;
public final class GETServerGroups implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.serverGroups;
package net.frozenorb.apiv3.route.serverGroups;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.model.ServerGroup;
public final class POSTServerGroup implements Handler<RoutingContext> {

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.route.serverGroups;
public class PUTServerGroup {
}

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.servers;
package net.frozenorb.apiv3.route.servers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class DELETEServer implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.servers;
package net.frozenorb.apiv3.route.servers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.model.Server;
public final class GETServer implements Handler<RoutingContext> {

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.servers;
package net.frozenorb.apiv3.route.servers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.model.Server;
public final class GETServers implements Handler<RoutingContext> {

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes.servers;
package net.frozenorb.apiv3.route.servers;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import java.math.BigInteger;
import java.util.Random;

View File

@ -1,5 +1,6 @@
package net.frozenorb.apiv3.routes.servers;
package net.frozenorb.apiv3.route.servers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
@ -7,12 +8,12 @@ import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.models.*;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.PermissionUtils;
import net.frozenorb.apiv3.utils.UUIDUtils;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.model.*;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.PermissionUtils;
import net.frozenorb.apiv3.util.UUIDUtils;
import org.bson.Document;
import java.util.*;
@ -126,7 +127,8 @@ public final class POSTServerHeartbeat implements Handler<RoutingContext> {
user.save();
}
response.put(uuid.toString(), user.createLoginInfo(server, punishments.get(uuid), grants.get(uuid)));
// TODO: Provide IPs for ip ban lookup
response.put(uuid.toString(), user.createLoginInfo(server, punishments.get(uuid), ImmutableList.of(), grants.get(uuid)));
}
callback.complete(response);

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.route.servers;
public class PUTServer {
}

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.models.UserMetaEntry;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document;
public final class DELETEUserMeta implements Handler<RoutingContext> {

View File

@ -1,11 +1,11 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.Rank;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.Rank;
import net.frozenorb.apiv3.model.User;
import java.util.*;

View File

@ -1,9 +1,9 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.User;
public final class GETUser implements Handler<RoutingContext> {

View File

@ -1,14 +1,14 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.Grant;
import net.frozenorb.apiv3.models.IpLogEntry;
import net.frozenorb.apiv3.models.Punishment;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.model.IpLogEntry;
import net.frozenorb.apiv3.model.Punishment;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserDetails implements Handler<RoutingContext> {

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.models.UserMetaEntry;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserMeta implements Handler<RoutingContext> {

View File

@ -1,14 +1,14 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.utils.TOTPUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import net.frozenorb.apiv3.util.TOTPUtils;
public final class GETUserRequiresTOTP implements Handler<RoutingContext> {

View File

@ -1,11 +1,11 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public final class GETUserVerifyPassword implements Handler<RoutingContext> {

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.List;
import java.util.concurrent.TimeUnit;

View File

@ -1,10 +1,10 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
public class POSTUserLeave implements Handler<RoutingContext> {

View File

@ -1,17 +1,17 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.actors.Actor;
import net.frozenorb.apiv3.actors.ActorType;
import net.frozenorb.apiv3.actors.ServerActor;
import net.frozenorb.apiv3.models.IpLogEntry;
import net.frozenorb.apiv3.models.Server;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.utils.UUIDUtils;
import net.frozenorb.apiv3.actor.Actor;
import net.frozenorb.apiv3.actor.ActorType;
import net.frozenorb.apiv3.actor.actors.ServerActor;
import net.frozenorb.apiv3.model.IpLogEntry;
import net.frozenorb.apiv3.model.Server;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import net.frozenorb.apiv3.util.UUIDUtils;
import java.util.UUID;
@ -26,10 +26,17 @@ public final class POSTUserLogin implements Handler<RoutingContext> {
}
Actor actor = ctx.get("actor");
Server server;
if (actor.getType() != ActorType.SERVER) {
ErrorUtils.respondServerOnly(ctx);
return;
if (actor.getType() == ActorType.SERVER) {
server = ((ServerActor) actor).getServer();
} else {
server = Server.findById(ctx.request().getParam("server"));
if (server == null) {
ErrorUtils.respondNotFound(ctx, "Server", ctx.request().getParam("server"));
return;
}
}
String username = ctx.request().getParam("username");
@ -68,7 +75,7 @@ public final class POSTUserLogin implements Handler<RoutingContext> {
if (error3 != null) {
ErrorUtils.respondInternalError(ctx, error3);
} else {
finalUser.getLoginInfo(((ServerActor) actor).getServer(), (loginInfo, error4) -> {
finalUser.getLoginInfo(server, userIp, (loginInfo, error4) -> {
if (error4 != null) {
ErrorUtils.respondInternalError(ctx, error4);
} else {

View File

@ -1,13 +1,13 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.NotificationTemplate;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.Notification;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,13 +1,13 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.NotificationTemplate;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.Notification;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import java.math.BigInteger;
import java.util.Date;

View File

@ -1,13 +1,13 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.TOTPUtils;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.TOTPUtils;
public final class POSTUserSetupTOTP implements Handler<RoutingContext> {

View File

@ -1,14 +1,14 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.unsorted.BlockingCallback;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.utils.IpUtils;
import net.frozenorb.apiv3.utils.TOTPUtils;
import net.frozenorb.apiv3.util.ErrorUtils;
import net.frozenorb.apiv3.util.IpUtils;
import net.frozenorb.apiv3.util.TOTPUtils;
import java.util.concurrent.TimeUnit;

View File

@ -1,12 +1,12 @@
package net.frozenorb.apiv3.routes.users;
package net.frozenorb.apiv3.route.users;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.ServerGroup;
import net.frozenorb.apiv3.models.User;
import net.frozenorb.apiv3.models.UserMetaEntry;
import net.frozenorb.apiv3.utils.ErrorUtils;
import net.frozenorb.apiv3.model.ServerGroup;
import net.frozenorb.apiv3.model.User;
import net.frozenorb.apiv3.model.UserMetaEntry;
import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document;
public final class PUTUserMeta implements Handler<RoutingContext> {

View File

@ -1,4 +0,0 @@
package net.frozenorb.apiv3.routes.notificationTemplates;
public class PUTNotificationTemplate {
}

View File

@ -1,4 +0,0 @@
package net.frozenorb.apiv3.routes.ranks;
public class PUTRank {
}

View File

@ -1,4 +0,0 @@
package net.frozenorb.apiv3.routes.serverGroups;
public class PUTServerGroup {
}

View File

@ -1,4 +0,0 @@
package net.frozenorb.apiv3.routes.servers;
public class PUTServer {
}

View File

@ -5,7 +5,7 @@ import com.google.common.net.MediaType;
import com.mongodb.async.SingleResultCallback;
import io.vertx.core.http.HttpHeaders;
import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.models.NotificationTemplate;
import net.frozenorb.apiv3.model.NotificationTemplate;
import org.bson.Document;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package net.frozenorb.apiv3.utils;
package net.frozenorb.apiv3.util;
import com.google.common.collect.ImmutableMap;
import io.vertx.ext.web.RoutingContext;

Some files were not shown because too many files have changed in this diff Show More