Skip to content

Commit 9daaaa8

Browse files
authored
fix/loginlockmgr-constructor (apache#16636)
1 parent 07d457e commit 9daaaa8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/LoginLockManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LoginLockManager {
4141

4242
// Configuration parameters
4343
private final int failedLoginAttempts;
44-
private final int failedLoginAttemptsPerUser;
44+
private int failedLoginAttemptsPerUser;
4545
private final int passwordLockTimeMinutes;
4646

4747
// Lock records storage (in-memory only)
@@ -79,6 +79,14 @@ public LoginLockManager(
7979
if (failedLoginAttemptsPerUser <= 0) {
8080
this.failedLoginAttemptsPerUser = -1; // Disable user-level restrictions
8181
LOGGER.info("User-level login attempts disabled (set to {})", failedLoginAttemptsPerUser);
82+
83+
// Additional check: if IP-level is enabled (>1), enable user-level with default 1000
84+
if (this.failedLoginAttempts > 1) {
85+
this.failedLoginAttemptsPerUser = 1000;
86+
LOGGER.warn(
87+
"User-level attempts auto-enabled with default 1000 because IP-level is enabled (set to {})",
88+
this.failedLoginAttempts);
89+
}
8290
} else {
8391
this.failedLoginAttemptsPerUser = failedLoginAttemptsPerUser;
8492
}

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/LoginLockManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testAllConfigScenarios() {
8282
// 3. Test mixed scenarios (IP enabled + user disabled, and vice versa)
8383
LoginLockManager ipEnabledUserDisabled = new LoginLockManager(3, 0, 10);
8484
assertEquals(3, getField(ipEnabledUserDisabled, "failedLoginAttempts"));
85-
assertEquals(-1, getField(ipEnabledUserDisabled, "failedLoginAttemptsPerUser"));
85+
assertEquals(1000, getField(ipEnabledUserDisabled, "failedLoginAttemptsPerUser"));
8686

8787
LoginLockManager ipDisabledUserEnabled = new LoginLockManager(-1, 5, 10);
8888
assertEquals(-1, getField(ipDisabledUserEnabled, "failedLoginAttempts"));
@@ -95,7 +95,7 @@ public void testAllConfigScenarios() {
9595

9696
LoginLockManager invalidUser =
9797
new LoginLockManager(5, -2, 10); // Negative treated as disable (-1)
98-
assertEquals(-1, getField(invalidUser, "failedLoginAttemptsPerUser"));
98+
assertEquals(1000, getField(invalidUser, "failedLoginAttemptsPerUser"));
9999

100100
// 5. Test lock time validation
101101
LoginLockManager zeroLockTime = new LoginLockManager(5, 1000, 0);

0 commit comments

Comments
 (0)