Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public PrivacyModule from(PrivacyModuleCreationContext creationContext) {

final List<PrivacyModule> innerPrivacyModules = SetUtils.emptyIfNull(scope.getSectionsIds()).stream()
.filter(sectionId -> !shouldSkip(sectionId, moduleConfig))
.map(sectionId -> forSection(creationContext.getActivity(), sectionId, scope.getGppModel()))
.map(sectionId -> forSection(
creationContext.getActivity(),
sectionId,
scope.getGppModel(),
moduleConfig.getConfig()))
.toList();

return new AndPrivacyModules(innerPrivacyModules);
Expand All @@ -61,7 +65,11 @@ private static boolean shouldSkip(Integer sectionId, AccountUSNatModuleConfig mo
|| (skipSectionIds != null && skipSectionIds.contains(sectionId));
}

private PrivacyModule forSection(Activity activity, Integer sectionId, GppModel gppModel) {
return new USNatModule(activity, gppReaderFactory.forSection(sectionId, gppModel));
private PrivacyModule forSection(Activity activity,
Integer sectionId,
GppModel gppModel,
AccountUSNatModuleConfig.Config config) {

return new USNatModule(activity, gppReaderFactory.forSection(sectionId, gppModel), config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.USNatSyncUser;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.USNatTransmitGeo;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.USNatTransmitUfpd;
import org.prebid.server.settings.model.activity.privacy.AccountUSNatModuleConfig;

import java.util.Objects;

public class USNatModule implements PrivacyModule, Loggable {

private final PrivacyModule innerModule;

public USNatModule(Activity activity, USNatGppReader gppReader) {
public USNatModule(Activity activity, USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
Objects.requireNonNull(activity);
Objects.requireNonNull(gppReader);

innerModule = innerModule(activity, gppReader);
innerModule = innerModule(activity, gppReader, config);
}

private static PrivacyModule innerModule(Activity activity, USNatGppReader gppReader) {
private static PrivacyModule innerModule(Activity activity,
USNatGppReader gppReader,
AccountUSNatModuleConfig.Config config) {

return switch (activity) {
case SYNC_USER, MODIFY_UFDP -> new USNatSyncUser(gppReader);
case TRANSMIT_UFPD, TRANSMIT_EIDS -> new USNatTransmitUfpd(gppReader);
case TRANSMIT_GEO -> new USNatTransmitGeo(gppReader);
case SYNC_USER, MODIFY_UFDP -> new USNatSyncUser(gppReader, config);
case TRANSMIT_UFPD, TRANSMIT_EIDS -> new USNatTransmitUfpd(gppReader, config);
case TRANSMIT_GEO -> new USNatTransmitGeo(gppReader, config);
case CALL_BIDDER, TRANSMIT_TID, REPORT_ANALYTICS -> USNatDefault.instance();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.TargetedAdvertisingOptOut;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.TargetedAdvertisingOptOutNotice;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.USNatField;
import org.prebid.server.settings.model.activity.privacy.AccountUSNatModuleConfig;

import java.util.List;
import java.util.Objects;
Expand All @@ -28,25 +29,25 @@ public class USNatSyncUser implements PrivacyModule, Loggable {
private final USNatGppReader gppReader;
private final Result result;

public USNatSyncUser(USNatGppReader gppReader) {
public USNatSyncUser(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
this.gppReader = gppReader;

result = disallow(gppReader) ? Result.DISALLOW : Result.ALLOW;
result = disallow(gppReader, config) ? Result.DISALLOW : Result.ALLOW;
}

@Override
public Result proceed(ActivityInvocationPayload activityInvocationPayload) {
return result;
}

public static boolean disallow(USNatGppReader gppReader) {
public static boolean disallow(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return equals(gppReader.getMspaServiceProviderMode(), MspaServiceProviderMode.YES)
|| equals(gppReader.getGpc(), Gpc.TRUE)
|| checkSale(gppReader)
|| checkSharing(gppReader)
|| checkTargetedAdvertising(gppReader)
|| checkKnownChildSensitiveDataConsents(gppReader)
|| equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
|| checkPersonalDataConsents(gppReader, config);
}

private static boolean checkSale(USNatGppReader gppReader) {
Expand Down Expand Up @@ -91,6 +92,11 @@ private static boolean checkKnownChildSensitiveDataConsents(USNatGppReader gppRe
|| equalsAtIndex(KnownChildSensitiveDataConsent.CONSENT, knownChildSensitiveDataConsents, 1);
}

private static boolean checkPersonalDataConsents(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return (config == null || !config.isAllowPersonalDataConsent2())
&& equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
}

private static <T> boolean equalsAtIndex(USNatField<T> expectedValue, List<T> list, int index) {
return list != null && list.size() > index && equals(list.get(index), expectedValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.SensitiveDataProcessing;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.SensitiveDataProcessingOptOutNotice;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.USNatField;
import org.prebid.server.settings.model.activity.privacy.AccountUSNatModuleConfig;

import java.util.List;
import java.util.Objects;
Expand All @@ -24,23 +25,23 @@ public class USNatTransmitGeo implements PrivacyModule, Loggable {
private final USNatGppReader gppReader;
private final Result result;

public USNatTransmitGeo(USNatGppReader gppReader) {
public USNatTransmitGeo(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
this.gppReader = gppReader;

result = disallow(gppReader) ? Result.DISALLOW : Result.ALLOW;
result = disallow(gppReader, config) ? Result.DISALLOW : Result.ALLOW;
}

@Override
public Result proceed(ActivityInvocationPayload activityInvocationPayload) {
return result;
}

public static boolean disallow(USNatGppReader gppReader) {
public static boolean disallow(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return equals(gppReader.getMspaServiceProviderMode(), MspaServiceProviderMode.YES)
|| equals(gppReader.getGpc(), Gpc.TRUE)
|| checkSensitiveData(gppReader)
|| checkKnownChildSensitiveDataConsents(gppReader)
|| equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
|| checkPersonalDataConsents(gppReader, config);
}

private static boolean checkSensitiveData(USNatGppReader gppReader) {
Expand All @@ -64,6 +65,11 @@ private static boolean checkKnownChildSensitiveDataConsents(USNatGppReader gppRe
|| equalsAtIndex(KnownChildSensitiveDataConsent.CONSENT, knownChildSensitiveDataConsents, 1);
}

private static boolean checkPersonalDataConsents(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return (config == null || !config.isAllowPersonalDataConsent2())
&& equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
}

private static <T> boolean equalsAtIndex(USNatField<T> expectedValue, List<T> list, int index) {
return list != null && list.size() > index && equals(list.get(index), expectedValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.TargetedAdvertisingOptOut;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.TargetedAdvertisingOptOutNotice;
import org.prebid.server.activity.infrastructure.privacy.usnat.inner.model.USNatField;
import org.prebid.server.settings.model.activity.privacy.AccountUSNatModuleConfig;

import java.util.List;
import java.util.Objects;
Expand All @@ -36,26 +37,26 @@ public class USNatTransmitUfpd implements PrivacyModule, Loggable {
private final USNatGppReader gppReader;
private final Result result;

public USNatTransmitUfpd(USNatGppReader gppReader) {
public USNatTransmitUfpd(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
this.gppReader = gppReader;

result = disallow(gppReader) ? Result.DISALLOW : Result.ALLOW;
result = disallow(gppReader, config) ? Result.DISALLOW : Result.ALLOW;
}

@Override
public Result proceed(ActivityInvocationPayload activityInvocationPayload) {
return result;
}

public static boolean disallow(USNatGppReader gppReader) {
public static boolean disallow(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return equals(gppReader.getMspaServiceProviderMode(), MspaServiceProviderMode.YES)
|| equals(gppReader.getGpc(), Gpc.TRUE)
|| checkSale(gppReader)
|| checkSharing(gppReader)
|| checkTargetedAdvertising(gppReader)
|| checkSensitiveData(gppReader)
|| checkKnownChildSensitiveDataConsents(gppReader)
|| equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
|| checkPersonalDataConsents(gppReader, config);
}

private static boolean checkSale(USNatGppReader gppReader) {
Expand Down Expand Up @@ -127,6 +128,11 @@ private static boolean checkKnownChildSensitiveDataConsents(USNatGppReader gppRe
|| equalsAtIndex(KnownChildSensitiveDataConsent.CONSENT, knownChildSensitiveDataConsents, 1);
}

private static boolean checkPersonalDataConsents(USNatGppReader gppReader, AccountUSNatModuleConfig.Config config) {
return (config == null || !config.isAllowPersonalDataConsent2())
&& equals(gppReader.getPersonalDataConsents(), PersonalDataConsents.CONSENT);
}

private static <T> boolean anyEqualsAtIndices(USNatField<T> expectedValue, List<T> list, Set<Integer> indices) {
return indices.stream().anyMatch(index -> equalsAtIndex(expectedValue, list, index));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ public static class Config {
@JsonProperty("skip_sids")
@JsonAlias({"skipSids", "skip-sids"})
List<Integer> skipSids;

@JsonProperty("allow_personal_data_consent_2")
@JsonAlias({"allowPersonalDataConsent2", "allow-personal-data-consent-2"})
boolean allowPersonalDataConsent2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class GppModuleConfig {
List<GppSectionId> skipSidsSnakeCase
@JsonProperty("skip-sids")
List<GppSectionId> skipSidsKebabCase
Boolean allowPersonalDataConsent2
@JsonProperty("allow_personal_data_consent_2")
Boolean allowPersonalDataConsent2SnakeCase
@JsonProperty("allow-personal-data-consent-2")
Boolean allowPersonalDataConsent2KebabCase

static GppModuleConfig getDefaultModuleConfig(ActivityConfig activityConfig = ActivityConfig.configWithDefaultRestrictRules,
List<GppSectionId> sids = [GppSectionId.US_NAT_V1],
Expand All @@ -35,8 +40,8 @@ class GppModuleConfig {
}

static GppModuleConfig getDefaultModuleConfigSnakeCase(ActivityConfig activityConfig = ActivityConfig.configWithDefaultRestrictRules,
List<GppSectionId> sids = [GppSectionId.US_NAT_V1],
Boolean normalizeFlags = true) {
List<GppSectionId> sids = [GppSectionId.US_NAT_V1],
Boolean normalizeFlags = true) {
new GppModuleConfig().tap {
it.activityConfigSnakeCase = [activityConfig]
it.sids = sids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,7 @@ class GppFetchBidActivitiesSpec extends PrivacyBaseSpec {
}

and: "Activities set for fetchBid with rejecting privacy regulation"
def rule = new ActivityRule().tap {
it.privacyRegulation = [privacyAllowRegulations]
}

def rule = new ActivityRule(privacyRegulation: [privacyAllowRegulations])
def activities = AllowActivities.getDefaultAllowActivities(FETCH_BIDS, Activity.getDefaultActivity([rule]))

and: "Account gpp configuration"
Expand Down Expand Up @@ -1312,9 +1309,7 @@ class GppFetchBidActivitiesSpec extends PrivacyBaseSpec {
}

and: "Activities set for fetchBid with allowing privacy regulation"
def rule = new ActivityRule().tap {
it.privacyRegulation = [privacyAllowRegulations]
}
def rule = new ActivityRule(privacyRegulation: [privacyAllowRegulations])

def activities = AllowActivities.getDefaultAllowActivities(FETCH_BIDS, Activity.getDefaultActivity([rule]))

Expand Down
Loading
Loading