-
Notifications
You must be signed in to change notification settings - Fork 17
Final Refactoring - Syw UID2-4159 token gen code refactoring user identity #1123
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
base: main
Are you sure you want to change the base?
Changes from 52 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
2ae26b1
78a70d4
7875d98
d207e9c
5a4ab03
3979ca4
ddd77eb
7a26361
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 = "optout@unifiedid.com"; | ||
| public static final String OptOutTokenIdentityForPhone = "+00000000001"; | ||
|
|
||
| // DIIs for for testing with token/validate endpoint, see https://unifiedid.com/docs/endpoints/post-token-validate | ||
| public static final String ValidateIdentityForEmail = "validate@example.com"; | ||
| 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 = "optout@example.com"; | ||
| 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 = "refresh-optout@example.com"; | ||
| public static final String RefreshOptOutIdentityForPhone = "+00000000002"; | ||
|
|
||
|
|
||
|
|
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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; | ||
|
|
||
| public class AdvertisingTokenInput extends VersionedToken { | ||
| public final OperatorIdentity operatorIdentity; | ||
|
Contributor
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 know this is existing way of defining scope, but why do we declare these as public instead of creating Getter methods ?
Contributor
Author
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. Legacy? making more changes to use getters don't necessarily improve the readability so i haven't done it |
||
| public final SourcePublisher sourcePublisher; | ||
| public final RawUidIdentity rawUidIdentity; | ||
| public final PrivacyBits privacyBits; | ||
| public final Instant establishedAt; | ||
|
|
||
| public AdvertisingTokenInput(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 |
|---|---|---|
| @@ -1,18 +1,39 @@ | ||
| package com.uid2.operator.model; | ||
|
|
||
| import com.uid2.operator.model.userIdentity.HashedDiiIdentity; | ||
| import com.uid2.operator.util.PrivacyBits; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| public final class IdentityRequest { | ||
| public final PublisherIdentity publisherIdentity; | ||
| public final UserIdentity userIdentity; | ||
| public final SourcePublisher sourcePublisher; | ||
| public final HashedDiiIdentity hashedDiiIdentity; | ||
| public final OptoutCheckPolicy optoutCheckPolicy; | ||
|
|
||
| public final PrivacyBits privacyBits; | ||
| public final Instant establishedAt; | ||
|
|
||
| public IdentityRequest( | ||
| PublisherIdentity publisherIdentity, | ||
| UserIdentity userIdentity, | ||
| OptoutCheckPolicy tokenGeneratePolicy) | ||
| SourcePublisher sourcePublisher, | ||
| HashedDiiIdentity hashedDiiIdentity, | ||
| OptoutCheckPolicy tokenGeneratePolicy, | ||
| PrivacyBits privacyBits, | ||
| Instant establishedAt) | ||
| { | ||
| this.publisherIdentity = publisherIdentity; | ||
| this.userIdentity = userIdentity; | ||
| this.sourcePublisher = sourcePublisher; | ||
| this.hashedDiiIdentity = hashedDiiIdentity; | ||
| this.optoutCheckPolicy = tokenGeneratePolicy; | ||
| this.privacyBits = privacyBits; | ||
| this.establishedAt = establishedAt; | ||
| } | ||
|
|
||
| public IdentityRequest( | ||
| SourcePublisher sourcePublisher, | ||
| HashedDiiIdentity hashedDiiIdentity, | ||
| OptoutCheckPolicy tokenGeneratePolicy) | ||
| { | ||
|
||
| this(sourcePublisher, hashedDiiIdentity, tokenGeneratePolicy, PrivacyBits.DEFAULT, Instant.now()); | ||
|
|
||
| } | ||
|
|
||
| public boolean shouldCheckOptOut() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| 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 | ||
| public class IdentityResponse { | ||
|
||
| public static IdentityResponse OptOutIdentityResponse = new IdentityResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH); | ||
|
||
| private final String advertisingToken; | ||
| private final TokenVersion advertisingTokenVersion; | ||
| private final String refreshToken; | ||
| 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,20 @@ | ||
| package com.uid2.operator.model; | ||
|
|
||
| import com.uid2.operator.model.userIdentity.HashedDiiIdentity; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| public final class MapRequest { | ||
|
||
| 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; | ||
|
Contributor
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 -
Contributor
Author
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 |
||
| this.hashedDiiIdentity = hashedDiiIdentity; | ||
| this.optoutCheckPolicy = optoutCheckPolicy; | ||
| this.asOf = asOf; | ||
| } | ||
|
|
||
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 { | ||
|
||
| public static 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,37 @@ | |
|
|
||
| public class RefreshResponse { | ||
|
||
|
|
||
| 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 RefreshResponse Invalid = new RefreshResponse(Status.Invalid, IdentityResponse.OptOutIdentityResponse); | ||
|
||
| public static RefreshResponse Optout = new RefreshResponse(Status.Optout, IdentityResponse.OptOutIdentityResponse); | ||
| public static RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityResponse.OptOutIdentityResponse); | ||
| public static RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityResponse.OptOutIdentityResponse); | ||
| public static 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() { | ||
|
|
||
This file was deleted.
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 in comments
for forThere 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