Skip to content
Merged
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 @@ -167,37 +167,37 @@ public TSStatus checkUserSysPrivilegesGrantOpt(String username, PrivilegeType pe
@Override
public List<Integer> checkUserPathPrivileges(
String username, List<? extends PartialPath> allPath, PrivilegeType permission) {
checkCacheAvailable();
List<Integer> posList = new ArrayList<>();
User user = iAuthorCache.getUserCache(username);
if (user != null) {
if (user.isOpenIdUser()) {
return posList;
}
int pos = 0;
for (PartialPath path : allPath) {
if (!user.checkPathPrivilege(path, permission)) {
boolean checkFromRole = false;
for (String rolename : user.getRoleSet()) {
Role cachedRole = iAuthorCache.getRoleCache(rolename);
if (cachedRole == null) {
return checkPathFromConfigNode(username, allPath, permission);
}
if (cachedRole.checkPathPrivilege(path, permission)) {
checkFromRole = true;
break;
}
if (username.equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
return posList;
}
checkCacheAvailable();
User user = getUser(username);
if (user.isOpenIdUser()) {
return posList;
}
int pos = 0;
for (PartialPath path : allPath) {
if (!user.checkPathPrivilege(path, permission)) {
boolean checkFromRole = false;
for (String rolename : user.getRoleSet()) {
Role cachedRole = iAuthorCache.getRoleCache(rolename);
if (cachedRole == null) {
checkRoleFromConfigNode(username, rolename);
cachedRole = iAuthorCache.getRoleCache(rolename);
}
Comment on lines +184 to 188
Copy link
Contributor

Choose a reason for hiding this comment

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

There is still a chance that the role is evicted between line 183 and 184, therefore, cachedRold can still be null.
One possible solution is to make checkRoleFromConfigNode() return the Role it just fetched.
And may rename checkRoleFromConfigNode() to fetchRoleFromConfigNode() which is more precise.

Copy link
Contributor

Choose a reason for hiding this comment

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

And what if the role is deleted concurrently? You can still not fetch it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have resolved the possible NPE issue, but the concurrency problem requires a more systematic design.

if (!checkFromRole) {
posList.add(pos);
if (cachedRole != null && cachedRole.checkPathPrivilege(path, permission)) {
checkFromRole = true;
break;
}
}
pos++;
if (!checkFromRole) {
posList.add(pos);
}
}
return posList;
} else {
return checkPathFromConfigNode(username, allPath, permission);
pos++;
}
return posList;
}

@Override
Expand Down Expand Up @@ -642,15 +642,6 @@ private TPermissionInfoResp checkPrivilegeFromConfigNode(TCheckUserPrivilegesReq
return permissionInfoResp;
}

private List<Integer> checkPathFromConfigNode(
String username, List<? extends PartialPath> allPath, PrivilegeType permission) {
TCheckUserPrivilegesReq req =
new TCheckUserPrivilegesReq(
username, PrivilegeModelType.TREE.ordinal(), permission.ordinal(), false);
req.setPaths(AuthUtils.serializePartialPathList(allPath));
return checkPrivilegeFromConfigNode(req).getFailPos();
}

private boolean checkRoleFromConfigNode(String username, String rolename) {
TAuthorizerReq req = new TAuthorizerReq();
// just reuse authorizer request. only need username and rolename field.
Expand Down
Loading