Skip to content

Commit

Permalink
Failure reset time is applied to Permanent Lockout
Browse files Browse the repository at this point in the history
Closes keycloak#28821

Signed-off-by: Douglas Palmer <[email protected]>
  • Loading branch information
douglaspalmer authored and mposolda committed Jul 18, 2024
1 parent 12d76a6 commit 3500618
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected void failure(KeycloakSession session, LoginEvent event) {
}
userLoginFailure.setLastFailure(currentTime);

if (deltaTime > 0) {
if (!(realm.isPermanentLockout() && realm.getMaxTemporaryLockouts() == 0) && deltaTime > 0) {
// if last failure was more than MAX_DELTA clear failures
if (deltaTime > (long) realm.getMaxDeltaTimeSeconds() * 1000L) {
userLoginFailure.clearFailures();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,47 @@ public void testBrowserInvalidPassword() throws Exception {
loginSuccess();
}

@Test
public void testFailureResetForTemporaryLockout() throws Exception {
RealmRepresentation realm = testRealm().toRepresentation();
try {
realm.setMaxDeltaTimeSeconds(5);
testRealm().update(realm);
loginInvalidPassword();

testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(5)));

loginInvalidPassword();
loginSuccess();
} finally {
realm.setMaxDeltaTimeSeconds(20);
testRealm().update(realm);
}
}

@Test
public void testNoFailureResetForPermanentLockout() throws Exception {
RealmRepresentation realm = testRealm().toRepresentation();
try {
realm.setMaxDeltaTimeSeconds(5);
realm.setPermanentLockout(true);
testRealm().update(realm);
loginInvalidPassword();

testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(5)));

loginInvalidPassword();
expectPermanentlyDisabled();
} finally {
realm.setPermanentLockout(false);
realm.setMaxDeltaTimeSeconds(20);
testRealm().update(realm);
UserRepresentation user = adminClient.realm("test").users().search("test-user@localhost", 0, 1).get(0);
user.setEnabled(true);
updateUser(user);
}
}

@Test
public void testWait() throws Exception {
loginSuccess();
Expand Down

0 comments on commit 3500618

Please sign in to comment.