Skip to content

Commit

Permalink
[UID2-2831] Send Site's app name in key/sharing and key/bidstream end…
Browse files Browse the repository at this point in the history
…points (#508)

* Send app names in sharing and bidstream endpoints

* Return app names list in key sharing and bidstream calls

* Removed flag for sending site domains

* simplify code and use case sensitive names

* Update tests with minor changes

* Update test

* simplified test code

* remove unnecessary null checks
  • Loading branch information
asloobq authored Apr 24, 2024
1 parent 3155674 commit 83b39fb
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 62 deletions.
2 changes: 1 addition & 1 deletion conf/local-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"optout_partition_interval": 86400,
"client_side_token_generate": true,
"client_side_token_generate_domain_name_check_enabled": true,
"key_sharing_endpoint_provide_site_domain_names": true,
"key_sharing_endpoint_provide_app_names": true,
"client_side_token_generate_log_invalid_http_origins": true,
"salts_expired_shutdown_hours": 12
}
2 changes: 1 addition & 1 deletion conf/local-e2e-docker-public-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"client_side_token_generate": true,
"client_side_token_generate_domain_name_check_enabled": true,
"client_side_token_generate_log_invalid_http_origins": true,
"key_sharing_endpoint_provide_site_domain_names": true,
"key_sharing_endpoint_provide_app_names": true,
"validate_service_links": true,
"optout_s3_bucket": "test-optout-bucket",
"optout_s3_folder": "optout-v2/",
Expand Down
2 changes: 1 addition & 1 deletion conf/local-e2e-public-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"optout_partition_interval": 86400,
"client_side_token_generate": true,
"client_side_token_generate_domain_name_check_enabled": true,
"key_sharing_endpoint_provide_site_domain_names": true,
"key_sharing_endpoint_provide_app_names": true,
"client_side_token_generate_log_invalid_http_origins": true,
"salts_expired_shutdown_hours": 12
}
2 changes: 1 addition & 1 deletion conf/validator-latest-e2e-docker-public-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"client_side_token_generate": true,
"client_side_token_generate_domain_name_check_enabled": true,
"client_side_token_generate_log_invalid_http_origins": true,
"key_sharing_endpoint_provide_site_domain_names": true,
"key_sharing_endpoint_provide_app_names": true,
"validate_service_links": true,
"optout_s3_bucket": "test-optout-bucket",
"optout_s3_folder": "optout-v2/",
Expand Down
39 changes: 25 additions & 14 deletions src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.CorsHandler;
import io.vertx.ext.web.handler.StaticHandler;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -115,8 +116,8 @@ public class UIDOperatorVerticle extends AbstractVerticle {
private final int maxBidstreamLifetimeSeconds;
private final int allowClockSkewSeconds;
protected int maxSharingLifetimeSeconds;
protected boolean keySharingEndpointProvideSiteDomainNames;
protected Map<Integer, Set<String>> siteIdToInvalidOriginsAndAppNames = new HashMap<>();
protected boolean keySharingEndpointProvideAppNames;
protected Instant lastInvalidOriginProcessTime = Instant.now();

public UIDOperatorVerticle(JsonObject config,
Expand Down Expand Up @@ -153,7 +154,7 @@ public UIDOperatorVerticle(JsonObject config,
this.phoneSupport = config.getBoolean("enable_phone_support", true);
this.tcfVendorId = config.getInteger("tcf_vendor_id", 21);
this.cstgDoDomainNameCheck = config.getBoolean("client_side_token_generate_domain_name_check_enabled", true);
this.keySharingEndpointProvideSiteDomainNames = config.getBoolean("key_sharing_endpoint_provide_site_domain_names", false);
this.keySharingEndpointProvideAppNames = config.getBoolean("key_sharing_endpoint_provide_app_names", false);
this._statsCollectorQueue = statsCollectorQueue;
this.clientKeyProvider = clientKeyProvider;
this.clientSideTokenGenerateLogInvalidHttpOrigin = config.getBoolean("client_side_token_generate_log_invalid_http_origins", false);
Expand Down Expand Up @@ -670,7 +671,7 @@ private void addBidstreamHeaderFields(JsonObject resp) {
}

private void addSites(JsonObject resp, List<KeysetKey> keys, Map<Integer, Keyset> keysetMap) {
final List<Site> sites = getSitesWithDomainNames(keys, keysetMap);
final List<Site> sites = getSitesWithDomainOrAppNames(keys, keysetMap);
if (sites != null) {
/*
The end result will look something like this:
Expand All @@ -686,14 +687,16 @@ private void addSites(JsonObject resp, List<KeysetKey> keys, Map<Integer, Keyset
{
"id": 102,
"domain_names": [
"102.co.uk",
"102.com"
"101.co.uk",
"101.com",
"com.uid2.operator",
"123456789"
]
}
]
*/
final List<JsonObject> sitesJson = sites.stream()
.map(UIDOperatorVerticle::toJson)
.map(site -> UIDOperatorVerticle.toJson(site, keySharingEndpointProvideAppNames))
.collect(Collectors.toList());
resp.put("site_data", sitesJson);
}
Expand Down Expand Up @@ -732,12 +735,9 @@ private void addAllowClockSkewSecondsField(JsonObject resp) {
resp.put("allow_clock_skew_seconds", allowClockSkewSeconds);
}

private List<Site> getSitesWithDomainNames(List<KeysetKey> keys, Map<Integer, Keyset> keysetMap) {
private List<Site> getSitesWithDomainOrAppNames(List<KeysetKey> keys, Map<Integer, Keyset> keysetMap) {
//without cstg enabled, operator won't have site data and siteProvider could be null
//and adding keySharingEndpointProvideSiteDomainNames in case something goes wrong
//and we can still enable cstg feature but turn off site domain name download in
// key/sharing endpoint
if (!keySharingEndpointProvideSiteDomainNames || !clientSideTokenGenerate) {
if (!clientSideTokenGenerate) {
return null;
}

Expand All @@ -747,18 +747,29 @@ private List<Site> getSitesWithDomainNames(List<KeysetKey> keys, Map<Integer, Ke
.distinct()
.mapToObj(siteProvider::getSite)
.filter(Objects::nonNull)
.filter(site -> !site.getDomainNames().isEmpty())
.filter(site -> {
if (CollectionUtils.isNotEmpty(site.getDomainNames())) {
return true;
} else {
return keySharingEndpointProvideAppNames && CollectionUtils.isNotEmpty(site.getAppNames());
}
})
.collect(Collectors.toList());
}

/**
* Converts the specified site to a JSON object.
* Includes the following fields: id, domain_names.
*/
private static JsonObject toJson(Site site) {
private static JsonObject toJson(Site site, boolean includeAppNames) {
JsonObject siteObj = new JsonObject();
siteObj.put("id", site.getId());
siteObj.put("domain_names", site.getDomainNames().stream().sorted().collect(Collectors.toList()));
Set<String> domainOrAppNames = new HashSet<>(site.getDomainNames());

if (includeAppNames) {
domainOrAppNames.addAll(site.getAppNames());
}
siteObj.put("domain_names", domainOrAppNames.stream().sorted().collect(Collectors.toList()));
return siteObj;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@
"created": 1609459200,
"activates": 1609469200,
"expires": 4088629662
},
{
"id": 11,
"keyset_id": 901,
"secret": "YgyxOX4yX1gYhCINq7O9XxM6jX+etXqSXluZxjB1aG1=",
"created": 1713225363,
"activates": 1713250563,
"expires": 1715756163
}
]
9 changes: 9 additions & 0 deletions src/main/resources/com.uid2.core/test/keysets/keysets.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,14 @@
"keyset_id": 801,
"name": "My keyset #5",
"site_id": 8
},
{
"site_id": 127,
"name": "App Name Test Site Key Set 1",
"keyset_id": 901,
"default": true,
"created": 1713225363,
"enabled": true,
"allowed_sites": [123]
}
]
7 changes: 7 additions & 0 deletions src/main/resources/com.uid2.core/test/sites/sites.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
"id": 126,
"name": "AWS Venice",
"enabled": true
},
{
"id": 127,
"name": "App Name Test Site",
"enabled": true,
"app_names" : ["com.UID2.operator.TEST", "13456789"],
"domain_names" : ["example.com", "unifiedid.com"]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public IUIDOperatorService getIdService() {
return this.idService;
}

public void setKeySharingEndpointProvideSiteDomainNames(boolean enable) {
this.keySharingEndpointProvideSiteDomainNames = enable;
public void setKeySharingEndpointProvideAppNames(boolean enable) {
this.keySharingEndpointProvideAppNames = enable;
}

public void setMaxSharingLifetimeSeconds(int maxSharingLifetimeSeconds) {
Expand Down
Loading

0 comments on commit 83b39fb

Please sign in to comment.