Skip to content

Commit 9d513a7

Browse files
authored
Fix/password upgrade failed (#16089)
* Old password invalid under current policy (ignored) * Old password invalid under current policy (ignored) * fix ut * implement forceUpdateUserPassword for old password * fix updateUserPassword
1 parent 490aab1 commit 9d513a7

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/authorizer/BasicAuthorizer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public boolean login(String username, String password) throws AuthException {
119119
}
120120
if (AuthUtils.validatePassword(
121121
password, user.getPassword(), AsymmetricEncrypt.DigestAlgorithm.MD5)) {
122-
userManager.updateUserPassword(username, password);
122+
try {
123+
forceUpdateUserPassword(username, password);
124+
} catch (AuthException ignore) {
125+
}
123126
return true;
124127
}
125128
return false;
@@ -141,7 +144,7 @@ public String login4Pipe(final String username, final String password) {
141144
if (AuthUtils.validatePassword(
142145
password, user.getPassword(), AsymmetricEncrypt.DigestAlgorithm.MD5)) {
143146
try {
144-
userManager.updateUserPassword(username, password);
147+
forceUpdateUserPassword(username, password);
145148
} catch (AuthException ignore) {
146149
}
147150
return userManager.getEntity(username).getPassword();
@@ -311,7 +314,14 @@ public Set<PrivilegeType> getPrivileges(String userName, PartialPath path) throw
311314

312315
@Override
313316
public void updateUserPassword(String userName, String newPassword) throws AuthException {
314-
if (!userManager.updateUserPassword(userName, newPassword)) {
317+
if (!userManager.updateUserPassword(userName, newPassword, false)) {
318+
throw new AuthException(
319+
TSStatusCode.ILLEGAL_PARAMETER, "password " + newPassword + " is illegal");
320+
}
321+
}
322+
323+
private void forceUpdateUserPassword(String userName, String newPassword) throws AuthException {
324+
if (!userManager.updateUserPassword(userName, newPassword, true)) {
315325
throw new AuthException(
316326
TSStatusCode.ILLEGAL_PARAMETER, "password " + newPassword + " is illegal");
317327
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/auth/user/BasicUserManager.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,16 @@ public boolean createUser(
133133
}
134134
}
135135

136-
public boolean updateUserPassword(String username, String newPassword) throws AuthException {
137-
if (CommonDescriptor.getInstance().getConfig().isEnforceStrongPassword()
138-
&& username.equals(newPassword)) {
139-
throw new AuthException(
140-
TSStatusCode.ILLEGAL_PASSWORD, "Password cannot be the same as user name");
136+
public boolean updateUserPassword(String username, String newPassword, boolean bypassValidate)
137+
throws AuthException {
138+
if (!bypassValidate) {
139+
if (CommonDescriptor.getInstance().getConfig().isEnforceStrongPassword()
140+
&& username.equals(newPassword)) {
141+
throw new AuthException(
142+
TSStatusCode.ILLEGAL_PASSWORD, "Password cannot be the same as user name");
143+
}
144+
AuthUtils.validatePassword(newPassword);
141145
}
142-
AuthUtils.validatePassword(newPassword);
143146

144147
lock.writeLock(username);
145148
try {

0 commit comments

Comments
 (0)