Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Audit Logging for User Activation: Capture First Login from Activation Link/Email #10732

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ public JwtPair activateUser(
}
}

return tokenFactory.createTokenPair(securityUser);
var tokenPair = tokenFactory.createTokenPair(securityUser);
systemSecurityService.logLoginAction(user, new RestAuthenticationDetails(request), ActionType.LOGIN, null);
return tokenPair;
}

@ApiOperation(value = "Reset password (resetPassword)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testAuditLogs() throws Exception {
}
} while (pageData.hasNext());

Assert.assertEquals(11, loadedAuditLogs.size());
Assert.assertEquals(11 + 1, loadedAuditLogs.size());

loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(5);
Expand All @@ -136,7 +136,7 @@ public void testAuditLogs() throws Exception {
}
} while (pageData.hasNext());

Assert.assertEquals(11, loadedAuditLogs.size());
Assert.assertEquals(11 + 1, loadedAuditLogs.size());

loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(5);
Expand All @@ -150,7 +150,7 @@ public void testAuditLogs() throws Exception {
}
} while (pageData.hasNext());

Assert.assertEquals(11, loadedAuditLogs.size());
Assert.assertEquals(11 + 1, loadedAuditLogs.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,13 @@ public void testTwoFa_logLoginAction() throws Exception {

logInWithPreVerificationToken(username, password);
await("async audit log saving").during(1, TimeUnit.SECONDS);
assertThat(getLogInAuditLogs()).isEmpty();
assertThat(userService.findUserById(tenantId, user.getId()).getAdditionalInfo()
.get("lastLoginTs")).isNull();

doPost("/api/auth/2fa/verification/check?providerType=TOTP&verificationCode=incorrect")
.andExpect(status().isBadRequest());

// there is the first login audit log after user activation
await("async audit log saving").atMost(1, TimeUnit.SECONDS)
.until(() -> getLogInAuditLogs().size() == 1);
.until(() -> getLogInAuditLogs().size() == 2);
assertThat(getLogInAuditLogs().get(0)).satisfies(failedLogInAuditLog -> {
assertThat(failedLogInAuditLog.getActionStatus()).isEqualTo(ActionStatus.FAILURE);
assertThat(failedLogInAuditLog.getActionFailureDetails()).containsIgnoringCase("verification code is incorrect");
Expand All @@ -316,7 +314,7 @@ public void testTwoFa_logLoginAction() throws Exception {
doPost("/api/auth/2fa/verification/check?providerType=TOTP&verificationCode=" + getCorrectTotp(totpTwoFaAccountConfig))
.andExpect(status().isOk());
await("async audit log saving").atMost(1, TimeUnit.SECONDS)
.until(() -> getLogInAuditLogs().size() == 2);
.until(() -> getLogInAuditLogs().size() == 3);
assertThat(getLogInAuditLogs().get(0)).satisfies(successfulLogInAuditLog -> {
assertThat(successfulLogInAuditLog.getActionStatus()).isEqualTo(ActionStatus.SUCCESS);
assertThat(successfulLogInAuditLog.getUserName()).isEqualTo(username);
Expand Down