From 1256174dbc153a899ad04780f57bac5b1081866e Mon Sep 17 00:00:00 2001 From: Zaiwei Du Date: Mon, 11 Sep 2023 13:58:10 -0700 Subject: [PATCH] Enforce opt-out policy check --- .../com/uid2/operator/model/IdentityMapPolicy.java | 4 ++++ .../com/uid2/operator/vertx/UIDOperatorVerticle.java | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/uid2/operator/model/IdentityMapPolicy.java b/src/main/java/com/uid2/operator/model/IdentityMapPolicy.java index 5a29d4df2..10a185152 100644 --- a/src/main/java/com/uid2/operator/model/IdentityMapPolicy.java +++ b/src/main/java/com/uid2/operator/model/IdentityMapPolicy.java @@ -19,4 +19,8 @@ public static com.uid2.operator.model.IdentityMapPolicy fromValue(int value) { public static com.uid2.operator.model.IdentityMapPolicy defaultPolicy() { return JustMap; } + + public static IdentityMapPolicy respectOptOut() { + return RespectOptOut; + } } diff --git a/src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java b/src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java index 1bf3bfe36..c1fc36a78 100644 --- a/src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java +++ b/src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java @@ -780,7 +780,7 @@ private void handleTokenGenerateV2(RoutingContext rc) { if (isAfterCutoffDate(clientKey.getCreated()) && (!req.containsKey(TOKEN_GENERATE_POLICY_PARAM) || TokenGeneratePolicy.fromValue(req.getInteger(TOKEN_GENERATE_POLICY_PARAM)) != TokenGeneratePolicy.respectOptOut())) { LOGGER.error("request body misses opt-out policy argument"); - ResponseUtil.ClientError(rc, "request body misses opt-out policy arguments"); + ResponseUtil.ClientError(rc, "request body misses opt-out policy argument"); return; } @@ -1301,6 +1301,14 @@ private void handleIdentityMapV2(RoutingContext rc) { } } + final ClientKey clientKey = (ClientKey) AuthMiddleware.getAuthClient(rc); + if (isAfterCutoffDate(clientKey.getCreated()) && (!requestJsonObject.containsKey(IDENTITY_MAP_POLICY_PARAM) + || IdentityMapPolicy.fromValue(requestJsonObject.getInteger(IDENTITY_MAP_POLICY_PARAM)) != IdentityMapPolicy.respectOptOut())) { + LOGGER.error("request body misses opt-out policy argument"); + ResponseUtil.ClientError(rc, "request body misses opt-out policy argument"); + return; + } + IdentityMapPolicy identityMapPolicy = readIdentityMapPolicy(requestJsonObject); recordIdentityMapPolicy(getApiContact(rc), identityMapPolicy);