-
Notifications
You must be signed in to change notification settings - Fork 9
Adding new Identity Map V3 and Refreshable UID fields to SaltEntry #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3cb879
Adding new Identity Map V3 and Refreshable UID fields to SaltEntry
aulme 73c14f2
Refactoring
aulme ea5da3a
Refactoring so we don't need to join and split the salt files into li…
aulme f300d80
Remove unnecessary file
aulme 0484311
Extra test and refactoring
aulme b03b948
Address some feedback
aulme c745404
Fix test
aulme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
package com.uid2.shared.model; | ||
|
||
public class SaltEntry { | ||
private final long id; | ||
private final String hashedId; | ||
private final long lastUpdated; | ||
private final String salt; | ||
public record SaltEntry( | ||
long id, | ||
String hashedId, | ||
long lastUpdated, | ||
String salt, | ||
|
||
public SaltEntry(long id, String hashedId, long lastUpdated, String salt) { | ||
this.id = id; | ||
this.lastUpdated = lastUpdated; | ||
this.hashedId = hashedId; | ||
this.salt = salt; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public String getHashedId() { | ||
return hashedId; | ||
} | ||
Long refreshFrom, // needs to be nullable until V3 Identity Map is fully rolled out | ||
String previousSalt, | ||
|
||
public long getLastUpdated() { | ||
return lastUpdated; | ||
KeyMaterial currentKey, | ||
KeyMaterial previousKey | ||
) { | ||
@Override | ||
public String toString() { | ||
return "SaltEntry{" + | ||
gmsdelmundo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"id=" + id + | ||
", hashedId='" + hashedId + '\'' + | ||
gmsdelmundo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
", lastUpdated=" + lastUpdated + | ||
", salt=<REDACTED>" + | ||
", refreshFrom=" + refreshFrom + | ||
", previousSalt=<REDACTED>" + | ||
", currentKey=" + currentKey + | ||
", previousKey=" + previousKey + | ||
'}'; | ||
} | ||
|
||
public String getSalt() { | ||
return salt; | ||
public record KeyMaterial( | ||
int id, | ||
String key, | ||
String salt | ||
){ | ||
aulme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public String toString() { | ||
return "KeyMaterial{" + | ||
"id=" + id + | ||
", key=<REDACTED>" + | ||
", salt=<REDACTED>" + | ||
'}'; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../com/uid2/shared/store/ISaltProvider.java → ...uid2/shared/store/salt/ISaltProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/uid2/shared/store/salt/IdHashingScheme.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.uid2.shared.store.salt; | ||
|
||
import org.hashids.Hashids; | ||
|
||
public class IdHashingScheme { | ||
private final String prefix; | ||
private final Hashids hasher; | ||
|
||
public IdHashingScheme(final String prefix, final String secret) { | ||
this.prefix = prefix; | ||
this.hasher = new Hashids(secret, 9); | ||
} | ||
|
||
public String encode(long id) { | ||
return prefix + this.hasher.encode(id); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/uid2/shared/store/salt/SaltFileParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.uid2.shared.store.salt; | ||
|
||
import com.uid2.shared.model.SaltEntry; | ||
|
||
public class SaltFileParser { | ||
private final IdHashingScheme idHashingScheme; | ||
|
||
public SaltFileParser(IdHashingScheme idHashingScheme) { | ||
this.idHashingScheme = idHashingScheme; | ||
} | ||
|
||
public SaltEntry[] parseFile(String saltFileContent, Integer size) { | ||
gmsdelmundo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var lines = saltFileContent.split("\n"); | ||
return parseFileLines(lines, size); | ||
} | ||
|
||
public SaltEntry[] parseFileLines(String[] saltFileLines, Integer size) { | ||
var entries = new SaltEntry[size]; | ||
int idx = 0; | ||
for (String line : saltFileLines) { | ||
final SaltEntry entry = parseLine(line); | ||
entries[idx] = entry; | ||
idx++; | ||
} | ||
return entries; | ||
} | ||
|
||
private SaltEntry parseLine(String line) { | ||
try { | ||
final String[] fields = line.split(","); | ||
final long id = Integer.parseInt(fields[0]); | ||
final String hashedId = this.idHashingScheme.encode(id); | ||
final long lastUpdated = Long.parseLong(fields[1]); | ||
final String salt = fields[2]; | ||
|
||
Long refreshFrom = null; | ||
String previousSalt = null; | ||
SaltEntry.KeyMaterial currentKey = null; | ||
SaltEntry.KeyMaterial previousKey = null; | ||
|
||
if (fields.length > 3) { | ||
aulme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
refreshFrom = Long.parseLong(fields[3]); | ||
} | ||
if (fields.length > 4) { | ||
previousSalt = fields[4]; | ||
} | ||
if (fields.length > 7) { | ||
currentKey = new SaltEntry.KeyMaterial(Integer.parseInt(fields[5]), fields[6], fields[7]); | ||
} | ||
if (fields.length > 10) { | ||
previousKey = new SaltEntry.KeyMaterial(Integer.parseInt(fields[8]), fields[9], fields[10]); | ||
} | ||
|
||
return new SaltEntry(id, hashedId, lastUpdated, salt, refreshFrom, previousSalt, currentKey, previousKey); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Trouble parsing Salt Entry " + line, e); | ||
aulme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.