Add hashed ip fields in IpIntel + IpLogEntry

This commit is contained in:
Colin McDonald 2016-08-17 22:30:47 -04:00
parent e100009f4a
commit 6473ee2bd1
2 changed files with 8 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package net.frozenorb.apiv3.model;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
import fr.javatic.mongo.jacksonCodec.Entity;
@ -25,6 +27,7 @@ public final class IpIntel {
private static final MongoCollection<IpIntel> ipIntelCollection = APIv3.getDatabase().getCollection("ipIntel", IpIntel.class);
@Getter @Id private String id;
@Getter private String hashedIp;
@Getter private Instant lastUpdatedAt;
@Getter private MaxMindResult result;
@ -127,6 +130,7 @@ public final class IpIntel {
private IpIntel(String ip, MaxMindResult result) {
this.id = ip;
this.hashedIp = Hashing.sha256().hashString(id + APIv3.getConfig().getProperty("ipHashing.salt"), Charsets.UTF_8).toString();
this.lastUpdatedAt = Instant.now();
this.result = result;
}

View File

@ -1,5 +1,7 @@
package net.frozenorb.apiv3.model;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.mongodb.async.SingleResultCallback;
import com.mongodb.async.client.MongoCollection;
import fr.javatic.mongo.jacksonCodec.Entity;
@ -26,6 +28,7 @@ public final class IpLogEntry {
@Getter @Id private String id;
@Getter private UUID user;
@Getter private String userIp;
@Getter private String hashedUserIp;
@Getter private Instant firstSeenAt;
@Getter private Instant lastSeenAt;
@Getter private int uses;
@ -68,6 +71,7 @@ public final class IpLogEntry {
this.id = new ObjectId().toString();
this.user = user.getId();
this.userIp = userIp;
this.hashedUserIp = Hashing.sha256().hashString(userIp + APIv3.getConfig().getProperty("ipHashing.salt"), Charsets.UTF_8).toString();
this.firstSeenAt = Instant.now();
this.lastSeenAt = Instant.now();
this.uses = 0;