@@ -233,7 +233,7 @@ public void handleKeysRequestV1(RoutingContext rc) {
233233 try {
234234 handleKeysRequestCommon (rc , keys -> ResponseUtil .Success (rc , keys ));
235235 } catch (Exception e ) {
236- LOGGER .error (e );
236+ LOGGER .error ("Unknown error while handling keys request v1" , e );
237237 rc .fail (500 );
238238 }
239239 }
@@ -242,7 +242,7 @@ public void handleKeysRequestV2(RoutingContext rc) {
242242 try {
243243 handleKeysRequestCommon (rc , keys -> ResponseUtil .SuccessV2 (rc , keys ));
244244 } catch (Exception e ) {
245- LOGGER .error (e );
245+ LOGGER .error ("Unknown error while handling keys request v2" , e );
246246 rc .fail (500 );
247247 }
248248 }
@@ -251,7 +251,7 @@ public void handleKeysRequest(RoutingContext rc) {
251251 try {
252252 handleKeysRequestCommon (rc , keys -> sendJsonResponse (rc , keys ));
253253 } catch (Exception e ) {
254- LOGGER .error (e );
254+ LOGGER .error ("Unknown error while handling keys request" , e );
255255 rc .fail (500 );
256256 }
257257 }
@@ -309,7 +309,7 @@ private void handleTokenRefreshV1(RoutingContext rc) {
309309 ResponseUtil .Success (rc , toJsonV1 (r .getTokens ()));
310310 }
311311 } catch (Exception e ) {
312- LOGGER .error (e );
312+ LOGGER .error ("unknown error while refreshing token" , e );
313313 ResponseUtil .Error (ResponseStatus .UnknownError , 500 , rc , "Service Error" );
314314 }
315315 }
@@ -336,7 +336,7 @@ private void handleTokenRefreshV2(RoutingContext rc) {
336336 ResponseUtil .SuccessV2 (rc , toJsonV1 (r .getTokens ()));
337337 }
338338 } catch (Exception e ) {
339- LOGGER .error (e );
339+ LOGGER .error ("Unknown error while refreshing token v2" , e );
340340 ResponseUtil .Error (ResponseStatus .UnknownError , 500 , rc , "Service Error" );
341341 }
342342 }
@@ -363,7 +363,7 @@ private void handleTokenValidateV1(RoutingContext rc) {
363363 ResponseUtil .Success (rc , Boolean .FALSE );
364364 }
365365 } catch (Exception e ) {
366- LOGGER .error (e );
366+ LOGGER .error ("Unknown error while validating token" , e );
367367 rc .fail (500 );
368368 }
369369 }
@@ -394,7 +394,7 @@ private void handleTokenValidateV2(RoutingContext rc) {
394394 ResponseUtil .SuccessV2 (rc , Boolean .FALSE );
395395 }
396396 } catch (Exception e ) {
397- LOGGER .error (e );
397+ LOGGER .error ("Unknown error while validating token v2" , e );
398398 rc .fail (500 );
399399 }
400400 }
@@ -409,14 +409,15 @@ private void handleTokenGenerateV1(RoutingContext rc) {
409409 final IdentityTokens t = this .idService .generateIdentity (
410410 new IdentityRequest (
411411 new PublisherIdentity (clientKey .getSiteId (), 0 , 0 ),
412- input .toUserIdentity (this .identityScope , 1 , Instant .now ())));
412+ input .toUserIdentity (this .identityScope , 1 , Instant .now ()),
413+ TokenGeneratePolicy .defaultPolicy ()));
413414
414415 //Integer.parseInt(rc.queryParam("privacy_bits").get(0))));
415416
416417 ResponseUtil .Success (rc , toJsonV1 (t ));
417418 }
418419 } catch (Exception e ) {
419- LOGGER .error (e );
420+ LOGGER .error ("Unknown error while generating token v1" , e );
420421 rc .fail (500 );
421422 }
422423 }
@@ -452,11 +453,20 @@ private void handleTokenGenerateV2(RoutingContext rc) {
452453 final IdentityTokens t = this .idService .generateIdentity (
453454 new IdentityRequest (
454455 new PublisherIdentity (clientKey .getSiteId (), 0 , 0 ),
455- input .toUserIdentity (this .identityScope , 1 , Instant .now ())));
456- ResponseUtil .SuccessV2 (rc , toJsonV1 (t ));
456+ input .toUserIdentity (this .identityScope , 1 , Instant .now ()),
457+ readTokenGeneratePolicy (req )));
458+
459+ if (t .isEmptyToken ()) {
460+ ResponseUtil .OptOutV2 (rc , toJsonV1 (t ));
461+ } else {
462+ ResponseUtil .SuccessV2 (rc , toJsonV1 (t ));
463+ }
457464 }
465+ } catch (IllegalArgumentException iae ) {
466+ LOGGER .warn ("request body contains invalid argument(s)" , iae );
467+ ResponseUtil .ClientError (rc , "request body contains invalid argument(s)" );
458468 } catch (Exception e ) {
459- LOGGER .error (e );
469+ LOGGER .error ("Unknown error while generating token v2" , e );
460470 rc .fail (500 );
461471 }
462472 }
@@ -473,14 +483,15 @@ private void handleTokenGenerate(RoutingContext rc) {
473483 final IdentityTokens t = this .idService .generateIdentity (
474484 new IdentityRequest (
475485 new PublisherIdentity (clientKey .getSiteId (), 0 , 0 ),
476- input .toUserIdentity (this .identityScope , 1 , Instant .now ())));
486+ input .toUserIdentity (this .identityScope , 1 , Instant .now ()),
487+ TokenGeneratePolicy .defaultPolicy ()));
477488
478489 //Integer.parseInt(rc.queryParam("privacy_bits").get(0))));
479490
480491 sendJsonResponse (rc , toJson (t ));
481492
482493 } catch (Exception e ) {
483- LOGGER .error (e );
494+ LOGGER .error ("Unknown error while generating token" , e );
484495 rc .fail (500 );
485496 }
486497 }
@@ -496,7 +507,7 @@ private void handleTokenRefresh(RoutingContext rc) {
496507 final RefreshResponse r = this .refreshIdentity (rc , tokenList .get (0 ));
497508 sendJsonResponse (rc , toJson (r .getTokens ()));
498509 } catch (Exception e ) {
499- LOGGER .error (e );
510+ LOGGER .error ("Unknown error while refreshing token" , e );
500511 rc .fail (500 );
501512 }
502513 }
@@ -519,7 +530,7 @@ private void handleValidate(RoutingContext rc) {
519530 rc .response ().end ("not allowed" );
520531 }
521532 } catch (Exception e ) {
522- LOGGER .error (e );
533+ LOGGER .error ("Unknown error while validating token" , e );
523534 rc .fail (500 );
524535 }
525536 }
@@ -577,7 +588,7 @@ private void handleOptOutGet(RoutingContext rc) {
577588 .write (String .valueOf (timestamp ))
578589 .end ();
579590 } catch (Exception ex ) {
580- LOGGER .error (ex );
591+ LOGGER .error ("Unexpected error while handling optout get" , ex );
581592 rc .fail (500 );
582593 }
583594 } else {
@@ -659,7 +670,7 @@ private void handleIdentityMapV1(RoutingContext rc) {
659670 jsonObject .put ("bucket_id" , mappedIdentity .bucketId );
660671 ResponseUtil .Success (rc , jsonObject );
661672 } catch (Exception e ) {
662- LOGGER .error (e );
673+ LOGGER .error ("Unknown error while mapping identity v1" , e );
663674 ResponseUtil .Error (ResponseStatus .UnknownError , 500 , rc , "Unknown State" );
664675 }
665676 }
@@ -677,7 +688,7 @@ private void handleIdentityMap(RoutingContext rc) {
677688 }
678689 }
679690 catch (Exception ex ) {
680- LOGGER .error (ex );
691+ LOGGER .error ("Unexpected error while mapping identity" , ex );
681692 rc .fail (500 );
682693 }
683694 }
@@ -887,7 +898,7 @@ private void handleIdentityMapBatchV1(RoutingContext rc) {
887898 resp .put ("mapped" , mapped );
888899 ResponseUtil .Success (rc , resp );
889900 } catch (Exception e ) {
890- LOGGER .error (e );
901+ LOGGER .error ("Unknown error while mapping batched identity" , e );
891902 ResponseUtil .Error (ResponseStatus .UnknownError , 500 , rc , "Unknown State" );
892903 }
893904 }
@@ -924,7 +935,7 @@ private void handleIdentityMapV2(RoutingContext rc) {
924935 resp .put ("mapped" , mapped );
925936 ResponseUtil .SuccessV2 (rc , resp );
926937 } catch (Exception e ) {
927- LOGGER .error (e );
938+ LOGGER .error ("Unknown error while mapping identity v2" , e );
928939 ResponseUtil .Error (ResponseStatus .UnknownError , 500 , rc , "Unknown State" );
929940 }
930941 }
@@ -1011,7 +1022,7 @@ private void handleIdentityMapBatch(RoutingContext rc) {
10111022 resp .put ("mapped" , mapped );
10121023 sendJsonResponse (rc , resp );
10131024 } catch (Exception e ) {
1014- LOGGER .error (e );
1025+ LOGGER .error ("Unknown error while mapping batched identity" , e );
10151026 rc .fail (500 );
10161027 }
10171028 }
@@ -1148,6 +1159,13 @@ private UserConsentStatus validateUserConsent(JsonObject req) {
11481159 return UserConsentStatus .SUFFICIENT ;
11491160 }
11501161
1162+ private static final String TOKEN_GENERATE_POLICY_PARAM = "policy" ;
1163+ private TokenGeneratePolicy readTokenGeneratePolicy (JsonObject req ) {
1164+ return req .containsKey (TOKEN_GENERATE_POLICY_PARAM ) ?
1165+ TokenGeneratePolicy .fromValue (req .getInteger (TOKEN_GENERATE_POLICY_PARAM )) :
1166+ TokenGeneratePolicy .defaultPolicy ();
1167+ }
1168+
11511169 private TransparentConsentParseResult getUserConsentV2 (JsonObject req ) {
11521170 final String rawTcString = req .getString ("tcf_consent_string" );
11531171 if (rawTcString == null || rawTcString .isEmpty ()) {
0 commit comments