Skip to content

Commit e02b247

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

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
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 & 4 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,6 +35,7 @@
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;
4040
import java.util.List;
4141
import java.util.concurrent.atomic.AtomicReference;
@@ -170,11 +170,11 @@ private Router createRouter() {
170170
.allowedHeader("Content-Type"));
171171

172172
router.route(Endpoints.OPTOUT_WRITE.toString())
173-
.handler(internalAuth.handleWithAudit(this::handleWrite, new AuditParams(), this.enableAuditLogging));
173+
.handler(internalAuth.handleWithAudit(this::handleWrite));
174174
router.route(Endpoints.OPTOUT_REPLICATE.toString())
175-
.handler(auth.handleWithAudit(this::handleReplicate, new AuditParams(), this.enableAuditLogging, Role.OPTOUT));
175+
.handler(auth.handleWithAudit(this::handleReplicate, Arrays.asList(Role.OPTOUT)));
176176
router.route(Endpoints.OPTOUT_REFRESH.toString())
177-
.handler(auth.handleWithAudit(attest.handle(this::handleRefresh, Role.OPERATOR), new AuditParams(), this.enableAuditLogging, Role.OPERATOR));
177+
.handler(auth.handleWithAudit(attest.handle(this::handleRefresh, Role.OPERATOR), Arrays.asList(Role.OPERATOR)));
178178
router.get(Endpoints.OPS_HEALTHCHECK.toString())
179179
.handler(this::handleHealthCheck);
180180

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void setup(){
3434

3535
@Test
3636
public void internalAuthHandlerNoAuthorizationHeader() {
37-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
37+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
3838
handler.handle(routingContext);
3939
verifyNoInteractions(nextHandler);
4040
verify(routingContext).fail(401);
@@ -43,7 +43,7 @@ public void internalAuthHandlerNoAuthorizationHeader() {
4343

4444
@Test public void authHandlerInvalidAuthorizationHeader() {
4545
when(request.getHeader("Authorization")).thenReturn("Bogus Header Value");
46-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
46+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
4747
handler.handle(routingContext);
4848
verifyNoInteractions(nextHandler);
4949
verify(routingContext).fail(401);
@@ -52,7 +52,7 @@ public void internalAuthHandlerNoAuthorizationHeader() {
5252

5353
@Test public void authHandlerUnknownKey() {
5454
when(request.getHeader("Authorization")).thenReturn("Bearer unknown-key");
55-
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler, new AuditParams(), true);
55+
Handler<RoutingContext> handler = internalAuth.handleWithAudit(nextHandler);
5656
handler.handle(routingContext);
5757
verifyNoInteractions(nextHandler);
5858
verify(routingContext).fail(401);

0 commit comments

Comments
 (0)