Skip to content

Commit f632b86

Browse files
committed
Initiate AuditParams() inside the middleware
1 parent 0a91037 commit f632b86

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/main/java/com/uid2/optout/auth/InternalAuthMiddleware.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,10 @@ public InternalAuthMiddleware(String internalApiToken, String auditSource) {
6565
this.audit = new Audit(auditSource);
6666
}
6767

68-
public Handler<RoutingContext> handleWithAudit(Handler<RoutingContext> handler, AuditParams auditParams, Boolean enableAuditLog) {
68+
public Handler<RoutingContext> handleWithAudit(Handler<RoutingContext> handler) {
6969
InternalAuthHandler h;
70-
if (enableAuditLog) {
71-
final Handler<RoutingContext> loggedHandler = logAndHandle(handler, auditParams);
72-
h = new InternalAuthHandler(loggedHandler, this.internalApiToken);
73-
} else {
74-
h = new InternalAuthHandler(handler, this.internalApiToken);
75-
}
70+
final Handler<RoutingContext> loggedHandler = logAndHandle(handler, new AuditParams());
71+
h = new InternalAuthHandler(loggedHandler, this.internalApiToken);
7672
return h::handle;
7773
}
7874
}

src/main/java/com/uid2/optout/vertx/OptOutServiceVerticle.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.uid2.shared.attest.AttestationTokenService;
88
import com.uid2.shared.attest.IAttestationTokenService;
99
import com.uid2.shared.attest.JwtService;
10-
import com.uid2.shared.audit.AuditParams;
1110
import com.uid2.shared.auth.IAuthorizableProvider;
1211
import com.uid2.shared.auth.OperatorKey;
1312
import com.uid2.shared.auth.Role;
@@ -36,8 +35,8 @@
3635
import java.net.URL;
3736
import java.time.Instant;
3837
import java.util.ArrayList;
38+
import java.util.Arrays;
3939
import java.util.Collection;
40-
import java.util.List;
4140
import java.util.concurrent.atomic.AtomicReference;
4241
import java.util.stream.Collectors;
4342

@@ -58,7 +57,6 @@ public class OptOutServiceVerticle extends AbstractVerticle {
5857
private final AtomicReference<Collection<String>> cloudPaths = new AtomicReference<>();
5958
private final ICloudStorage cloudStorage;
6059
private final boolean enableOptOutPartnerMock;
61-
private final boolean enableAuditLogging;
6260
private final String internalApiKey;
6361
private final InternalAuthMiddleware internalAuth;
6462

@@ -88,8 +86,6 @@ public OptOutServiceVerticle(Vertx vertx,
8886
this.listenPort = Const.Port.ServicePortForOptOut + Utils.getPortOffset();
8987
this.deltaRotateInterval = jsonConfig.getInteger(Const.Config.OptOutDeltaRotateIntervalProp);
9088
this.isVerbose = jsonConfig.getBoolean(Const.Config.ServiceVerboseProp, false);
91-
this.enableAuditLogging = true;
92-
9389

9490
String replicaUrisConfig = jsonConfig.getString(Const.Config.OptOutReplicaUris);
9591
if (replicaUrisConfig == null) {
@@ -170,11 +166,11 @@ private Router createRouter() {
170166
.allowedHeader("Content-Type"));
171167

172168
router.route(Endpoints.OPTOUT_WRITE.toString())
173-
.handler(internalAuth.handleWithAudit(this::handleWrite, new AuditParams(), this.enableAuditLogging));
169+
.handler(internalAuth.handleWithAudit(this::handleWrite));
174170
router.route(Endpoints.OPTOUT_REPLICATE.toString())
175-
.handler(auth.handleWithAudit(this::handleReplicate, new AuditParams(), this.enableAuditLogging, Role.OPTOUT));
171+
.handler(auth.handleWithAudit(this::handleReplicate, Arrays.asList(Role.OPTOUT)));
176172
router.route(Endpoints.OPTOUT_REFRESH.toString())
177-
.handler(auth.handleWithAudit(attest.handle(this::handleRefresh, Role.OPERATOR), new AuditParams(), this.enableAuditLogging, Role.OPERATOR));
173+
.handler(auth.handleWithAudit(attest.handle(this::handleRefresh, Role.OPERATOR), Arrays.asList(Role.OPERATOR)));
178174
router.get(Endpoints.OPS_HEALTHCHECK.toString())
179175
.handler(this::handleHealthCheck);
180176

src/test/java/com/uid2/optout/auth/InternalAuthMiddlewareTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.uid2.optout.auth;
22

33
import org.junit.jupiter.api.BeforeEach;
4-
import com.uid2.shared.audit.AuditParams;
54
import io.vertx.core.Handler;
65
import io.vertx.core.http.HttpServerRequest;
76
import io.vertx.ext.web.RoutingContext;
@@ -34,7 +33,7 @@ public void setup(){
3433

3534
@Test
3635
public void internalAuthHandlerNoAuthorizationHeader() {
37-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
36+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
3837
handler.handle(routingContext);
3938
verifyNoInteractions(nextHandler);
4039
verify(routingContext).fail(401);
@@ -43,7 +42,7 @@ public void internalAuthHandlerNoAuthorizationHeader() {
4342

4443
@Test public void authHandlerInvalidAuthorizationHeader() {
4544
when(request.getHeader("Authorization")).thenReturn("Bogus Header Value");
46-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
45+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
4746
handler.handle(routingContext);
4847
verifyNoInteractions(nextHandler);
4948
verify(routingContext).fail(401);
@@ -52,7 +51,7 @@ public void internalAuthHandlerNoAuthorizationHeader() {
5251

5352
@Test public void authHandlerUnknownKey() {
5453
when(request.getHeader("Authorization")).thenReturn("Bearer unknown-key");
55-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
54+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
5655
handler.handle(routingContext);
5756
verifyNoInteractions(nextHandler);
5857
verify(routingContext).fail(401);

0 commit comments

Comments
 (0)