-
Notifications
You must be signed in to change notification settings - Fork 17
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
Final Refactoring - Syw UID2-4158 token gen code refactoring user identity #1123
base: main
Are you sure you want to change the base?
Changes from 63 commits
1693ea8
14fd733
7dd3a69
f2e7a87
c0cb6df
0fccf8c
113e8ca
ae03ff5
5595a15
c6bc08f
639b799
d9c730e
42c5890
b62aa54
b272d40
7e5ad5d
131d203
8dc0a41
91ffa12
d9845b7
4bb4ccb
8ae5e08
5a0bb89
b507d8e
f5877b7
ccc639f
dabff48
d8eda03
e74e8da
7f4ebf5
72f7be4
44ed5d3
21f0c60
6031d14
3b1718c
0ab0a79
7538bfb
249c25d
53f4de1
3624f15
a38af09
4c1de75
062f908
76a1345
5db6e4f
741237d
3900017
e5b104d
e25cd19
986cf2e
f445180
e4e7d2d
fa1c0f1
20d695c
c950c6d
a908e1f
04dfc14
2edcb05
ca44945
da549b0
c6586a5
d76bceb
23a6f50
a002ad1
ea0b247
4476ee1
6bb1fb9
a8f0915
7875d98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,22 @@ | |
import com.uid2.operator.service.EncodingUtils; | ||
|
||
public class IdentityConst { | ||
|
||
// DIIs for generating optout tokens for legacy participants - to be deprecated | ||
public static final String OptOutTokenIdentityForEmail = "[email protected]"; | ||
public static final String OptOutTokenIdentityForPhone = "+00000000001"; | ||
|
||
// DIIs for testing with token/validate endpoint, see https://unifiedid.com/docs/endpoints/post-token-validate | ||
public static final String ValidateIdentityForEmail = "[email protected]"; | ||
public static final String ValidateIdentityForPhone = "+12345678901"; | ||
public static final byte[] ValidateIdentityForEmailHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForEmail); | ||
public static final byte[] ValidateIdentityForPhoneHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForPhone); | ||
|
||
// DIIs to use when you want to generate a optout response in token generation or identity map | ||
public static final String OptOutIdentityForEmail = "[email protected]"; | ||
public static final String OptOutIdentityForPhone = "+00000000000"; | ||
|
||
// DIIs to use when you want to generate a UID token but when doing refresh token, you want to always get an optout response | ||
// to test the optout handling workflow | ||
public static final String RefreshOptOutIdentityForEmail = "[email protected]"; | ||
public static final String RefreshOptOutIdentityForPhone = "+00000000002"; | ||
|
||
|
||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.uid2.operator.model; | ||
|
||
import java.time.Instant; | ||
|
||
import com.uid2.operator.model.userIdentity.RawUidIdentity; | ||
import com.uid2.operator.util.PrivacyBits; | ||
import com.uid2.shared.model.TokenVersion; | ||
|
||
// class containing enough data to create a new uid or advertising token | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it mean "new uid token" and "new advertising token"? If so, what is the difference between the two? Or does it mean "new uid" and "new advertising token"? If so, why is the advertising token request used to create a new uid? What is a uid in this case anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should re-phrase better to I use the term uid because this is about UID2/EUID. I think we have an understanding previously that from now on we should try to call things UID if it's used for both UID2 & EUID. |
||
public class AdvertisingTokenRequest extends VersionedToken { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this class inherit from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VersionedToken is a generic store for both AdvertisingTokenRequest and RefreshTokenRequest. So yeh i can rename to VersionedTokenRequest to be consistent. Fixed |
||
public final OperatorIdentity operatorIdentity; | ||
public final SourcePublisher sourcePublisher; | ||
public final RawUidIdentity rawUidIdentity; | ||
public final PrivacyBits privacyBits; | ||
public final Instant establishedAt; | ||
|
||
public AdvertisingTokenRequest(TokenVersion version, Instant createdAt, Instant expiresAt, OperatorIdentity operatorIdentity, | ||
SourcePublisher sourcePublisher, RawUidIdentity rawUidIdentity, PrivacyBits privacyBits, | ||
Instant establishedAt) { | ||
super(version, createdAt, expiresAt); | ||
this.operatorIdentity = operatorIdentity; | ||
this.sourcePublisher = sourcePublisher; | ||
this.rawUidIdentity = rawUidIdentity; | ||
this.privacyBits = privacyBits; | ||
this.establishedAt = establishedAt; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.uid2.operator.model; | ||
|
||
import com.uid2.shared.model.TokenVersion; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
import java.time.Instant; | ||
|
||
// this defines all the fields for the response of the /token/generate and /client/generate endpoints before they are | ||
// jsonified | ||
// todo: can be converted to record later | ||
public class IdentityResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was IdentityTokens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given this is used for token generation / refresh responses and that we have identity map API, it can be confusing what this refers to. Should this be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sidenote: we can start using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noted. probably won't change it but leaving a note as future improvement |
||
public static IdentityResponse OptOutIdentityResponse = new IdentityResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
//aka UID token | ||
private final String advertisingToken; | ||
private final TokenVersion advertisingTokenVersion; | ||
private final String refreshToken; | ||
// when the advertising token/uid token expires | ||
private final Instant identityExpires; | ||
private final Instant refreshExpires; | ||
private final Instant refreshFrom; | ||
|
||
public IdentityResponse(String advertisingToken, TokenVersion advertisingTokenVersion, String refreshToken, | ||
Instant identityExpires, Instant refreshExpires, Instant refreshFrom) { | ||
this.advertisingToken = advertisingToken; | ||
this.advertisingTokenVersion = advertisingTokenVersion; | ||
this.refreshToken = refreshToken; | ||
this.identityExpires = identityExpires; | ||
this.refreshExpires = refreshExpires; | ||
this.refreshFrom = refreshFrom; | ||
} | ||
|
||
public String getAdvertisingToken() { | ||
return advertisingToken; | ||
} | ||
|
||
public TokenVersion getAdvertisingTokenVersion() { | ||
return advertisingTokenVersion; | ||
} | ||
|
||
public String getRefreshToken() { | ||
return refreshToken; | ||
} | ||
|
||
public Instant getIdentityExpires() { | ||
return identityExpires; | ||
} | ||
|
||
public Instant getRefreshExpires() { | ||
return refreshExpires; | ||
} | ||
|
||
public Instant getRefreshFrom() { | ||
return refreshFrom; | ||
} | ||
|
||
public boolean isOptedOut() { | ||
return advertisingToken == null || advertisingToken.isEmpty(); | ||
} | ||
|
||
// for v1/v2 token/generate and token/refresh and client/generate (CSTG) endpoints | ||
public JsonObject toJsonV1() { | ||
final JsonObject json = new JsonObject(); | ||
json.put("advertising_token", getAdvertisingToken()); | ||
json.put("refresh_token", getRefreshToken()); | ||
json.put("identity_expires", getIdentityExpires().toEpochMilli()); | ||
json.put("refresh_expires", getRefreshExpires().toEpochMilli()); | ||
json.put("refresh_from", getRefreshFrom().toEpochMilli()); | ||
return json; | ||
} | ||
|
||
// for the original/legacy token/generate and token/refresh endpoint | ||
public JsonObject toJsonV0() { | ||
final JsonObject json = new JsonObject(); | ||
json.put("advertisement_token", getAdvertisingToken()); | ||
json.put("advertising_token", getAdvertisingToken()); | ||
json.put("refresh_token", getRefreshToken()); | ||
|
||
return json; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com.uid2.operator.model; | ||
|
||
import com.uid2.operator.model.userIdentity.HashedDiiIdentity; | ||
|
||
import java.time.Instant; | ||
|
||
public final class MapRequest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed to |
||
public final UserIdentity userIdentity; | ||
public final HashedDiiIdentity hashedDiiIdentity; | ||
public final OptoutCheckPolicy optoutCheckPolicy; | ||
public final Instant asOf; | ||
|
||
public MapRequest( | ||
UserIdentity userIdentity, | ||
HashedDiiIdentity hashedDiiIdentity, | ||
OptoutCheckPolicy optoutCheckPolicy, | ||
Instant asOf) | ||
{ | ||
this.userIdentity = userIdentity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is an existing styling issue here - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
Instant asOf) { | ||
this.hashedDiiIdentity = hashedDiiIdentity; | ||
this.optoutCheckPolicy = optoutCheckPolicy; | ||
this.asOf = asOf; | ||
} | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.uid2.operator.model; | ||
|
||
// Contains the computed raw UID and its bucket ID from identity/map request | ||
public class RawUidResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed from MappedIdentity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking again - I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this applies too to the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm the identity/map function has a hashed dii input and returns a raw Uid (and bucket id). I can call For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to IdentityMapResponseItem and also MapRequest to IdentityMapRequestItem |
||
public static final RawUidResponse OptoutIdentity = new RawUidResponse(new byte[33], ""); | ||
// The raw UID is also known as Advertising Id (historically) | ||
public final byte[] rawUid; | ||
public final String bucketId; | ||
|
||
public RawUidResponse(byte[] rawUid, String bucketId) { | ||
this.rawUid = rawUid; | ||
this.bucketId = bucketId; | ||
} | ||
|
||
// historically Optout is known as Logout | ||
public boolean isOptedOut() { | ||
return this.equals(OptoutIdentity) || this.bucketId == null || this.bucketId.isEmpty(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,37 +4,38 @@ | |
|
||
public class RefreshResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
|
||
public static RefreshResponse Invalid = new RefreshResponse(Status.Invalid, IdentityTokens.LogoutToken); | ||
public static RefreshResponse Optout = new RefreshResponse(Status.Optout, IdentityTokens.LogoutToken); | ||
public static RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityTokens.LogoutToken); | ||
public static RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityTokens.LogoutToken); | ||
public static RefreshResponse NoActiveKey = new RefreshResponse(Status.NoActiveKey, IdentityTokens.LogoutToken); | ||
public static final RefreshResponse Invalid = new RefreshResponse(Status.Invalid, | ||
IdentityResponse.OptOutIdentityResponse); | ||
public static final RefreshResponse Optout = new RefreshResponse(Status.Optout, IdentityResponse.OptOutIdentityResponse); | ||
public static final RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityResponse.OptOutIdentityResponse); | ||
public static final RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityResponse.OptOutIdentityResponse); | ||
public static final RefreshResponse NoActiveKey = new RefreshResponse(Status.NoActiveKey, IdentityResponse.OptOutIdentityResponse); | ||
private final Status status; | ||
private final IdentityTokens tokens; | ||
private final IdentityResponse identityResponse; | ||
private final Duration durationSinceLastRefresh; | ||
private final boolean isCstg; | ||
|
||
private RefreshResponse(Status status, IdentityTokens tokens, Duration durationSinceLastRefresh, boolean isCstg) { | ||
private RefreshResponse(Status status, IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) { | ||
this.status = status; | ||
this.tokens = tokens; | ||
this.identityResponse = identityResponse; | ||
this.durationSinceLastRefresh = durationSinceLastRefresh; | ||
this.isCstg = isCstg; | ||
} | ||
|
||
private RefreshResponse(Status status, IdentityTokens tokens) { | ||
this(status, tokens, null, false); | ||
private RefreshResponse(Status status, IdentityResponse identityResponse) { | ||
this(status, identityResponse, null, false); | ||
} | ||
|
||
public static RefreshResponse createRefreshedResponse(IdentityTokens tokens, Duration durationSinceLastRefresh, boolean isCstg) { | ||
return new RefreshResponse(Status.Refreshed, tokens, durationSinceLastRefresh, isCstg); | ||
public static RefreshResponse createRefreshedResponse(IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) { | ||
return new RefreshResponse(Status.Refreshed, identityResponse, durationSinceLastRefresh, isCstg); | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public IdentityTokens getTokens() { | ||
return tokens; | ||
public IdentityResponse getIdentityResponse() { | ||
return identityResponse; | ||
} | ||
|
||
public Duration getDurationSinceLastRefresh() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: should be
an optout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed