Skip to content

Commit

Permalink
renamed the variable/method useIdentityV3/identityV3Enabled to useRaw…
Browse files Browse the repository at this point in the history
…UidV3/rawUidV3Enabled to be up to date with latest terminlogies
  • Loading branch information
sunnywu committed Dec 10, 2024
1 parent ed1512d commit 526155f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class UIDOperatorService implements IUIDOperatorService {

private final OperatorIdentity operatorIdentity;
private final TokenVersion refreshTokenVersion;
private final boolean identityV3Enabled;
// if we use Raw UID v3 format for the raw UID2/EUIDs generated in this operator
private final boolean rawUidV3Enabled;

private final Handler<Boolean> saltRetrievalResponseHandler;

Expand Down Expand Up @@ -90,7 +91,7 @@ public UIDOperatorService(JsonObject config, IOptOutStore optOutStore, ISaltProv
}

this.refreshTokenVersion = TokenVersion.V3;
this.identityV3Enabled = config.getBoolean("identity_v3", false);
this.rawUidV3Enabled = config.getBoolean("identity_v3", false);
}

@Override
Expand Down Expand Up @@ -230,7 +231,7 @@ private MappedIdentity getAdvertisingId(UserIdentity firstLevelHashIdentity, Ins
final SaltEntry rotatingSalt = getSaltProviderSnapshot(asOf).getRotatingSalt(firstLevelHashIdentity.id);

return new MappedIdentity(
this.identityV3Enabled
this.rawUidV3Enabled
? TokenUtils.getAdvertisingIdV3(firstLevelHashIdentity.identityScope, firstLevelHashIdentity.identityType, firstLevelHashIdentity.id, rotatingSalt.getSalt())
: TokenUtils.getAdvertisingIdV2(firstLevelHashIdentity.id, rotatingSalt.getSalt()),
rotatingSalt.getHashedId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public EUIDOperatorVerticleTest() throws IOException {
@Override
protected IdentityScope getIdentityScope() { return IdentityScope.EUID; }
@Override
protected boolean useIdentityV3() { return true; }
protected boolean useRawUidV3() { return true; }
@Override
protected void addAdditionalTokenGenerateParams(JsonObject payload) {
if (payload != null && !payload.containsKey("tcf_consent_string")) {
Expand Down
21 changes: 9 additions & 12 deletions src/test/java/com/uid2/operator/UIDOperatorVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.uid2.operator.util.Tuple;
import com.uid2.operator.vertx.OperatorShutdownHandler;
import com.uid2.operator.vertx.UIDOperatorVerticle;
import com.uid2.operator.vertx.ClientInputValidationException;
import com.uid2.shared.Utils;
import com.uid2.shared.auth.ClientKey;
import com.uid2.shared.auth.Keyset;
Expand All @@ -27,9 +26,7 @@
import com.uid2.shared.secret.KeyHasher;
import com.uid2.shared.store.*;
import com.uid2.shared.store.reader.RotatingKeysetProvider;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand Down Expand Up @@ -158,7 +155,7 @@ private void setupConfig(JsonObject config) {
config.put(Const.Config.SharingTokenExpiryProp, 60 * 60 * 24 * 30);

config.put("identity_scope", getIdentityScope().toString());
config.put("identity_v3", useIdentityV3());
config.put("identity_v3", useRawUidV3());
config.put("client_side_token_generate", true);
config.put("key_sharing_endpoint_provide_app_names", true);
config.put("client_side_token_generate_log_invalid_http_origins", true);
Expand Down Expand Up @@ -622,23 +619,23 @@ private void assertTokenStatusMetrics(Integer siteId, TokenResponseStatsCollecto
}

private byte[] getAdvertisingIdFromIdentity(IdentityType identityType, String identityString, String firstLevelSalt, String rotatingSalt) {
return getRawUid(identityType, identityString, firstLevelSalt, rotatingSalt, getIdentityScope(), useIdentityV3());
return getRawUid(identityType, identityString, firstLevelSalt, rotatingSalt, getIdentityScope(), useRawUidV3());
}

private static byte[] getRawUid(IdentityType identityType, String identityString, String firstLevelSalt, String rotatingSalt, IdentityScope identityScope, boolean useIdentityV3) {
return !useIdentityV3
private static byte[] getRawUid(IdentityType identityType, String identityString, String firstLevelSalt, String rotatingSalt, IdentityScope identityScope, boolean useRawUidV3) {
return !useRawUidV3
? TokenUtils.getAdvertisingIdV2FromIdentity(identityString, firstLevelSalt, rotatingSalt)
: TokenUtils.getAdvertisingIdV3FromIdentity(identityScope, identityType, identityString, firstLevelSalt, rotatingSalt);
}

public static byte[] getRawUid(IdentityType identityType, String identityString, IdentityScope identityScope, boolean useIdentityV3) {
return !useIdentityV3
public static byte[] getRawUid(IdentityType identityType, String identityString, IdentityScope identityScope, boolean useRawUidV3) {
return !useRawUidV3
? TokenUtils.getAdvertisingIdV2FromIdentity(identityString, firstLevelSalt, rotatingSalt123.getSalt())
: TokenUtils.getAdvertisingIdV3FromIdentity(identityScope, identityType, identityString, firstLevelSalt, rotatingSalt123.getSalt());
}

private byte[] getAdvertisingIdFromIdentityHash(IdentityType identityType, String identityString, String firstLevelSalt, String rotatingSalt) {
return !useIdentityV3()
return !useRawUidV3()
? TokenUtils.getAdvertisingIdV2FromIdentityHash(identityString, firstLevelSalt, rotatingSalt)
: TokenUtils.getAdvertisingIdV3FromIdentityHash(getIdentityScope(), identityType, identityString, firstLevelSalt, rotatingSalt);
}
Expand All @@ -665,7 +662,7 @@ private JsonObject setupIdentityMapServiceLinkTest() {

protected TokenVersion getTokenVersion() {return TokenVersion.V4;}

protected boolean useIdentityV3() { return false; }
protected boolean useRawUidV3() { return false; }
protected IdentityScope getIdentityScope() { return IdentityScope.UID2; }
protected void addAdditionalTokenGenerateParams(JsonObject payload) {}

Expand Down Expand Up @@ -819,7 +816,7 @@ private AdvertisingToken validateAndGetToken(EncryptedTokenEncoder encoder, Json

// without useIdentityV3() the assert will be trigger as there's no IdentityType in v4 token generated with
// a raw UID v2 as old raw UID format doesn't store the identity type (and scope)
if (useIdentityV3() && getTokenVersion() == TokenVersion.V4) {
if (useRawUidV3() && getTokenVersion() == TokenVersion.V4) {
assertEquals(identityType, advertisingToken.userIdentity.identityType);
}
return advertisingToken;
Expand Down

0 comments on commit 526155f

Please sign in to comment.