diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java b/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java index dbc2623..49fe2b9 100644 --- a/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java +++ b/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java @@ -30,7 +30,7 @@ public final class UserConverter implements Block { 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)) { return; diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index 7e9ad00..28fc690 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -67,8 +67,7 @@ public final class User { public static void findById(String id, SingleResultCallback callback) { try { - UUID uuid = UUID.fromString(id); - findById(uuid, callback); + findById(UuidUtils.parseUuid(id), callback); } 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. } @@ -428,7 +427,15 @@ public final class User { public void checkTotpAuthorization(int code, String ip, SingleResultCallback callback) { 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; } diff --git a/src/main/java/net/frozenorb/apiv3/route/accessTokens/DELETEAccessTokensId.java b/src/main/java/net/frozenorb/apiv3/route/accessTokens/DELETEAccessTokensId.java index 73968a6..94bf671 100644 --- a/src/main/java/net/frozenorb/apiv3/route/accessTokens/DELETEAccessTokensId.java +++ b/src/main/java/net/frozenorb/apiv3/route/accessTokens/DELETEAccessTokensId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.AccessToken; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEAccessTokensId implements Handler { @@ -33,7 +32,7 @@ public final class DELETEAccessTokensId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/auditLog/DELETEAuditLogId.java b/src/main/java/net/frozenorb/apiv3/route/auditLog/DELETEAuditLogId.java index 25403d5..9eb5ea3 100644 --- a/src/main/java/net/frozenorb/apiv3/route/auditLog/DELETEAuditLogId.java +++ b/src/main/java/net/frozenorb/apiv3/route/auditLog/DELETEAuditLogId.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.AuditLogEntry; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEAuditLogId implements Handler { @@ -37,7 +36,7 @@ public final class DELETEAuditLogId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/DELETEBannedAsnsId.java b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/DELETEBannedAsnsId.java index f9bf418..6231e48 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/DELETEBannedAsnsId.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/DELETEBannedAsnsId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.BannedAsn; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEBannedAsnsId implements Handler { @@ -31,7 +30,7 @@ public final class DELETEBannedAsnsId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java index d20a828..1e56dbe 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedAsns/POSTBannedAsns.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.BannedAsn; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTBannedAsns implements Handler { @@ -26,7 +25,7 @@ public final class POSTBannedAsns implements Handler { callback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/DELETEBannedCellCarriersId.java b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/DELETEBannedCellCarriersId.java index 0ca4e84..f0c56d5 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/DELETEBannedCellCarriersId.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/DELETEBannedCellCarriersId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.BannedCellCarrier; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEBannedCellCarriersId implements Handler { @@ -31,7 +30,7 @@ public final class DELETEBannedCellCarriersId implements Handler JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java index 6fbcf5c..fe7ece0 100644 --- a/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java +++ b/src/main/java/net/frozenorb/apiv3/route/bannedCellCarriers/POSTBannedCellCarriers.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.BannedCellCarrier; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTBannedCellCarriers implements Handler { @@ -26,7 +25,7 @@ public final class POSTBannedCellCarriers implements Handler { callback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/DELETENotificationTemplatesId.java b/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/DELETENotificationTemplatesId.java index 65fa5d0..dc5cc67 100644 --- a/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/DELETENotificationTemplatesId.java +++ b/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/DELETENotificationTemplatesId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.NotificationTemplate; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETENotificationTemplatesId implements Handler { @@ -33,7 +32,7 @@ public final class DELETENotificationTemplatesId implements Handler { + 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/POSTNotificationTemplates.java b/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/POSTNotificationTemplates.java index ead428f..0a3db2d 100644 --- a/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/POSTNotificationTemplates.java +++ b/src/main/java/net/frozenorb/apiv3/route/notificationTemplates/POSTNotificationTemplates.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.NotificationTemplate; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTNotificationTemplates implements Handler { @@ -27,7 +26,7 @@ public final class POSTNotificationTemplates implements Handler callback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/ranks/DELETERanksId.java b/src/main/java/net/frozenorb/apiv3/route/ranks/DELETERanksId.java index 9bef8dd..a126901 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ranks/DELETERanksId.java +++ b/src/main/java/net/frozenorb/apiv3/route/ranks/DELETERanksId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.Rank; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETERanksId implements Handler { @@ -31,7 +30,7 @@ public final class DELETERanksId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java index 75b1740..8fc808f 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java +++ b/src/main/java/net/frozenorb/apiv3/route/ranks/POSTRanks.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.Rank; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTRanks implements Handler { @@ -32,7 +31,7 @@ public final class POSTRanks implements Handler { callback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/serverGroups/DELETEServerGroupsId.java b/src/main/java/net/frozenorb/apiv3/route/serverGroups/DELETEServerGroupsId.java index 8c14116..66cc8c7 100644 --- a/src/main/java/net/frozenorb/apiv3/route/serverGroups/DELETEServerGroupsId.java +++ b/src/main/java/net/frozenorb/apiv3/route/serverGroups/DELETEServerGroupsId.java @@ -11,8 +11,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.ServerGroup; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEServerGroupsId implements Handler { @@ -31,7 +30,7 @@ public final class DELETEServerGroupsId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/serverGroups/POSTServerGroups.java b/src/main/java/net/frozenorb/apiv3/route/serverGroups/POSTServerGroups.java index 0d70c4a..1c897f6 100644 --- a/src/main/java/net/frozenorb/apiv3/route/serverGroups/POSTServerGroups.java +++ b/src/main/java/net/frozenorb/apiv3/route/serverGroups/POSTServerGroups.java @@ -10,8 +10,7 @@ import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.model.ServerGroup; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTServerGroups implements Handler { @@ -26,7 +25,7 @@ public final class POSTServerGroups implements Handler { callback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/servers/DELETEServersId.java b/src/main/java/net/frozenorb/apiv3/route/servers/DELETEServersId.java index eb25b8b..18c1833 100644 --- a/src/main/java/net/frozenorb/apiv3/route/servers/DELETEServersId.java +++ b/src/main/java/net/frozenorb/apiv3/route/servers/DELETEServersId.java @@ -13,8 +13,7 @@ import net.frozenorb.apiv3.model.AccessToken; import net.frozenorb.apiv3.model.Server; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class DELETEServersId implements Handler { @@ -45,7 +44,7 @@ public final class DELETEServersId implements Handler { JsonObject requestBody = ctx.getBodyAsJson(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/servers/POSTServers.java b/src/main/java/net/frozenorb/apiv3/route/servers/POSTServers.java index ffcb96b..0ce0de9 100644 --- a/src/main/java/net/frozenorb/apiv3/route/servers/POSTServers.java +++ b/src/main/java/net/frozenorb/apiv3/route/servers/POSTServers.java @@ -13,8 +13,7 @@ import net.frozenorb.apiv3.model.ServerGroup; import net.frozenorb.apiv3.unsorted.BlockingCallback; import net.frozenorb.apiv3.util.ErrorUtils; import net.frozenorb.apiv3.util.IpUtils; - -import java.util.UUID; +import net.frozenorb.apiv3.util.UuidUtils; public final class POSTServers implements Handler { @@ -46,7 +45,7 @@ public final class POSTServers implements Handler { insertAccessTokenCallback.get(); 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) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLogin.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLogin.java index de44af0..30a0db0 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLogin.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLogin.java @@ -1,5 +1,6 @@ package net.frozenorb.apiv3.route.users; +import com.google.common.collect.ImmutableMap; import com.mongodb.client.result.UpdateResult; import io.vertx.core.Handler; import io.vertx.core.json.JsonObject; @@ -20,7 +21,7 @@ import java.util.UUID; public final class POSTUsersIdLogin implements Handler { 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)) { ErrorUtils.respondInvalidInput(ctx, "UUID \"" + uuid + "\" is not valid - must be version 4 UUID."); @@ -36,7 +37,7 @@ public final class POSTUsersIdLogin implements Handler { Actor actor = ctx.get("actor"); 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; } diff --git a/src/main/java/net/frozenorb/apiv3/util/UuidUtils.java b/src/main/java/net/frozenorb/apiv3/util/UuidUtils.java index ce0af79..1bc5b54 100644 --- a/src/main/java/net/frozenorb/apiv3/util/UuidUtils.java +++ b/src/main/java/net/frozenorb/apiv3/util/UuidUtils.java @@ -11,4 +11,14 @@ public class UuidUtils { 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); + } + } + } \ No newline at end of file