Skip to content

Commit

Permalink
Feature: Default account DSA support (#2955)
Browse files Browse the repository at this point in the history
  • Loading branch information
Net-burst authored Feb 12, 2024
1 parent 774166d commit aaa4cc7
Show file tree
Hide file tree
Showing 34 changed files with 1,055 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import com.iab.openrtb.request.Dooh;
import com.iab.openrtb.request.Geo;
import com.iab.openrtb.request.Publisher;
import com.iab.openrtb.request.Regs;
import com.iab.openrtb.request.Site;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.RoutingContext;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.activity.infrastructure.ActivityInfrastructure;
Expand Down Expand Up @@ -52,15 +54,21 @@
import org.prebid.server.proto.openrtb.ext.FlexibleExtension;
import org.prebid.server.proto.openrtb.ext.request.ExtPublisher;
import org.prebid.server.proto.openrtb.ext.request.ExtPublisherPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRegs;
import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsa;
import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsaTransparency;
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestTargeting;
import org.prebid.server.proto.openrtb.ext.request.TraceLevel;
import org.prebid.server.settings.ApplicationSettings;
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.AccountAuctionConfig;
import org.prebid.server.settings.model.AccountDsaConfig;
import org.prebid.server.settings.model.AccountPrivacyConfig;
import org.prebid.server.settings.model.AccountStatus;
import org.prebid.server.settings.model.AccountTargetingConfig;
import org.prebid.server.settings.model.DefaultDsa;
import org.prebid.server.util.HttpUtil;
import org.prebid.server.util.ObjectUtil;
import org.prebid.server.validation.RequestValidator;
Expand Down Expand Up @@ -217,16 +225,69 @@ public BidRequest enrichBidRequestWithAccountAndPrivacyData(AuctionContext aucti
final Device device = bidRequest.getDevice();
final Device enrichedDevice = enrichDevice(device, privacyContext);

if (enrichedRequestExt != null || enrichedDevice != null) {
final Regs regs = bidRequest.getRegs();
final Regs enrichedRegs = enrichRegs(regs, privacyContext, account);

if (enrichedRequestExt != null || enrichedDevice != null || enrichedRegs != null) {
return bidRequest.toBuilder()
.ext(ObjectUtils.defaultIfNull(enrichedRequestExt, requestExt))
.device(ObjectUtils.defaultIfNull(enrichedDevice, device))
.regs(ObjectUtils.defaultIfNull(enrichedRegs, regs))
.build();
}

return bidRequest;
}

private static Regs enrichRegs(Regs regs, PrivacyContext privacyContext, Account account) {
final ExtRegs regsExt = regs != null ? regs.getExt() : null;
final ExtRegsDsa regsExtDsa = regsExt != null ? regsExt.getDsa() : null;
if (regsExtDsa != null) {
return null;
}

final AccountDsaConfig accountDsaConfig = Optional.ofNullable(account)
.map(Account::getPrivacy)
.map(AccountPrivacyConfig::getDsa)
.orElse(null);
final DefaultDsa defaultDsa = accountDsaConfig != null ? accountDsaConfig.getDefaultDsa() : null;
if (defaultDsa == null) {
return null;
}

final boolean isGdprOnly = BooleanUtils.isTrue(accountDsaConfig.getGdprOnly());
if (isGdprOnly && !privacyContext.getTcfContext().isInGdprScope()) {
return null;
}

return Optional.ofNullable(regs)
.map(Regs::toBuilder)
.orElseGet(Regs::builder)
.ext(mapRegsExtDsa(defaultDsa, regsExt))
.build();
}

private static ExtRegs mapRegsExtDsa(DefaultDsa defaultDsa, ExtRegs regsExt) {
final List<ExtRegsDsaTransparency> enrichedDsaTransparencies = defaultDsa.getTransparency()
.stream()
.map(dsaTransparency -> ExtRegsDsaTransparency.of(
dsaTransparency.getDomain(), dsaTransparency.getDsaParams()))
.toList();

final ExtRegsDsa enrichedRegsExtDsa = ExtRegsDsa.of(
defaultDsa.getDsaRequired(),
defaultDsa.getPubRender(),
defaultDsa.getDataToPub(),
enrichedDsaTransparencies);

final boolean isRegsExtPresent = regsExt != null;
return ExtRegs.of(
isRegsExtPresent ? regsExt.getGdpr() : null,
isRegsExtPresent ? regsExt.getUsPrivacy() : null,
isRegsExtPresent ? regsExt.getGpc() : null,
enrichedRegsExtDsa);
}

public Future<HttpRequestContext> executeEntrypointHooks(RoutingContext routingContext,
String body,
AuctionContext auctionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private Account validateAndModifyAccount(Account account) {
.privacy(AccountPrivacyConfig.of(
accountPrivacyConfig.getGdpr(),
accountPrivacyConfig.getCcpa(),
accountPrivacyConfig.getDsa(),
AccountActivitiesConfigurationUtils
.removeInvalidRules(accountPrivacyConfig.getActivities()),
accountPrivacyConfig.getModules()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.prebid.server.settings.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

@Value(staticConstructor = "of")
public class AccountDsaConfig {

@JsonProperty("default")
DefaultDsa defaultDsa;

@JsonProperty("gdpr-only")
Boolean gdprOnly;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class AccountPrivacyConfig {

AccountCcpaConfig ccpa;

AccountDsaConfig dsa;

@JsonProperty("allowactivities")
Map<Activity, AccountActivityConfiguration> activities;

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/prebid/server/settings/model/DefaultDsa.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.prebid.server.settings.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

import java.util.List;

@Value(staticConstructor = "of")
public class DefaultDsa {

@JsonProperty("dsarequired")
Integer dsaRequired;

@JsonProperty("pubrender")
Integer pubRender;

@JsonProperty("datatopub")
Integer dataToPub;

List<DsaTransparency> transparency;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.settings.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

import java.util.List;

@Value(staticConstructor = "of")
public class DsaTransparency {

String domain;

@JsonProperty("dsaparams")
List<Integer> dsaParams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.prebid.server.functional.model.config

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.model.request.auction.Dsa

@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy)
@ToString(includeNames = true, ignoreNulls = true)
class AccountDsaConfig {

@JsonProperty("default")
Dsa defaultDsa
Boolean gdprOnly
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AccountPrivacyConfig {

AccountGdprConfig gdpr
AccountCcpaConfig ccpa
AccountDsaConfig dsa
@JsonProperty("allowactivities")
AllowActivities allowActivities
List<AccountGppConfig> modules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@EqualsAndHashCode
@ToString(includeNames = true, ignoreNulls = true)
class Dsa {

DsaRequired dsaRequired
DsaPubRender pubRender
DsaDataToPub dataToPub
List<DsaTransparency> transparency

static Dsa getDefaultDsa(DsaRequired dsaRequired = PBSUtils.getRandomEnum(DsaRequired)) {
new Dsa(dsaRequired: dsaRequired,
pubRender: PBSUtils.getRandomEnum(DsaPubRender),
dataToPub: PBSUtils.getRandomEnum(DsaDataToPub),
transparency: [DsaTransparency.defaultDsaTransparency])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonValue
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
enum DsaDataToPub {

DO_NOT_SEND_TRANSPARENCY(0),
OPTIONAL_TO_SEND(1),
SEND_TRANSPARENCY(2)

@JsonValue
final int value

private DsaDataToPub(int value) {
this.value = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonValue
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
enum DsaPubRender {

PUB_CANT_RENDER(0),
PUB_MIGHT_RENDER(1),
PUB_WILL_RENDER(2)

@JsonValue
final int value

private DsaPubRender(int value) {
this.value = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonValue
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
enum DsaRequired {

NOT_REQUIRED(0),
SUPPORTED(1),
REQUIRED(2),
REQUIRED_PUBLISHER_IS_ONLINE_PLATFORM(3)

@JsonValue
final int value

private DsaRequired(int value) {
this.value = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@EqualsAndHashCode
@ToString(includeNames = true, ignoreNulls = true)
class DsaTransparency {

String domain
List<Integer> dsaParams
List<DsaTransparencyParam> dsaParams

static DsaTransparency getDefaultRegsDsaTransparency() {
static DsaTransparency getDefaultDsaTransparency() {
new DsaTransparency(domain: PBSUtils.randomString)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.annotation.JsonValue
import groovy.transform.ToString

@ToString(includeNames = true, ignoreNulls = true)
enum DsaTransparencyParam {

PROFILING(1),
BASIC_ADVERTISING(2),
PRECISE_GEO(3)

@JsonValue
final int value

private DsaTransparencyParam(int value) {
this.value = value
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +0,0 @@
package org.prebid.server.functional.model.request.auction

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming
import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@JsonNaming(PropertyNamingStrategies.LowerCaseStrategy)
@ToString(includeNames = true, ignoreNulls = true)
class RegsDsa {

Integer dsaRequired
Integer pubRender
Integer dataToPub
List<DsaTransparency> transparency

static RegsDsa getDefaultRegsDsa(ReqsDsaRequiredType required) {
new RegsDsa(
dsaRequired: required.value,
pubRender: PBSUtils.getRandomNumber(0, 2),
dataToPub: PBSUtils.getRandomNumber(0, 2),
transparency: [DsaTransparency.defaultRegsDsaTransparency]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ class RegsExt {
Integer gdpr
String usPrivacy
String gpc
RegsDsa dsa

Dsa dsa
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ class BidExt {
Prebid prebid
BigDecimal origbidcpm
Currency origbidcur
BidExtDsa dsa

Dsa dsa
}
Loading

0 comments on commit aaa4cc7

Please sign in to comment.