From 694394a67010cca7b920440e87e4e8970978c6b5 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Wed, 27 Jul 2016 15:04:11 -0400 Subject: [PATCH] Don't run SyncUtils.runBlocking methods in AuditLog callbacks (these callbacks are ran on an event loop thread) --- .../POSTDisposableLoginTokensIdUse.java | 6 ++++-- .../route/users/GETUsersIdVerifyPassword.java | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/route/disposableLoginTokens/POSTDisposableLoginTokensIdUse.java b/src/main/java/net/frozenorb/apiv3/route/disposableLoginTokens/POSTDisposableLoginTokensIdUse.java index 5fc120e..abcbb90 100644 --- a/src/main/java/net/frozenorb/apiv3/route/disposableLoginTokens/POSTDisposableLoginTokensIdUse.java +++ b/src/main/java/net/frozenorb/apiv3/route/disposableLoginTokens/POSTDisposableLoginTokensIdUse.java @@ -37,6 +37,8 @@ public final class POSTDisposableLoginTokensIdUse implements Handler UserSessionUtils.createSession(user.getId(), userIp, v)); + AuditLog.log(user.getId(), userIp, ctx, AuditLogActionType.DISPOSABLE_LOGIN_TOKEN_USE, (ignored, error2) -> { if (error2 != null) { ErrorUtils.respondInternalError(ctx, error2); @@ -46,8 +48,8 @@ public final class POSTDisposableLoginTokensIdUse implements HandlerrunBlocking(v -> UserSessionUtils.createSession(user.getId(), userIp, v)) - )); + "session", session) + ); }); }); } diff --git a/src/main/java/net/frozenorb/apiv3/route/users/GETUsersIdVerifyPassword.java b/src/main/java/net/frozenorb/apiv3/route/users/GETUsersIdVerifyPassword.java index cf06d76..31883ed 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/GETUsersIdVerifyPassword.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/GETUsersIdVerifyPassword.java @@ -1,5 +1,6 @@ package net.frozenorb.apiv3.route.users; +import com.mongodb.async.SingleResultCallback; import io.vertx.core.Handler; import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; @@ -50,18 +51,31 @@ public final class GETUsersIdVerifyPassword implements Handler { AuditLog.log(user.getId(), userIp, ctx, authorized ? AuditLogActionType.USER_LOGIN_SUCCESS : AuditLogActionType.USER_LOGIN_FAIL, (ignored, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); - } else { + return; + } + + SingleResultCallback responseCallback = (session, sessionError) -> { + if (sessionError != null) { + ErrorUtils.respondInternalError(ctx, sessionError); + return; + } + Map result = new HashMap<>(); result.put("authorized", authorized); result.put("uuid", finalUuid); if (authorized) { - String session = SyncUtils.runBlocking(v -> UserSessionUtils.createSession(finalUuid, userIp, v)); result.put("session", session); } APIv3.respondJson(ctx, 200, result); + }; + + if (authorized) { + UserSessionUtils.createSession(finalUuid, userIp, responseCallback); + } else { + responseCallback.onResult(null, null); } }); }