tristaZero commented on a change in pull request #10310:
URL: https://github.com/apache/shardingsphere/pull/10310#discussion_r634039265
##########
File path:
shardingsphere-infra/shardingsphere-infra-authority/shardingsphere-infra-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
##########
@@ -56,7 +58,25 @@ public SQLCheckResult check(final SQLStatement sqlStatement,
final List<Object>
// TODO add error msg
return privileges.map(optional -> new
SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))),
"")).orElseGet(() -> new SQLCheckResult(false, ""));
}
-
+
+ @Override
+ public boolean check(final Grantee grantee, final AuthorityRule
authorityRule) {
+ Optional<ShardingSphereUser> user = authorityRule.findUser(grantee);
+ return user.isPresent() ? true : false;
+ }
+
+ @Override
+ public boolean check(final Grantee grantee, final BiPredicate<Object,
Object> validate, final Object cipher, final AuthorityRule authorityRule) {
+ Optional<ShardingSphereUser> user = authorityRule.findUser(grantee);
+ if (!user.isPresent()) {
+ return false;
+ }
+ if (validate.test(user.get(), cipher)) {
+ return true;
+ }
+ return false;
Review comment:
TODO-1,
Please consider the ternary operator to make it clean.
##########
File path:
shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilder.java
##########
@@ -139,14 +135,4 @@ private ShardingSphereResource buildResource(final
DatabaseType databaseType, fi
private ShardingSphereSchema buildSchema(final DatabaseType databaseType,
final Map<String, DataSource> dataSourceMap, final
Collection<ShardingSphereRule> rules) throws SQLException {
return SchemaBuilder.build(new SchemaBuilderMaterials(databaseType,
dataSourceMap, rules, props));
}
-
- private Collection<ShardingSphereUser> getUsersFromAuthorityRule() {
Review comment:
TODO-2,
Please consider whether `shardingsphere-infra-authority-api` can be removed
from `shardingsphere-infra/shardingsphere-infra-context/pom.xml`
##########
File path:
shardingsphere-infra/shardingsphere-infra-authority/shardingsphere-infra-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
##########
@@ -56,7 +58,28 @@ public SQLCheckResult check(final SQLStatement sqlStatement,
final List<Object>
// TODO add error msg
return privileges.map(optional -> new
SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))),
"")).orElseGet(() -> new SQLCheckResult(false, ""));
}
-
+
+ @Override
+ public boolean check(final Grantee grantee, final AuthorityRule
authorityRule) {
+ Optional<ShardingSphereUser> user = authorityRule.findUser(grantee);
+ if (!user.isPresent()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean check(final Grantee grantee, final BiPredicate<Object,
Object> validate, final Object cipher, final AuthorityRule authorityRule) {
Review comment:
TODO-4,
The third argument is likely to be `BiPredicate<Grantee, byte[]>` rather
than `BiPredicate<Object, Object>`. Thus, the argument `Object cipher` is
supposed to be `byte[] cipher`.
##########
File path:
shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
##########
@@ -225,10 +217,8 @@ public synchronized void renew(final
PropertiesChangedEvent event) {
*/
@Subscribe
public synchronized void renew(final AuthorityChangedEvent event) {
- Collection<ShardingSphereUser> users = new
HashSet<>(getNewUsers(event.getUsers()));
- users.addAll(getModifiedUsers(event.getUsers()));
metaDataContexts = new StandardMetaDataContexts(
- metaDataContexts.getMetaDataMap(),
metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(),
new ShardingSphereUsers(users), metaDataContexts.getProps());
+ metaDataContexts.getMetaDataMap(),
metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(),
metaDataContexts.getProps());
Review comment:
TODO-3
--
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:
[email protected]