1313import com .uid2 .operator .util .Tuple ;
1414import com .uid2 .operator .vertx .OperatorShutdownHandler ;
1515import com .uid2 .operator .vertx .UIDOperatorVerticle ;
16- import com .uid2 .operator .vertx .ClientInputValidationException ;
1716import com .uid2 .shared .Utils ;
1817import com .uid2 .shared .auth .ClientKey ;
1918import com .uid2 .shared .auth .Keyset ;
2726import com .uid2 .shared .secret .KeyHasher ;
2827import com .uid2 .shared .store .*;
2928import com .uid2 .shared .store .reader .RotatingKeysetProvider ;
30- import io .micrometer .core .instrument .Counter ;
3129import io .micrometer .core .instrument .Metrics ;
32- import io .micrometer .core .instrument .search .MeterNotFoundException ;
3330import io .micrometer .core .instrument .simple .SimpleMeterRegistry ;
3431import io .vertx .core .AsyncResult ;
3532import io .vertx .core .Future ;
@@ -158,7 +155,7 @@ private void setupConfig(JsonObject config) {
158155 config .put (Const .Config .SharingTokenExpiryProp , 60 * 60 * 24 * 30 );
159156
160157 config .put ("identity_scope" , getIdentityScope ().toString ());
161- config .put ("identity_v3" , useIdentityV3 ());
158+ config .put ("identity_v3" , useRawUidV3 ());
162159 config .put ("client_side_token_generate" , true );
163160 config .put ("key_sharing_endpoint_provide_app_names" , true );
164161 config .put ("client_side_token_generate_log_invalid_http_origins" , true );
@@ -622,23 +619,23 @@ private void assertTokenStatusMetrics(Integer siteId, TokenResponseStatsCollecto
622619 }
623620
624621 private byte [] getAdvertisingIdFromIdentity (IdentityType identityType , String identityString , String firstLevelSalt , String rotatingSalt ) {
625- return getRawUid (identityType , identityString , firstLevelSalt , rotatingSalt , getIdentityScope (), useIdentityV3 ());
622+ return getRawUid (identityType , identityString , firstLevelSalt , rotatingSalt , getIdentityScope (), useRawUidV3 ());
626623 }
627624
628- private static byte [] getRawUid (IdentityType identityType , String identityString , String firstLevelSalt , String rotatingSalt , IdentityScope identityScope , boolean useIdentityV3 ) {
629- return !useIdentityV3
625+ private static byte [] getRawUid (IdentityType identityType , String identityString , String firstLevelSalt , String rotatingSalt , IdentityScope identityScope , boolean useRawUidV3 ) {
626+ return !useRawUidV3
630627 ? TokenUtils .getAdvertisingIdV2FromIdentity (identityString , firstLevelSalt , rotatingSalt )
631628 : TokenUtils .getAdvertisingIdV3FromIdentity (identityScope , identityType , identityString , firstLevelSalt , rotatingSalt );
632629 }
633630
634- public static byte [] getRawUid (IdentityType identityType , String identityString , IdentityScope identityScope , boolean useIdentityV3 ) {
635- return !useIdentityV3
631+ public static byte [] getRawUid (IdentityType identityType , String identityString , IdentityScope identityScope , boolean useRawUidV3 ) {
632+ return !useRawUidV3
636633 ? TokenUtils .getAdvertisingIdV2FromIdentity (identityString , firstLevelSalt , rotatingSalt123 .getSalt ())
637634 : TokenUtils .getAdvertisingIdV3FromIdentity (identityScope , identityType , identityString , firstLevelSalt , rotatingSalt123 .getSalt ());
638635 }
639636
640637 private byte [] getAdvertisingIdFromIdentityHash (IdentityType identityType , String identityString , String firstLevelSalt , String rotatingSalt ) {
641- return !useIdentityV3 ()
638+ return !useRawUidV3 ()
642639 ? TokenUtils .getAdvertisingIdV2FromIdentityHash (identityString , firstLevelSalt , rotatingSalt )
643640 : TokenUtils .getAdvertisingIdV3FromIdentityHash (getIdentityScope (), identityType , identityString , firstLevelSalt , rotatingSalt );
644641 }
@@ -665,7 +662,7 @@ private JsonObject setupIdentityMapServiceLinkTest() {
665662
666663 protected TokenVersion getTokenVersion () {return TokenVersion .V4 ;}
667664
668- final boolean useIdentityV3 () { return getTokenVersion () != TokenVersion . V2 ; }
665+ protected boolean useRawUidV3 () { return false ; }
669666 protected IdentityScope getIdentityScope () { return IdentityScope .UID2 ; }
670667 protected void addAdditionalTokenGenerateParams (JsonObject payload ) {}
671668
@@ -816,7 +813,10 @@ private AdvertisingToken validateAndGetToken(EncryptedTokenEncoder encoder, Json
816813 final String advertisingTokenString = body .getString ("advertising_token" );
817814 validateAdvertisingToken (advertisingTokenString , getTokenVersion (), getIdentityScope (), identityType );
818815 AdvertisingToken advertisingToken = encoder .decodeAdvertisingToken (advertisingTokenString );
819- if (getTokenVersion () == TokenVersion .V4 ) {
816+
817+ // without useIdentityV3() the assert will be trigger as there's no IdentityType in v4 token generated with
818+ // a raw UID v2 as old raw UID format doesn't store the identity type (and scope)
819+ if (useRawUidV3 () && getTokenVersion () == TokenVersion .V4 ) {
820820 assertEquals (identityType , advertisingToken .userIdentity .identityType );
821821 }
822822 return advertisingToken ;
0 commit comments