KEYCLOAK-17829
Unnessary calls to session.users().getUserById in DefaultBruteForceProtector
This commit is contained in:
parent
ae9df51438
commit
455e93856c
1 changed files with 8 additions and 7 deletions
|
@ -103,10 +103,6 @@ public class DefaultBruteForceProtector implements Runnable, BruteForceProtector
|
||||||
logFailure(event);
|
logFailure(event);
|
||||||
|
|
||||||
String userId = event.userId;
|
String userId = event.userId;
|
||||||
UserModel user = session.users().getUserById(realm, userId);
|
|
||||||
if (user == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserLoginFailureModel userLoginFailure = getUserModel(session, event);
|
UserLoginFailureModel userLoginFailure = getUserModel(session, event);
|
||||||
if (userLoginFailure == null) {
|
if (userLoginFailure == null) {
|
||||||
|
@ -126,6 +122,10 @@ public class DefaultBruteForceProtector implements Runnable, BruteForceProtector
|
||||||
logger.debugv("new num failures: {0}", userLoginFailure.getNumFailures());
|
logger.debugv("new num failures: {0}", userLoginFailure.getNumFailures());
|
||||||
|
|
||||||
if(userLoginFailure.getNumFailures() == realm.getFailureFactor()) {
|
if(userLoginFailure.getNumFailures() == realm.getFailureFactor()) {
|
||||||
|
UserModel user = session.users().getUserById(realm, userId);
|
||||||
|
if (user == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
logger.debugv("user {0} locked permanently due to too many login attempts", user.getUsername());
|
logger.debugv("user {0} locked permanently due to too many login attempts", user.getUsername());
|
||||||
user.setEnabled(false);
|
user.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
|
@ -251,12 +251,13 @@ public class DefaultBruteForceProtector implements Runnable, BruteForceProtector
|
||||||
|
|
||||||
private void success(KeycloakSession session, LoginEvent event) {
|
private void success(KeycloakSession session, LoginEvent event) {
|
||||||
String userId = event.userId;
|
String userId = event.userId;
|
||||||
UserModel model = session.users().getUserById(getRealmModel(session, event), userId);
|
|
||||||
|
|
||||||
UserLoginFailureModel user = getUserModel(session, event);
|
UserLoginFailureModel user = getUserModel(session, event);
|
||||||
if(user == null) return;
|
if(user == null) return;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debugv("user {0} successfully logged in, clearing all failures", model.getUsername());
|
UserModel model = session.users().getUserById(getRealmModel(session, event), userId);
|
||||||
|
logger.debugv("user {0} successfully logged in, clearing all failures", model.getUsername());
|
||||||
|
}
|
||||||
user.clearFailures();
|
user.clearFailures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue