-
Notifications
You must be signed in to change notification settings - Fork 242
Update cookie sync to use bidder name instead of cookie family #4464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Lightwood13
wants to merge
7
commits into
master
Choose a base branch
from
update-cookie-sync-to-use-bidder-name-instead-of-cookie-family
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
310da3f
Update setuid endpoint to accept both bidder names and cookie family …
Lightwood13 7ac551f
Update cookie sync endpoint to return bidder name instead of cookie f…
Lightwood13 522d1c8
Update setuid endpoint to accept only bidder name
Lightwood13 62271c3
Refactor UsersyncInfoBuilder
Lightwood13 bf61d1d
Merge branch 'refs/heads/master' into update-cookie-sync-to-use-bidde…
Lightwood13 410d99a
Merge branch 'refs/heads/master' into update-cookie-sync-to-use-bidde…
Lightwood13 75acdfd
Merge branch 'master' into update-cookie-sync-to-use-bidder-name-inst…
Lightwood13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 0 additions & 100 deletions
100
src/main/java/org/prebid/server/bidder/UsersyncInfoBuilder.java
This file was deleted.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
src/main/java/org/prebid/server/bidder/UsersyncInfoFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package org.prebid.server.bidder; | ||
|
|
||
| import lombok.Value; | ||
| 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.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class UsersyncInfoFactory { | ||
|
|
||
| private static final String CALLBACK_URL_TEMPLATE = """ | ||
| %s/setuid?\ | ||
| bidder=%s\ | ||
| &gdpr={{gdpr}}\ | ||
| &gdpr_consent={{gdpr_consent}}\ | ||
| &us_privacy={{us_privacy}}\ | ||
| &gpp={{gpp}}\ | ||
| &gpp_sid={{gpp_sid}}\ | ||
| &f={{format}}\ | ||
| &uid=%s"""; | ||
|
|
||
| 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 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 UsersyncUrls usersyncUrls = buildUsersyncUrls(bidder, hostCookieUid, usersyncMethod); | ||
| final UsersyncUrls usersyncUrlsWithPrivacy = applyPrivacy(usersyncUrls, privacy); | ||
| final String resolvedUsersyncUrl = usersyncUrlsWithPrivacy.usersyncUrl.replace( | ||
| REDIRECT_URL_PLACEHOLDER, HttpUtil.encodeUrl(usersyncUrlsWithPrivacy.redirectUrl)); | ||
|
|
||
| return UsersyncInfo.of(resolvedUsersyncUrl, usersyncMethod.getType(), usersyncMethod.isSupportCORS()); | ||
| } | ||
|
|
||
| private UsersyncUrls buildUsersyncUrls(String bidder, String hostCookieUid, UsersyncMethod usersyncMethod) { | ||
| 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; | ||
|
|
||
| return UsersyncUrls.of(usersyncUrl, redirectUrl); | ||
| } | ||
|
|
||
| private String buildRedirectUrl(String bidder, String uid, UsersyncMethod method) { | ||
| final String url = CALLBACK_URL_TEMPLATE.formatted( | ||
| externalUrl, HttpUtil.encodeUrl(bidder), StringUtils.defaultString(uid)); | ||
| return url.replace(FORMAT_PLACEHOLDER, resolveFormat(method).name); | ||
| } | ||
|
|
||
| private static UsersyncFormat resolveFormat(UsersyncMethod method) { | ||
| return ObjectUtils.firstNonNull(method.getFormatOverride(), method.getType().format); | ||
| } | ||
|
|
||
| private static UsersyncUrls applyPrivacy(UsersyncUrls usersyncUrls, Privacy privacy) { | ||
| final String gdpr = StringUtils.defaultString(privacy.getGdpr()); | ||
| final String consent = StringUtils.defaultString(privacy.getConsentString()); | ||
| final String ccpa = StringUtils.defaultString(privacy.getCcpa().getUsPrivacy()); | ||
| final String gpp = StringUtils.defaultString(privacy.getGpp()); | ||
| final String gppSid = listToString(privacy.getGppSid()); | ||
|
|
||
| final String redirectUrl = updateUrlWithPrivacy(usersyncUrls.redirectUrl, gdpr, consent, ccpa, gpp, gppSid); | ||
|
|
||
| final String encodedGdpr = HttpUtil.encodeUrl(gdpr); | ||
| final String encodedConsent = HttpUtil.encodeUrl(consent); | ||
| final String encodedUsPrivacy = HttpUtil.encodeUrl(ccpa); | ||
| final String encodedGpp = HttpUtil.encodeUrl(gpp); | ||
| final String endodedGppSid = HttpUtil.encodeUrl(gppSid); | ||
|
|
||
| final String usersyncUrl = updateUrlWithPrivacy( | ||
| usersyncUrls.usersyncUrl, encodedGdpr, encodedConsent, encodedUsPrivacy, encodedGpp, endodedGppSid); | ||
|
|
||
| return UsersyncUrls.of(usersyncUrl, redirectUrl); | ||
| } | ||
|
|
||
| private static String listToString(List<Integer> gppSid) { | ||
| return CollectionUtils.emptyIfNull(gppSid).stream() | ||
| .map(String::valueOf) | ||
| .collect(Collectors.joining(",")); | ||
| } | ||
|
|
||
| private static String updateUrlWithPrivacy(String url, | ||
| String gdpr, | ||
| String gdprConsent, | ||
| String usPrivacy, | ||
| String gpp, | ||
| String gppSid) { | ||
|
|
||
| return url | ||
| .replace(GDPR_PLACEHOLDER, gdpr) | ||
| .replace(GDPR_CONSENT_PLACEHOLDER, gdprConsent) | ||
| .replace(US_PRIVACY_PLACEHOLDER, usPrivacy) | ||
| .replace(GPP_PLACEHOLDER, gpp) | ||
| .replace(GPP_SID_PLACEHOLDER, gppSid); | ||
| } | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| private static class UsersyncUrls { | ||
| String usersyncUrl; | ||
| String redirectUrl; | ||
| } | ||
|
Comment on lines
+119
to
+123
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%s->{{MACRO}}