Skip to content

Commit 51b90c5

Browse files
committed
Merge branch 'main' into aul-UID2-5549-ui-refactor
# Conflicts: # pom.xml # webroot/adm/salt.html # webroot/adm/service.html # webroot/js/participantSummary.js
2 parents 85c52a4 + b737f46 commit 51b90c5

File tree

11 files changed

+570
-308
lines changed

11 files changed

+570
-308
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.uid2</groupId>
88
<artifactId>uid2-admin</artifactId>
9-
<version>6.3.1-alpha-187-SNAPSHOT</version>
9+
<version>6.5.7</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -16,7 +16,7 @@
1616
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
1717
<micrometer.version>1.12.2</micrometer.version>
1818
<junit-jupiter.version>5.11.2</junit-jupiter.version>
19-
<uid2-shared.version>10.1.0</uid2-shared.version>
19+
<uid2-shared.version>10.3.0</uid2-shared.version>
2020
<okta-jwt.version>0.5.10</okta-jwt.version>
2121
<image.version>${project.version}</image.version>
2222
</properties>

src/main/java/com/uid2/admin/vertx/Endpoints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public enum Endpoints {
6767
API_PRIVATE_SITES_REFRESH_NOW("/api/private-sites/refreshNow"),
6868

6969
API_SALT_SNAPSHOTS("/api/salt/snapshots"),
70+
API_SALT_REBUILD("/api/salt/rebuild"),
7071
API_SALT_ROTATE("/api/salt/rotate"),
71-
API_SALT_ROTATE_ZERO("/api/salt/rotate-zero"),
7272

7373
API_SEARCH("/api/search"),
7474

@@ -82,6 +82,7 @@ public enum Endpoints {
8282
API_SERVICE_ADD("/api/service/add"),
8383
API_SERVICE_UPDATE("/api/service/update"),
8484
API_SERVICE_DELETE("/api/service/delete"),
85+
API_SERVICE_REMOVE_LINK_ID_REGEX("/api/service/remove-link-id-regex"),
8586

8687
API_SHARING_LISTS("/api/sharing/lists"),
8788
API_SHARING_LIST_SITEID("/api/sharing/list/:siteId"),

src/main/java/com/uid2/admin/vertx/service/SaltService.java

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ public void setupRoutes(Router router) {
5454
router.get(API_SALT_SNAPSHOTS.toString()).handler(
5555
auth.handle(this::handleSaltSnapshots, Role.MAINTAINER));
5656

57-
router.post(API_SALT_ROTATE.toString()).blockingHandler(auth.handle((ctx) -> {
57+
router.post(API_SALT_REBUILD.toString()).blockingHandler(auth.handle(ctx -> {
5858
synchronized (writeLock) {
59-
this.handleSaltRotate(ctx);
59+
this.handleSaltRebuild(ctx);
6060
}
61-
}, new AuditParams(List.of("fraction", "min_ages_in_seconds", "target_date"), Collections.emptyList()), Role.SUPER_USER, Role.SECRET_ROTATION));
61+
}, new AuditParams(List.of(), Collections.emptyList()), Role.MAINTAINER));
6262

63-
router.post(API_SALT_ROTATE_ZERO.toString()).blockingHandler(auth.handle((ctx) -> {
63+
router.post(API_SALT_ROTATE.toString()).blockingHandler(auth.handle((ctx) -> {
6464
synchronized (writeLock) {
65-
this.handleSaltRotateZero(ctx);
65+
this.handleSaltRotate(ctx);
6666
}
67-
}, new AuditParams(List.of(), Collections.emptyList()), Role.MAINTAINER));
67+
}, new AuditParams(List.of("fraction", "min_ages_in_seconds", "target_date"), Collections.emptyList()), Role.SUPER_USER, Role.SECRET_ROTATION));
6868
}
6969

7070
private void handleSaltSnapshots(RoutingContext rc) {
7171
try {
7272
final JsonArray ja = new JsonArray();
73-
this.saltProvider.getSnapshots().stream()
73+
saltProvider.getSnapshots().stream()
7474
.forEachOrdered(s -> ja.add(toJson(s)));
7575

7676
rc.response()
@@ -82,30 +82,21 @@ private void handleSaltSnapshots(RoutingContext rc) {
8282
}
8383
}
8484

85-
private void handleSaltRotate(RoutingContext rc) {
85+
private void handleSaltRebuild(RoutingContext rc) {
8686
try {
87-
final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction");
88-
if (fraction.isEmpty()) return;
89-
final Duration[] minAges = RequestUtil.getDurations(rc, "min_ages_in_seconds");
90-
if (minAges == null) return;
91-
92-
93-
final TargetDate targetDate =
94-
RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE)
95-
.map(TargetDate::new)
96-
.orElse(TargetDate.now().plusDays(1))
97-
;
87+
Instant now = Instant.now();
9888

9989
// force refresh
100-
this.saltProvider.loadContent();
90+
saltProvider.loadContent();
10191

10292
// mark all the referenced files as ready to archive
10393
storageManager.archiveSaltLocations();
10494

105-
final List<RotatingSaltProvider.SaltSnapshot> snapshots = this.saltProvider.getSnapshots();
106-
final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast();
95+
// Unlike in regular salt rotation, this should be based on the currently effective snapshot.
96+
// The latest snapshot may be in the future, and we may have changes that shouldn't be activated yet.
97+
var effectiveSnapshot = saltProvider.getSnapshot(now);
10798

108-
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, fraction.get(), targetDate);
99+
var result = saltRotation.rotateSaltsZero(effectiveSnapshot, TargetDate.now(), now);
109100
if (!result.hasSnapshot()) {
110101
ResponseUtil.error(rc, 200, result.getReason());
111102
return;
@@ -122,21 +113,28 @@ private void handleSaltRotate(RoutingContext rc) {
122113
}
123114
}
124115

125-
private void handleSaltRotateZero(RoutingContext rc) {
116+
private void handleSaltRotate(RoutingContext rc) {
126117
try {
127-
Instant now = Instant.now();
118+
final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction");
119+
if (fraction.isEmpty()) return;
120+
final Duration[] minAges = RequestUtil.getDurations(rc, "min_ages_in_seconds");
121+
if (minAges == null) return;
128122

129-
// force refresh
130-
this.saltProvider.loadContent();
123+
final TargetDate targetDate =
124+
RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE)
125+
.map(TargetDate::new)
126+
.orElse(TargetDate.now().plusDays(1));
131127

132-
// mark all the referenced files as ready to archive
128+
// Force refresh
129+
saltProvider.loadContent();
130+
131+
// Mark all the referenced files as ready to archive
133132
storageManager.archiveSaltLocations();
134133

135-
// Unlike in regular salt rotation, this should be based on the currently effective snapshot.
136-
// The latest snapshot may be in the future, and we may have changes that shouldn't be activated yet.
137-
var effectiveSnapshot = this.saltProvider.getSnapshot(now);
134+
final List<RotatingSaltProvider.SaltSnapshot> snapshots = saltProvider.getSnapshots();
135+
final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast();
138136

139-
var result = saltRotation.rotateSaltsZero(effectiveSnapshot, TargetDate.now(), now);
137+
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, fraction.get(), targetDate);
140138
if (!result.hasSnapshot()) {
141139
ResponseUtil.error(rc, 200, result.getReason());
142140
return;

src/main/java/com/uid2/admin/vertx/service/ServiceLinkService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.slf4j.LoggerFactory;
2020

2121
import java.util.*;
22+
import java.util.regex.Pattern;
2223
import java.util.stream.Collectors;
2324

2425
import static com.uid2.admin.vertx.Endpoints.*;
@@ -118,6 +119,12 @@ private void handleServiceLinkAdd(RoutingContext rc) {
118119
return;
119120
}
120121

122+
String linkIdRegex = serviceProvider.getService(serviceId).getLinkIdRegex();
123+
if (!isValidLinkId(linkId, linkIdRegex)) {
124+
ResponseUtil.error(rc, 400, "link_id " + linkId + " does not match service_id " + serviceId + " link_id_regex: " + linkIdRegex);
125+
return;
126+
}
127+
121128
Set<Role> serviceRoles = serviceProvider.getService(serviceId).getRoles();
122129
final Set<Role> roles;
123130
try {
@@ -270,4 +277,11 @@ private Set<Role> validateRoles(JsonArray rolesToValidate, Set<Role> serviceRole
270277
}
271278
return roles;
272279
}
280+
281+
private boolean isValidLinkId(String linkId, String serviceRegex) {
282+
if (serviceRegex == null) {
283+
return true;
284+
}
285+
return Pattern.matches(serviceRegex, linkId);
286+
}
273287
}

0 commit comments

Comments
 (0)