Skip to content
Open
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 @@ -138,11 +138,11 @@ public static void invalidateAllCache() {
}

public static User getUser(String username) {
return authorityFetcher.get().getUser(username);
return authorityFetcher.get().getUser(username, false);
}

public static Optional<Long> getUserId(String username) {
User user = authorityFetcher.get().getUser(username);
User user = authorityFetcher.get().getUser(username, false);
return Optional.ofNullable(user == null ? null : user.getUserId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.consensus.ConfigRegionId;
import org.apache.iotdb.commons.exception.IoTDBException;
import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathPatternTree;
Expand Down Expand Up @@ -172,7 +173,7 @@ public List<Integer> checkUserPathPrivileges(
return posList;
}
checkCacheAvailable();
User user = getUser(username);
User user = getUser(username, true);
if (user.isOpenIdUser()) {
return posList;
}
Expand Down Expand Up @@ -443,13 +444,12 @@ private SettableFuture<ConfigTaskResult> handleAccountUnlock(
Object authorStatement, String username, boolean isRelational, Runnable successCallback) {

if (isUnlockStatement(authorStatement, isRelational)) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
User user = getUser(username);
if (user == null) {
future.setException(
new IoTDBException(
String.format("User %s does not exist", username),
TSStatusCode.USER_NOT_EXIST.getStatusCode()));
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
final User user;
try {
user = getUser(username, false);
} catch (final IoTDBRuntimeException e) {
future.setException(e);
return future;
}
String loginAddr =
Expand Down Expand Up @@ -593,7 +593,8 @@ public TSStatus checkUser(
}
}

public User getUser(String userName) {
@Override
public User getUser(String userName, final boolean force) {
checkCacheAvailable();
User user = iAuthorCache.getUserCache(userName);
if (user != null) {
Expand All @@ -616,6 +617,10 @@ public User getUser(String userName) {
}
}
}
if (user == null && force) {
throw new IoTDBRuntimeException(
"User " + userName + " does not exist", TSStatusCode.USER_NOT_EXIST.getStatusCode());
}
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ PathPatternTree getAuthorizedPatternTree(String username, PrivilegeType permissi

void refreshToken();

User getUser(String username);
User getUser(String username, final boolean force);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,7 @@ protected IConfigTask visitRelationalAuthorPlan(
}

private void visitUpdateUser(RelationalAuthorStatement node) {
User user = AuthorityChecker.getAuthorityFetcher().getUser(node.getUserName());
if (user == null) {
throw new SemanticException("User " + node.getUserName() + " not found");
}
final User user = AuthorityChecker.getAuthorityFetcher().getUser(node.getUserName(), true);
node.setOldPassword(user.getPassword());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.iotdb.common.rpc.thrift.Model;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.commons.audit.UserEntity;
import org.apache.iotdb.commons.auth.entity.User;
import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
import org.apache.iotdb.commons.executable.ExecutableManager;
import org.apache.iotdb.commons.path.PartialPath;
Expand Down Expand Up @@ -340,18 +339,14 @@ public IConfigTask visitAuthor(AuthorStatement statement, MPPQueryContext contex
}

private void visitUpdateUser(AuthorStatement statement) {
User user = AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName());
if (user == null) {
throw new SemanticException("User " + statement.getUserName() + " not found");
}
statement.setPassWord(user.getPassword());
statement.setPassWord(
AuthorityChecker.getAuthorityFetcher()
.getUser(statement.getUserName(), true)
.getPassword());
}

private void visitRenameUser(AuthorStatement statement) {
User user = AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName());
if (user == null) {
throw new SemanticException("User " + statement.getUserName() + " not found");
}
AuthorityChecker.getAuthorityFetcher().getUser(statement.getUserName(), true);
}

@Override
Expand Down
Loading