You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/04/01 15:01:00 UTC
[GitHub] [shardingsphere] zhujunxxxxx commented on a change in pull request #9884: Add testcase for MySQLPrivilageLoader & fix bug
zhujunxxxxx commented on a change in pull request #9884:
URL: https://github.com/apache/shardingsphere/pull/9884#discussion_r605728218
##########
File path: shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/auth/builder/loader/dialect/MySQLPrivilegeLoader.java
##########
@@ -52,6 +52,7 @@
@Override
public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
+ users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));
Review comment:
```
private void fillGlobalPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
if (user.isPresent()) {
privileges.get(user.get()).getAdministrativePrivilege().getPrivileges().addAll(loadAdministrativePrivileges(resultSet));
privileges.get(user.get()).getDatabasePrivilege().getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
}
}
```
We analyzed this code will find in `getShardingSphereUser` method, if parameter `privileges` is empty it will returns empty, so `user.isPresent()` always false. `fillGlobalPrivilege` can't add any elements to `privileges`.The same problem in `fillSchemaPrivilege` and `fillTablePrivilege`. but the parameter `privileges` is empty at first.
so I add the below code in the first to avoid this problem.
```
users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));
```
@tristaZero Can you help me see if this is right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org