Skip to content

Commit 845c336

Browse files
committed
Add consent strings
1 parent d2ef40b commit 845c336

1 file changed

Lines changed: 61 additions & 20 deletions

File tree

src/main/java/org/prebid/server/auction/requestfactory/GetInterfaceRequestFactory.java

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.iab.openrtb.request.Video;
1717
import io.vertx.core.Future;
1818
import io.vertx.ext.web.RoutingContext;
19+
import lombok.Value;
1920
import org.apache.commons.lang3.StringUtils;
2021
import org.prebid.server.auction.DebugResolver;
2122
import org.prebid.server.auction.GeoLocationServiceWrapper;
@@ -27,6 +28,7 @@
2728
import org.prebid.server.auction.gpp.AuctionGppService;
2829
import org.prebid.server.auction.model.AuctionContext;
2930
import org.prebid.server.auction.model.AuctionStoredResult;
31+
import org.prebid.server.auction.model.ConsentType;
3032
import org.prebid.server.auction.model.IpAddress;
3133
import org.prebid.server.auction.privacy.contextfactory.AuctionPrivacyContextFactory;
3234
import org.prebid.server.auction.versionconverter.BidRequestOrtbVersionConversionManager;
@@ -188,16 +190,17 @@ public Future<AuctionContext> enrichAuctionContext(AuctionContext initialContext
188190

189191
private BidRequest initialBidRequest(HttpRequestContext httpRequest) {
190192
final GetInterfaceParams params = new GetInterfaceParams(httpRequest);
193+
final Consent consent = params.consent();
191194

192195
return BidRequest.builder()
193196
.imp(Collections.singletonList(initialImp(params)))
194197
.site(tmpSite(params)) // Temporarily add to fetch account
195198
.device(initialDevice(params))
196-
.user(initialUser(params))
199+
.user(initialUser(params, consent))
197200
.tmax(params.tmax())
198201
.bcat(params.bCat())
199202
.badv(params.bAdv())
200-
.regs(initialRegs(params))
203+
.regs(initialRegs(params, consent))
201204
.ext(initialExtRequest(params))
202205
.build();
203206
}
@@ -231,19 +234,21 @@ private static Device initialDevice(GetInterfaceParams params) {
231234
.build();
232235
}
233236

234-
private static User initialUser(GetInterfaceParams params) {
237+
private static User initialUser(GetInterfaceParams params, Consent consent) {
235238
return User.builder()
239+
.consent(consent.getTcfConsent())
236240
.ext(ExtUser.builder()
237241
.consentedProvidersSettings(ConsentedProvidersSettings.of(params.consentedProviders()))
238242
.build())
239243
.build();
240244
}
241245

242-
private static Regs initialRegs(GetInterfaceParams params) {
246+
private static Regs initialRegs(GetInterfaceParams params, Consent consent) {
243247
return Regs.builder()
244248
.coppa(params.coppa())
245249
.gdpr(params.gdpr())
246-
.usPrivacy(params.usPrivacy())
250+
.usPrivacy(consent.getUsPrivacy())
251+
.gpp(consent.getGpp())
247252
.gppSid(params.gppSid())
248253
.ext(ExtRegs.of(null, null, params.gpc(), null))
249254
.build();
@@ -706,32 +711,58 @@ public Integer targeting() {
706711
return null; // TODO: GET
707712
}
708713

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);
713744
}
714745

715746
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+
}
720751

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+
};
723757
}
724758

725759
public String consentedProviders() {
726760
return getString("addtl_consent");
727761
}
728762

729-
public Integer consentType() {
730-
return getInteger("consent_type");
731-
}
732-
733763
public List<Integer> gppSid() {
734-
return getListOfIntegers("gpp_sid");
764+
return Optional.ofNullable(getListOfIntegers("gpps"))
765+
.orElseGet(() -> getListOfIntegers("gpp_sid"));
735766
}
736767

737768
public Integer coppa() {
@@ -868,4 +899,14 @@ private List<Integer> getListOfIntegers(String key) {
868899
: null;
869900
}
870901
}
902+
903+
@Value(staticConstructor = "of")
904+
private static class Consent {
905+
906+
String tcfConsent;
907+
908+
String usPrivacy;
909+
910+
String gpp;
911+
}
871912
}

0 commit comments

Comments
 (0)