Skip to content

Commit

Permalink
Enforce opt-out policy check
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiweidu committed Sep 11, 2023
1 parent 8cfe605 commit 013f5bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public static TokenGeneratePolicy fromValue(int value) {
public static TokenGeneratePolicy defaultPolicy() {
return JustGenerate;
}

public static TokenGeneratePolicy respectOptOut() {
return RespectOptOut;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,13 @@ 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");
return;
}

final TokenGeneratePolicy tokenGeneratePolicy = readTokenGeneratePolicy(req);
final IdentityTokens t = this.idService.generateIdentity(
new IdentityRequest(
Expand Down Expand Up @@ -1636,6 +1643,11 @@ private TokenGeneratePolicy readTokenGeneratePolicy(JsonObject req) {
TokenGeneratePolicy.defaultPolicy();
}

private boolean isAfterCutoffDate(long timestamp) {
long cutoff = Instant.parse("2023-09-01T00:00:00.00Z").getEpochSecond();
return timestamp >= cutoff;
}

private static final String IDENTITY_MAP_POLICY_PARAM = "policy";

private IdentityMapPolicy readIdentityMapPolicy(JsonObject req) {
Expand Down

0 comments on commit 013f5bf

Please sign in to comment.