Skip to content

Commit 7d0813f

Browse files
committed
Add audit logging to handleUserInfo
1 parent 34b2af7 commit 7d0813f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/java/com/uid2/admin/auth/OktaAuthProvider.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ public AuthenticationHandler createAuthHandler(Vertx vertx, Route callbackRoute)
7272
);
7373
OAuth2AuthHandler authHandler = OAuth2AuthHandler.create(vertx, oktaAuth, this.config.getString(OKTA_CALLBACK));
7474
authHandler.extraParams(new JsonObject(String.format("{\"scope\":\"%s\"}", String.join(" ", this.scopes))));
75-
callbackRoute.handler(ctx -> {
76-
System.out.println("AUDIT START - Path: " + ctx.request().path());
77-
System.out.println("Query: " + ctx.request().query());
78-
this.audit.log(ctx, new AuditParams());
79-
ctx.next();
80-
});
8175
authHandler.setupCallback(callbackRoute);
8276
return authHandler;
8377
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.uid2.admin.vertx.service.IService;
77
import com.uid2.shared.Const;
88
import com.uid2.shared.Utils;
9+
import com.uid2.shared.audit.Audit;
10+
import com.uid2.shared.audit.AuditParams;
911
import io.vertx.core.AbstractVerticle;
1012
import io.vertx.core.Promise;
1113
import io.vertx.core.http.HttpServerOptions;
@@ -34,6 +36,7 @@ public class AdminVerticle extends AbstractVerticle {
3436
private final TokenRefreshHandler tokenRefreshHandler;
3537
private final IService[] services;
3638
private final V2Router v2Router;
39+
private final Audit audit;
3740

3841
public AdminVerticle(JsonObject config,
3942
AuthProvider authProvider,
@@ -45,6 +48,7 @@ public AdminVerticle(JsonObject config,
4548
this.tokenRefreshHandler = tokenRefreshHandler;
4649
this.services = services;
4750
this.v2Router = v2Router;
51+
this.audit = new Audit("admin");
4852
}
4953

5054
public void start(Promise<Void> startPromise) {
@@ -113,6 +117,16 @@ private void handleUserinfo(RoutingContext rc) {
113117
List<String> groups = (List<String>) idJwt.getClaims().get("groups");
114118
jo.put("groups", new JsonArray(groups));
115119
jo.put("email", idJwt.getClaims().get("email"));
120+
121+
JsonObject userDetails = new JsonObject();
122+
userDetails.put("email", idJwt.getClaims().get("email"));
123+
userDetails.put("sub", idJwt.getClaims().get("sub"));
124+
userDetails.put("path", "/login");
125+
126+
LOGGER.info("Authenticated user accessing admin page - User: {}", userDetails.toString());
127+
rc.put("user_details", userDetails);
128+
this.audit.log(rc, new AuditParams());
129+
116130
rc.response().setStatusCode(200).end(jo.toString());
117131
} catch (Exception e) {
118132
if (rc.session() != null) {

0 commit comments

Comments
 (0)