-
Notifications
You must be signed in to change notification settings - Fork 224
Core: EID Permissions extension #4349
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a3153a7
EID Permissions extension
Net-burst 9a711eb
Minor refactoring
Net-burst e49d0ff
Simplification refactoring
Net-burst ab462db
Merge branch 'refs/heads/master' into feature/extend-eid-permissions
Net-burst 86492b5
Refactor
Lightwood13 5372661
Refactoring.
And1sS 6823ce6
Refactoring.
And1sS 5018a0a
Refactored unit tests.
And1sS 47844e0
Tests: EID Permissions extension (#4357)
osulzhenko ae8cace
minor test fix
osulzhenko 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
81 changes: 81 additions & 0 deletions
81
src/main/java/org/prebid/server/auction/EidPermissionResolver.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,81 @@ | ||
| package org.prebid.server.auction; | ||
|
|
||
| import com.iab.openrtb.request.Eid; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidDataEidPermissions; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class EidPermissionResolver { | ||
|
|
||
| private static final String WILDCARD_BIDDER = "*"; | ||
|
|
||
| private static final ExtRequestPrebidDataEidPermissions DEFAULT_RULE = ExtRequestPrebidDataEidPermissions.builder() | ||
| .bidders(Collections.singletonList(WILDCARD_BIDDER)) | ||
| .build(); | ||
|
|
||
| private static final EidPermissionResolver EMPTY = new EidPermissionResolver(Collections.emptyList()); | ||
|
|
||
| private final List<ExtRequestPrebidDataEidPermissions> eidPermissions; | ||
|
|
||
| private EidPermissionResolver(List<ExtRequestPrebidDataEidPermissions> eidPermissions) { | ||
| this.eidPermissions = new ArrayList<>(eidPermissions); | ||
| this.eidPermissions.add(DEFAULT_RULE); | ||
| } | ||
|
|
||
| public static EidPermissionResolver of(List<ExtRequestPrebidDataEidPermissions> eidPermissions) { | ||
| return new EidPermissionResolver(eidPermissions); | ||
| } | ||
|
|
||
| public static EidPermissionResolver empty() { | ||
| return EMPTY; | ||
| } | ||
|
|
||
| public List<Eid> resolveAllowedEids(List<Eid> userEids, String bidder) { | ||
| return CollectionUtils.emptyIfNull(userEids) | ||
| .stream() | ||
| .filter(userEid -> isAllowed(userEid, bidder)) | ||
| .toList(); | ||
| } | ||
|
|
||
| private boolean isAllowed(Eid eid, String bidder) { | ||
| final Map<Integer, List<ExtRequestPrebidDataEidPermissions>> matchingRulesBySpecificity = eidPermissions | ||
| .stream() | ||
| .filter(rule -> isRuleMatched(eid, rule)) | ||
| .collect(Collectors.groupingBy(this::getRuleSpecificity)); | ||
|
|
||
| final int highestSpecificityMatchingRules = Collections.max(matchingRulesBySpecificity.keySet()); | ||
| return matchingRulesBySpecificity.get(highestSpecificityMatchingRules).stream() | ||
| .anyMatch(eidPermission -> isBidderAllowed(bidder, eidPermission.getBidders())); | ||
| } | ||
|
|
||
| private int getRuleSpecificity(ExtRequestPrebidDataEidPermissions eidPermission) { | ||
| return (int) Stream.of( | ||
| eidPermission.getInserter(), | ||
| eidPermission.getSource(), | ||
| eidPermission.getMatcher(), | ||
| eidPermission.getMm()) | ||
| .filter(Objects::nonNull) | ||
| .count(); | ||
| } | ||
|
|
||
| private boolean isRuleMatched(Eid eid, ExtRequestPrebidDataEidPermissions eidPermission) { | ||
| return (eidPermission.getInserter() == null || eidPermission.getInserter().equals(eid.getInserter())) | ||
| && (eidPermission.getSource() == null || eidPermission.getSource().equals(eid.getSource())) | ||
| && (eidPermission.getMatcher() == null || eidPermission.getMatcher().equals(eid.getMatcher())) | ||
| && (eidPermission.getMm() == null || eidPermission.getMm().equals(eid.getMm())); | ||
| } | ||
|
|
||
| private boolean isBidderAllowed(String bidder, List<String> ruleBidders) { | ||
| return ruleBidders == null || ruleBidders.stream() | ||
| .anyMatch(allowedBidder -> StringUtils.equalsIgnoreCase(allowedBidder, bidder) | ||
| || WILDCARD_BIDDER.equals(allowedBidder)); | ||
| } | ||
| } | ||
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
27 changes: 23 additions & 4 deletions
27
.../java/org/prebid/server/proto/openrtb/ext/request/ExtRequestPrebidDataEidPermissions.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 |
|---|---|---|
| @@ -1,24 +1,43 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import lombok.Builder; | ||
| import lombok.Value; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions | ||
| */ | ||
| @Value(staticConstructor = "of") | ||
| @Value | ||
| @Builder | ||
| public class ExtRequestPrebidDataEidPermissions { | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions.inserter | ||
| */ | ||
| String inserter; | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions.source | ||
| */ | ||
| String source; | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions.matcher | ||
| */ | ||
| String matcher; | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions.mm | ||
| */ | ||
| Integer mm; | ||
|
|
||
| /** | ||
| * Defines the contract for bidrequest.ext.prebid.data.eidPermissions.bidders | ||
| */ | ||
| @JsonFormat(without = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) | ||
| List<String> bidders; | ||
|
|
||
| @Deprecated | ||
| public static ExtRequestPrebidDataEidPermissions of(String source, List<String> bidders) { | ||
| return new ExtRequestPrebidDataEidPermissions(null, source, null, null, bidders); | ||
| } | ||
And1sS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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 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
30 changes: 29 additions & 1 deletion
30
src/test/groovy/org/prebid/server/functional/model/request/auction/EidPermission.groovy
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 |
|---|---|---|
| @@ -1,11 +1,39 @@ | ||
| package org.prebid.server.functional.model.request.auction | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import groovy.transform.ToString | ||
| import org.prebid.server.functional.model.bidder.BidderName | ||
| import org.prebid.server.functional.util.PBSUtils | ||
|
|
||
| import static org.prebid.server.functional.model.bidder.BidderName.GENERIC | ||
|
|
||
| @ToString(includeNames = true, ignoreNulls = true) | ||
| class EidPermission { | ||
|
|
||
| String source | ||
| List<BidderName> bidders | ||
| String inserter | ||
| String matcher | ||
| @JsonProperty("mm") | ||
| Integer matchMethod | ||
| List<BidderName> bidders = [GENERIC] | ||
|
|
||
| static EidPermission getDefaultEidPermission(List<BidderName> bidders = [GENERIC]) { | ||
| new EidPermission().tap { | ||
| it.source = PBSUtils.randomString | ||
| it.inserter = PBSUtils.randomString | ||
| it.matcher = PBSUtils.randomString | ||
| it.matchMethod = PBSUtils.randomNumber | ||
| it.bidders = bidders | ||
| } | ||
| } | ||
|
|
||
| static EidPermission from(Eid eid, List<BidderName> bidders = [GENERIC]) { | ||
| new EidPermission().tap { | ||
| it.source = eid.source | ||
| it.inserter = eid.inserter | ||
| it.matcher = eid.matcher | ||
| it.matchMethod = eid.matchMethod | ||
| it.bidders = bidders | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.