Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected Pair<Boolean, Boolean> enforcePolicies(
});

suspend |= user.getFailedLogins() != null && policy.getMaxAuthenticationAttempts() > 0
&& user.getFailedLogins() > policy.getMaxAuthenticationAttempts() && !user.isSuspended();
&& user.getFailedLogins() >= policy.getMaxAuthenticationAttempts() && !user.isSuspended();
propagateSuspension |= policy.isPropagateSuspension();
}
}
Expand Down Expand Up @@ -380,10 +380,7 @@ public Pair<UserWorkflowResult<String>, Boolean> suspendOnAuthFailures(

Pair<Boolean, Boolean> enforce = enforcePolicies(user, true, null);
if (enforce.getKey()) {
LOG.debug("User {} {} is over the max failed logins", user.getKey(), user.getUsername());

// reduce failed logins number to avoid multiple request
user.setFailedLogins(user.getFailedLogins() - 1);
LOG.debug("User {} {} reached the max failed logins", user.getKey(), user.getUsername());

// set suspended flag
user.setSuspended(Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -333,13 +334,7 @@ public void checkUserSuspension() {

assertEquals(0, USER_SERVICE.read(userKey).getFailedLogins());

// authentications failed ...
try {
CLIENT_FACTORY.create(userTO.getUsername(), "wrongpwd1");
fail("This should not happen");
} catch (NotAuthorizedException e) {
assertNotNull(e);
}
// /odd has an account policy with maxAuthenticationAttempts = 3.
try {
CLIENT_FACTORY.create(userTO.getUsername(), "wrongpwd1");
fail("This should not happen");
Expand All @@ -353,9 +348,10 @@ public void checkUserSuspension() {
assertNotNull(e);
}

assertEquals(3, USER_SERVICE.read(userKey).getFailedLogins());
userTO = USER_SERVICE.read(userTO.getKey());
assertEquals(2, userTO.getFailedLogins().intValue());
assertNotEquals("suspended", userTO.getStatus());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status value comes from the workflow definition in use, so it might vary.

The cleanest check here is

assertFalse(userTO.isSuspended();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I have to do the same thing few rows below adding assertTrue(userTO.isSuspended());

userTO = USER_SERVICE.read(userTO.getKey());
assertNotNull(userTO);
assertNotNull(userTO.getFailedLogins());
assertEquals(3, userTO.getFailedLogins().intValue());
assertEquals("suspended", userTO.getStatus());


// last authentication before suspension
try {
CLIENT_FACTORY.create(userTO.getUsername(), "wrongpwd1");
fail("This should not happen");
Expand Down
Loading