Add totp dump type, which returns UUIDs of Users with totp setup

This commit is contained in:
Colin McDonald 2016-11-28 22:25:39 -05:00
parent 6ae09cde9b
commit f4b59cf9b3
3 changed files with 26 additions and 2 deletions

View File

@ -110,7 +110,8 @@ public class MongoConfig {
db.getCollection("users").createIndexes(ImmutableList.of( db.getCollection("users").createIndexes(ImmutableList.of(
new IndexModel(new Document("lastUsername", 1)), new IndexModel(new Document("lastUsername", 1)),
new IndexModel(new Document("lastUsernameLower", 1)), new IndexModel(new Document("lastUsernameLower", 1)),
new IndexModel(new Document("emailToken", 1)) new IndexModel(new Document("emailToken", 1)),
new IndexModel(new Document("totpSecret", 1))
), (a, b) -> {}); ), (a, b) -> {});
db.getCollection("userMeta").createIndexes(ImmutableList.of( db.getCollection("userMeta").createIndexes(ImmutableList.of(
new IndexModel(new Document("user", 1).append("serverGroup", 1)) new IndexModel(new Document("user", 1).append("serverGroup", 1))

View File

@ -92,6 +92,10 @@ public final class User {
usersCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); usersCollection.find().sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }
public static void findAllWithTotpSetup(SingleResultCallback<List<User>> callback) {
usersCollection.find(new Document("totpSecret", new Document("$exists", true))).sort(new Document("lastSeenAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
}
public static void findById(String id, SingleResultCallback<User> callback) { public static void findById(String id, SingleResultCallback<User> callback) {
try { try {
findById(UuidUtils.parseUuid(id), callback); findById(UuidUtils.parseUuid(id), callback);

View File

@ -39,6 +39,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
private final DecimalFormat coordinateFormat = new DecimalFormat("#.#####"); private final DecimalFormat coordinateFormat = new DecimalFormat("#.#####");
private List<UUID> totpCache = ImmutableList.of();
private List<UUID> banCache = ImmutableList.of(); private List<UUID> banCache = ImmutableList.of();
private List<UUID> blacklistCache = ImmutableList.of(); private List<UUID> blacklistCache = ImmutableList.of();
private List<String> ipBanCache = ImmutableList.of(); private List<String> ipBanCache = ImmutableList.of();
@ -48,6 +49,21 @@ public final class GETDumpsType implements Handler<RoutingContext> {
// 5 minutes, can't use TimeUnit expression in annotation // 5 minutes, can't use TimeUnit expression in annotation
@Scheduled(fixedRate = 5 * 60 * 1000) @Scheduled(fixedRate = 5 * 60 * 1000)
public void updateCache() { public void updateCache() {
User.findAllWithTotpSetup((users, error) -> {
if (error != null) {
error.printStackTrace();
return;
}
List<UUID> totpCache = new LinkedList<>();
for (User user : users) {
totpCache.add(user.getId());
}
this.totpCache = totpCache;
});
Punishment.findByType(ImmutableSet.of( Punishment.findByType(ImmutableSet.of(
Punishment.PunishmentType.BAN, Punishment.PunishmentType.BAN,
Punishment.PunishmentType.BLACKLIST Punishment.PunishmentType.BLACKLIST
@ -157,6 +173,9 @@ public final class GETDumpsType implements Handler<RoutingContext> {
String dumpType = ctx.request().getParam("dumpType"); String dumpType = ctx.request().getParam("dumpType");
switch (dumpType.toLowerCase()) { switch (dumpType.toLowerCase()) {
case "totp":
APIv3.respondJson(ctx, 200, totpCache);
return;
case "ban": case "ban":
APIv3.respondJson(ctx, 200, banCache); APIv3.respondJson(ctx, 200, banCache);
return; return;
@ -246,7 +265,7 @@ public final class GETDumpsType implements Handler<RoutingContext> {
)); ));
return; return;
default: default:
ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [ban, blacklist, accessDeniable, ipBan, grant, ipIntel, ipIntelFormatted]"); ErrorUtils.respondInvalidInput(ctx, dumpType + " is not a valid type. Not in [totp, ban, blacklist, accessDeniable, ipBan, grant, ipIntel, ipIntelFormatted]");
} }
} }