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 @@ -6,7 +6,7 @@
import lombok.Value;
import org.prebid.server.activity.infrastructure.ActivityInfrastructure;
import org.prebid.server.auction.gpp.model.GppContext;
import org.prebid.server.bidder.UsersyncMethodType;
import org.prebid.server.bidder.Usersyncer;
import org.prebid.server.cookie.UidsCookie;
import org.prebid.server.execution.timeout.Timeout;
import org.prebid.server.privacy.model.PrivacyContext;
Expand All @@ -27,10 +27,10 @@ public class SetuidContext {

Account account;

String cookieName;
String bidder;

@JsonIgnore
UsersyncMethodType syncType;
Usersyncer usersyncer;

PrivacyContext privacyContext;

Expand Down
100 changes: 0 additions & 100 deletions src/main/java/org/prebid/server/bidder/UsersyncInfoBuilder.java

This file was deleted.

102 changes: 102 additions & 0 deletions src/main/java/org/prebid/server/bidder/UsersyncInfoFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.prebid.server.bidder;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.privacy.model.Privacy;
import org.prebid.server.proto.response.UsersyncInfo;
import org.prebid.server.util.HttpUtil;

import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class UsersyncInfoFactory {

private static final String CALLBACK_URL_TEMPLATE = """
{{base_url}}/setuid?\
bidder={{bidder}}\
&gdpr={{gdpr}}\
&gdpr_consent={{gdpr_consent}}\
&us_privacy={{us_privacy}}\
&gpp={{gpp}}\
&gpp_sid={{gpp_sid}}\
&f={{format}}\
&uid={{uid}}""";

private static final String BASE_URL_PLACEHOLDER = "{{base_url}}";
private static final String BIDDER_PLACEHOLDER = "{{bidder}}";
private static final String GDPR_PLACEHOLDER = "{{gdpr}}";
private static final String GDPR_CONSENT_PLACEHOLDER = "{{gdpr_consent}}";
private static final String US_PRIVACY_PLACEHOLDER = "{{us_privacy}}";
private static final String GPP_PLACEHOLDER = "{{gpp}}";
private static final String GPP_SID_PLACEHOLDER = "{{gpp_sid}}";
private static final String REDIRECT_URL_PLACEHOLDER = "{{redirect_url}}";
private static final String FORMAT_PLACEHOLDER = "{{format}}";
private static final String UID_PLACEHOLDER = "{{uid}}";

private final String externalUrl;

public UsersyncInfoFactory(String externalUrl) {
this.externalUrl = HttpUtil.validateUrl(Objects.requireNonNull(externalUrl));
}

public UsersyncInfo build(String bidder,
String hostCookieUid,
UsersyncMethod usersyncMethod,
Privacy privacy) {

final String usersyncUrl = hostCookieUid == null
? StringUtils.defaultString(usersyncMethod.getUsersyncUrl())
: buildRedirectUrl(bidder, hostCookieUid, usersyncMethod);

final String redirectUrl = hostCookieUid == null
? buildRedirectUrl(bidder, usersyncMethod.getUidMacro(), usersyncMethod)
: StringUtils.EMPTY;

final Map<String, String> privacyParams = preparePrivacyParams(privacy);
final String usersyncUrlWithPrivacy = applyParams(usersyncUrl, encodeParams(privacyParams));
final String redirectUrlWithPrivacy = applyParams(redirectUrl, privacyParams);

final String finalUrl = usersyncUrlWithPrivacy.replace(
REDIRECT_URL_PLACEHOLDER, HttpUtil.encodeUrl(redirectUrlWithPrivacy));

return UsersyncInfo.of(finalUrl, usersyncMethod.getType(), usersyncMethod.isSupportCORS());
}

private String buildRedirectUrl(String bidder, String uid, UsersyncMethod method) {
return CALLBACK_URL_TEMPLATE
.replace(BASE_URL_PLACEHOLDER, externalUrl)
.replace(BIDDER_PLACEHOLDER, HttpUtil.encodeUrl(bidder))
.replace(UID_PLACEHOLDER, StringUtils.defaultString(uid))
.replace(FORMAT_PLACEHOLDER, resolveFormat(method).name);
}

private static UsersyncFormat resolveFormat(UsersyncMethod method) {
return ObjectUtils.firstNonNull(method.getFormatOverride(), method.getType().format);
}

private static Map<String, String> preparePrivacyParams(Privacy privacy) {
return Map.of(
GDPR_PLACEHOLDER, StringUtils.defaultString(privacy.getGdpr()),
GDPR_CONSENT_PLACEHOLDER, StringUtils.defaultString(privacy.getConsentString()),
US_PRIVACY_PLACEHOLDER, StringUtils.defaultString(privacy.getCcpa().getUsPrivacy()),
GPP_PLACEHOLDER, StringUtils.defaultString(privacy.getGpp()),
GPP_SID_PLACEHOLDER, CollectionUtils.emptyIfNull(privacy.getGppSid()).stream()
.map(String::valueOf)
.collect(Collectors.joining(",")));
}

private static Map<String, String> encodeParams(Map<String, String> params) {
return params.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> HttpUtil.encodeUrl(entry.getValue())));
}

private static String applyParams(String url, Map<String, String> params) {
String result = url;
for (Map.Entry<String, String> param: params.entrySet()) {
result = result.replace(param.getKey(), param.getValue());
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/prebid/server/bidder/UsersyncMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class UsersyncMethod {

String usersyncUrl;

String redirectUrl;
String uidMacro;

boolean supportCORS;

Expand Down
54 changes: 0 additions & 54 deletions src/main/java/org/prebid/server/bidder/UsersyncUtil.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/org/prebid/server/bidder/Usersyncer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.prebid.server.bidder;

import lombok.Value;
import org.prebid.server.spring.config.bidder.model.usersync.CookieFamilySource;

import java.util.List;

Expand All @@ -12,8 +11,6 @@ public class Usersyncer {

String cookieFamilyName;

CookieFamilySource cookieFamilySource;

UsersyncMethod iframe;

UsersyncMethod redirect;
Expand All @@ -31,7 +28,6 @@ public static Usersyncer of(String cookieFamilyName,
return of(
true,
cookieFamilyName,
CookieFamilySource.ROOT,
iframe,
redirect,
skipWhenInGdprScope,
Expand Down
Loading
Loading