|
16 | 16 | import com.iab.openrtb.request.Video; |
17 | 17 | import io.vertx.core.Future; |
18 | 18 | import io.vertx.ext.web.RoutingContext; |
| 19 | +import lombok.Value; |
19 | 20 | import org.apache.commons.lang3.StringUtils; |
20 | 21 | import org.prebid.server.auction.DebugResolver; |
21 | 22 | import org.prebid.server.auction.GeoLocationServiceWrapper; |
|
27 | 28 | import org.prebid.server.auction.gpp.AuctionGppService; |
28 | 29 | import org.prebid.server.auction.model.AuctionContext; |
29 | 30 | import org.prebid.server.auction.model.AuctionStoredResult; |
| 31 | +import org.prebid.server.auction.model.ConsentType; |
30 | 32 | import org.prebid.server.auction.model.IpAddress; |
31 | 33 | import org.prebid.server.auction.privacy.contextfactory.AuctionPrivacyContextFactory; |
32 | 34 | import org.prebid.server.auction.versionconverter.BidRequestOrtbVersionConversionManager; |
@@ -188,16 +190,17 @@ public Future<AuctionContext> enrichAuctionContext(AuctionContext initialContext |
188 | 190 |
|
189 | 191 | private BidRequest initialBidRequest(HttpRequestContext httpRequest) { |
190 | 192 | final GetInterfaceParams params = new GetInterfaceParams(httpRequest); |
| 193 | + final Consent consent = params.consent(); |
191 | 194 |
|
192 | 195 | return BidRequest.builder() |
193 | 196 | .imp(Collections.singletonList(initialImp(params))) |
194 | 197 | .site(tmpSite(params)) // Temporarily add to fetch account |
195 | 198 | .device(initialDevice(params)) |
196 | | - .user(initialUser(params)) |
| 199 | + .user(initialUser(params, consent)) |
197 | 200 | .tmax(params.tmax()) |
198 | 201 | .bcat(params.bCat()) |
199 | 202 | .badv(params.bAdv()) |
200 | | - .regs(initialRegs(params)) |
| 203 | + .regs(initialRegs(params, consent)) |
201 | 204 | .ext(initialExtRequest(params)) |
202 | 205 | .build(); |
203 | 206 | } |
@@ -231,19 +234,21 @@ private static Device initialDevice(GetInterfaceParams params) { |
231 | 234 | .build(); |
232 | 235 | } |
233 | 236 |
|
234 | | - private static User initialUser(GetInterfaceParams params) { |
| 237 | + private static User initialUser(GetInterfaceParams params, Consent consent) { |
235 | 238 | return User.builder() |
| 239 | + .consent(consent.getTcfConsent()) |
236 | 240 | .ext(ExtUser.builder() |
237 | 241 | .consentedProvidersSettings(ConsentedProvidersSettings.of(params.consentedProviders())) |
238 | 242 | .build()) |
239 | 243 | .build(); |
240 | 244 | } |
241 | 245 |
|
242 | | - private static Regs initialRegs(GetInterfaceParams params) { |
| 246 | + private static Regs initialRegs(GetInterfaceParams params, Consent consent) { |
243 | 247 | return Regs.builder() |
244 | 248 | .coppa(params.coppa()) |
245 | 249 | .gdpr(params.gdpr()) |
246 | | - .usPrivacy(params.usPrivacy()) |
| 250 | + .usPrivacy(consent.getUsPrivacy()) |
| 251 | + .gpp(consent.getGpp()) |
247 | 252 | .gppSid(params.gppSid()) |
248 | 253 | .ext(ExtRegs.of(null, null, params.gpc(), null)) |
249 | 254 | .build(); |
@@ -706,32 +711,58 @@ public Integer targeting() { |
706 | 711 | return null; // TODO: GET |
707 | 712 | } |
708 | 713 |
|
709 | | - public String consent() { // TODO: GET |
710 | | - return Optional.ofNullable(getString("consent")) |
711 | | - .or(() -> Optional.ofNullable(getString("gdpr_consent"))) |
712 | | - .orElseGet(() -> getString("consent_string")); |
| 714 | + public Consent consent() { |
| 715 | + String tcfConsent = getString("tcfc"); |
| 716 | + String usPrivacy = getString("usp"); |
| 717 | + String gpp = getString("gppc"); |
| 718 | + |
| 719 | + final String consentString = Optional.ofNullable(getString("consent_string")) |
| 720 | + .orElseGet(() -> getString("gdpr_consent")); |
| 721 | + final ConsentType consentType = StringUtils.isNotBlank(consentString) |
| 722 | + ? ConsentType.from(getString("consent_type")) |
| 723 | + : ConsentType.UNKNOWN; |
| 724 | + |
| 725 | + switch (consentType) { |
| 726 | + case TCF_V1, TCF_V2 -> { |
| 727 | + if (tcfConsent == null) { |
| 728 | + tcfConsent = consentString; |
| 729 | + } |
| 730 | + } |
| 731 | + case CCPA -> { |
| 732 | + if (usPrivacy == null) { |
| 733 | + usPrivacy = consentString; |
| 734 | + } |
| 735 | + } |
| 736 | + case GPP -> { |
| 737 | + if (gpp == null) { |
| 738 | + gpp = consentString; |
| 739 | + } |
| 740 | + } |
| 741 | + } |
| 742 | + |
| 743 | + return Consent.of(tcfConsent, usPrivacy, gpp); |
713 | 744 | } |
714 | 745 |
|
715 | 746 | public Integer gdpr() { |
716 | | - return Optional.ofNullable(getInteger("gdpr")) |
717 | | - .or(() -> Optional.ofNullable(getInteger("privacy"))) |
718 | | - .orElseGet(() -> getInteger("gdpr_applies")); |
719 | | - } |
| 747 | + Integer gdpr = getInteger("gdpr"); |
| 748 | + if (gdpr != null) { |
| 749 | + return gdpr; |
| 750 | + } |
720 | 751 |
|
721 | | - public String usPrivacy() { |
722 | | - return getString("usp"); |
| 752 | + return switch (getString("gdpr_applies")) { |
| 753 | + case "true" -> 1; |
| 754 | + case "false" -> 0; |
| 755 | + case null, default -> null; |
| 756 | + }; |
723 | 757 | } |
724 | 758 |
|
725 | 759 | public String consentedProviders() { |
726 | 760 | return getString("addtl_consent"); |
727 | 761 | } |
728 | 762 |
|
729 | | - public Integer consentType() { |
730 | | - return getInteger("consent_type"); |
731 | | - } |
732 | | - |
733 | 763 | public List<Integer> gppSid() { |
734 | | - return getListOfIntegers("gpp_sid"); |
| 764 | + return Optional.ofNullable(getListOfIntegers("gpps")) |
| 765 | + .orElseGet(() -> getListOfIntegers("gpp_sid")); |
735 | 766 | } |
736 | 767 |
|
737 | 768 | public Integer coppa() { |
@@ -868,4 +899,14 @@ private List<Integer> getListOfIntegers(String key) { |
868 | 899 | : null; |
869 | 900 | } |
870 | 901 | } |
| 902 | + |
| 903 | + @Value(staticConstructor = "of") |
| 904 | + private static class Consent { |
| 905 | + |
| 906 | + String tcfConsent; |
| 907 | + |
| 908 | + String usPrivacy; |
| 909 | + |
| 910 | + String gpp; |
| 911 | + } |
871 | 912 | } |
0 commit comments