Add UuidUtils#parseUuid, which is more liberal on what it accepts, and convert most everything to use it
This commit is contained in:
parent
527f465c12
commit
035e9fbb81
@ -30,7 +30,7 @@ public final class UserConverter implements Block<Document> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = UUID.fromString(uuidString.replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
UUID uuid = UuidUtils.parseUuid(uuidString);
|
||||||
|
|
||||||
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
||||||
return;
|
return;
|
||||||
|
@ -67,8 +67,7 @@ public final class User {
|
|||||||
|
|
||||||
public static void findById(String id, SingleResultCallback<User> callback) {
|
public static void findById(String id, SingleResultCallback<User> callback) {
|
||||||
try {
|
try {
|
||||||
UUID uuid = UUID.fromString(id);
|
findById(UuidUtils.parseUuid(id), callback);
|
||||||
findById(uuid, callback);
|
|
||||||
} catch (NullPointerException | IllegalArgumentException ignored) { // from UUID parsing
|
} catch (NullPointerException | IllegalArgumentException ignored) { // from UUID parsing
|
||||||
callback.onResult(null, null); // We don't pass in the exception, we just pretend we couldn't find them.
|
callback.onResult(null, null); // We don't pass in the exception, we just pretend we couldn't find them.
|
||||||
}
|
}
|
||||||
@ -428,7 +427,15 @@ public final class User {
|
|||||||
|
|
||||||
public void checkTotpAuthorization(int code, String ip, SingleResultCallback<TotpAuthorizationResult> callback) {
|
public void checkTotpAuthorization(int code, String ip, SingleResultCallback<TotpAuthorizationResult> callback) {
|
||||||
if (totpSecret == null) {
|
if (totpSecret == null) {
|
||||||
callback.onResult(TotpAuthorizationResult.AUTHORIZED_NOT_SET, null);
|
hasPermissionAnywhere(Permissions.REQUIRE_TOTP_CODE, (totpRequired, error) -> {
|
||||||
|
if (error != null) {
|
||||||
|
callback.onResult(null, error);
|
||||||
|
} else {
|
||||||
|
TotpAuthorizationResult result = totpRequired ? TotpAuthorizationResult.NOT_AUTHORIZED_NOT_SET : TotpAuthorizationResult.AUTHORIZED_NOT_SET;
|
||||||
|
callback.onResult(result, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.AccessToken;
|
import net.frozenorb.apiv3.model.AccessToken;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ public final class DELETEAccessTokensId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_DELETE, ImmutableMap.of("accessTokenId", accessToken.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.ACCESS_TOKEN_DELETE, ImmutableMap.of("accessTokenId", accessToken.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.AuditLogEntry;
|
import net.frozenorb.apiv3.model.AuditLogEntry;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ public final class DELETEAuditLogId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("revertedBy")) {
|
if (requestBody.containsKey("revertedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("revertedBy")), requestBody.getString("revertedByIp"), ctx, AuditLogActionType.AUDIT_LOG_REVERT, ImmutableMap.of("auditLogEntryId", auditLogEntry.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("revertedBy")), requestBody.getString("revertedByIp"), ctx, AuditLogActionType.AUDIT_LOG_REVERT, ImmutableMap.of("auditLogEntryId", auditLogEntry.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.BannedAsn;
|
import net.frozenorb.apiv3.model.BannedAsn;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public final class DELETEBannedAsnsId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_ASN_DELETE, ImmutableMap.of("bannedAsnId", bannedAsn.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_ASN_DELETE, ImmutableMap.of("bannedAsnId", bannedAsn.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.BannedAsn;
|
import net.frozenorb.apiv3.model.BannedAsn;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTBannedAsns implements Handler<RoutingContext> {
|
public final class POSTBannedAsns implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ public final class POSTBannedAsns implements Handler<RoutingContext> {
|
|||||||
callback.get();
|
callback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_ASN_CREATE, ImmutableMap.of("bannedAsnId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_ASN_CREATE, ImmutableMap.of("bannedAsnId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.BannedCellCarrier;
|
import net.frozenorb.apiv3.model.BannedCellCarrier;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEBannedCellCarriersId implements Handler<RoutingContext> {
|
public final class DELETEBannedCellCarriersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public final class DELETEBannedCellCarriersId implements Handler<RoutingContext>
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_DELETE, ImmutableMap.of("bannedCellCarrierId", bannedCellCarrier.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_DELETE, ImmutableMap.of("bannedCellCarrierId", bannedCellCarrier.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.BannedCellCarrier;
|
import net.frozenorb.apiv3.model.BannedCellCarrier;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ public final class POSTBannedCellCarriers implements Handler<RoutingContext> {
|
|||||||
callback.get();
|
callback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_CREATE, ImmutableMap.of("bannedCellCarrierId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.BANNED_CALL_CARRIER_CREATE, ImmutableMap.of("bannedCellCarrierId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.NotificationTemplate;
|
import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETENotificationTemplatesId implements Handler<RoutingContext> {
|
public final class DELETENotificationTemplatesId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ public final class DELETENotificationTemplatesId implements Handler<RoutingConte
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_DELETE, ImmutableMap.of("notificationTemplateId", notificationTemplate.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_DELETE, ImmutableMap.of("notificationTemplateId", notificationTemplate.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.NotificationTemplate;
|
import net.frozenorb.apiv3.model.NotificationTemplate;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
|
public final class POSTNotificationTemplates implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ public final class POSTNotificationTemplates implements Handler<RoutingContext>
|
|||||||
callback.get();
|
callback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_CREATE, ImmutableMap.of("notificationTemplateId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.NOTIFICATION_TEMPLATE_CREATE, ImmutableMap.of("notificationTemplateId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.Rank;
|
import net.frozenorb.apiv3.model.Rank;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETERanksId implements Handler<RoutingContext> {
|
public final class DELETERanksId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public final class DELETERanksId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.RANK_DELETE, ImmutableMap.of("rankId", rank.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.RANK_DELETE, ImmutableMap.of("rankId", rank.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.Rank;
|
import net.frozenorb.apiv3.model.Rank;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTRanks implements Handler<RoutingContext> {
|
public final class POSTRanks implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ public final class POSTRanks implements Handler<RoutingContext> {
|
|||||||
callback.get();
|
callback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.RANK_CREATE, ImmutableMap.of("rankId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.RANK_CREATE, ImmutableMap.of("rankId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.ServerGroup;
|
import net.frozenorb.apiv3.model.ServerGroup;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public final class DELETEServerGroupsId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("emovedBy")), requestBody.getString("emovedByIp"), ctx, AuditLogActionType.SERVER_GROUP_DELETE, ImmutableMap.of("serverGroupId", serverGroup.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("emovedBy")), requestBody.getString("emovedByIp"), ctx, AuditLogActionType.SERVER_GROUP_DELETE, ImmutableMap.of("serverGroupId", serverGroup.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType;
|
|||||||
import net.frozenorb.apiv3.model.ServerGroup;
|
import net.frozenorb.apiv3.model.ServerGroup;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTServerGroups implements Handler<RoutingContext> {
|
public final class POSTServerGroups implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ public final class POSTServerGroups implements Handler<RoutingContext> {
|
|||||||
callback.get();
|
callback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_GROUP_CREATE, ImmutableMap.of("serverGroupId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_GROUP_CREATE, ImmutableMap.of("serverGroupId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,8 +13,7 @@ import net.frozenorb.apiv3.model.AccessToken;
|
|||||||
import net.frozenorb.apiv3.model.Server;
|
import net.frozenorb.apiv3.model.Server;
|
||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class DELETEServersId implements Handler<RoutingContext> {
|
public final class DELETEServersId implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ public final class DELETEServersId implements Handler<RoutingContext> {
|
|||||||
JsonObject requestBody = ctx.getBodyAsJson();
|
JsonObject requestBody = ctx.getBodyAsJson();
|
||||||
|
|
||||||
if (requestBody.containsKey("removedBy")) {
|
if (requestBody.containsKey("removedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.SERVER_DELETE, ImmutableMap.of("serverId", server.getId()), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("removedBy")), requestBody.getString("removedByIp"), ctx, AuditLogActionType.SERVER_DELETE, ImmutableMap.of("serverId", server.getId()), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,8 +13,7 @@ import net.frozenorb.apiv3.model.ServerGroup;
|
|||||||
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
import net.frozenorb.apiv3.unsorted.BlockingCallback;
|
||||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||||
import net.frozenorb.apiv3.util.IpUtils;
|
import net.frozenorb.apiv3.util.IpUtils;
|
||||||
|
import net.frozenorb.apiv3.util.UuidUtils;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public final class POSTServers implements Handler<RoutingContext> {
|
public final class POSTServers implements Handler<RoutingContext> {
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public final class POSTServers implements Handler<RoutingContext> {
|
|||||||
insertAccessTokenCallback.get();
|
insertAccessTokenCallback.get();
|
||||||
|
|
||||||
if (requestBody.containsKey("addedBy")) {
|
if (requestBody.containsKey("addedBy")) {
|
||||||
AuditLog.log(UUID.fromString(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_CREATE, ImmutableMap.of("serverId", id), (ignored, error) -> {
|
AuditLog.log(UuidUtils.parseUuid(requestBody.getString("addedBy")), requestBody.getString("addedByIp"), ctx, AuditLogActionType.SERVER_CREATE, ImmutableMap.of("serverId", id), (ignored, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
ErrorUtils.respondInternalError(ctx, error);
|
ErrorUtils.respondInternalError(ctx, error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.frozenorb.apiv3.route.users;
|
package net.frozenorb.apiv3.route.users;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mongodb.client.result.UpdateResult;
|
import com.mongodb.client.result.UpdateResult;
|
||||||
import io.vertx.core.Handler;
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
@ -20,7 +21,7 @@ import java.util.UUID;
|
|||||||
public final class POSTUsersIdLogin implements Handler<RoutingContext> {
|
public final class POSTUsersIdLogin implements Handler<RoutingContext> {
|
||||||
|
|
||||||
public void handle(RoutingContext ctx) {
|
public void handle(RoutingContext ctx) {
|
||||||
UUID uuid = UUID.fromString(ctx.request().getParam("userId"));
|
UUID uuid = UuidUtils.parseUuid(ctx.request().getParam("userId"));
|
||||||
|
|
||||||
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
if (!UuidUtils.isAcceptableUuid(uuid)) {
|
||||||
ErrorUtils.respondInvalidInput(ctx, "UUID \"" + uuid + "\" is not valid - must be version 4 UUID.");
|
ErrorUtils.respondInvalidInput(ctx, "UUID \"" + uuid + "\" is not valid - must be version 4 UUID.");
|
||||||
@ -36,7 +37,7 @@ public final class POSTUsersIdLogin implements Handler<RoutingContext> {
|
|||||||
Actor actor = ctx.get("actor");
|
Actor actor = ctx.get("actor");
|
||||||
|
|
||||||
if (actor.getType() != ActorType.SERVER) {
|
if (actor.getType() != ActorType.SERVER) {
|
||||||
ErrorUtils.respondGeneric(ctx, 403, "This action can only be performed when requested by a server.");
|
ErrorUtils.respondOther(ctx, 403, "This action can only be performed when requested by a server.", "serverOnly", ImmutableMap.of());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,4 +11,14 @@ public class UuidUtils {
|
|||||||
return uuid.version() == 4;
|
return uuid.version() == 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UUID parseUuid(String input) {
|
||||||
|
if (input.length() == 36) {
|
||||||
|
return UUID.fromString(input);
|
||||||
|
} else if (input.length() == 32) {
|
||||||
|
return UUID.fromString(input.replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid UUID string: " + input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user