Don't run SyncUtils.runBlocking methods in AuditLog callbacks (these callbacks are ran on an event loop thread)

This commit is contained in:
Colin McDonald 2016-07-27 15:04:11 -04:00
parent 79a9f7770c
commit 694394a670
2 changed files with 20 additions and 4 deletions

View File

@ -37,6 +37,8 @@ public final class POSTDisposableLoginTokensIdUse implements Handler<RoutingCont
return;
}
String session = SyncUtils.runBlocking(v -> 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 Handler<RoutingCont
APIv3.respondJson(ctx, 200, ImmutableMap.of(
"authorized", true,
"uuid", user.getId(),
"session", SyncUtils.<String>runBlocking(v -> UserSessionUtils.createSession(user.getId(), userIp, v))
));
"session", session)
);
});
});
}

View File

@ -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<RoutingContext> {
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<String> responseCallback = (session, sessionError) -> {
if (sessionError != null) {
ErrorUtils.respondInternalError(ctx, sessionError);
return;
}
Map<String, Object> 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);
}
});
}