You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/02/12 13:51:59 UTC
[shardingsphere] branch master updated: Refactor AuthorityRule (#24128)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6fe1d689025 Refactor AuthorityRule (#24128)
6fe1d689025 is described below
commit 6fe1d6890253c68cfbaa9c9ca146fb763cea480b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Feb 12 21:51:51 2023 +0800
Refactor AuthorityRule (#24128)
---
.../authority/rule/AuthorityRule.java | 37 ++++++++--------------
1 file changed, 13 insertions(+), 24 deletions(-)
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index 351af264490..ec74d02e11f 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.spi.AuthorityProvider;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -30,7 +29,6 @@ import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
@@ -42,23 +40,26 @@ public final class AuthorityRule implements GlobalRule {
@Getter
private final AuthorityRuleConfiguration configuration;
- private final Collection<ShardingSphereUser> users;
-
private final AuthorityProvider provider;
private volatile AuthorityRegistry authorityRegistry;
- private final Map<String, AlgorithmConfiguration> authenticatorConfig = new LinkedHashMap<>();
-
- private final String defaultAuthenticator;
-
public AuthorityRule(final AuthorityRuleConfiguration ruleConfig, final Map<String, ShardingSphereDatabase> databases) {
configuration = ruleConfig;
- users = ruleConfig.getUsers();
provider = TypedSPILoader.getService(AuthorityProvider.class, ruleConfig.getAuthorityProvider().getType(), ruleConfig.getAuthorityProvider().getProps());
authorityRegistry = provider.buildAuthorityRegistry(databases, ruleConfig.getUsers());
- authenticatorConfig.putAll(ruleConfig.getAuthenticators());
- defaultAuthenticator = ruleConfig.getDefaultAuthenticator();
+ }
+
+ /**
+ * Get authenticator type.
+ *
+ * @param user user
+ * @return authenticator type
+ */
+ public String getAuthenticatorType(final ShardingSphereUser user) {
+ return configuration.getAuthenticators().containsKey(user.getAuthenticationMethodName())
+ ? configuration.getAuthenticators().get(user.getAuthenticationMethodName()).getType()
+ : Optional.ofNullable(configuration.getDefaultAuthenticator()).orElse("");
}
/**
@@ -68,7 +69,7 @@ public final class AuthorityRule implements GlobalRule {
* @return user
*/
public Optional<ShardingSphereUser> findUser(final Grantee grantee) {
- return users.stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
+ return configuration.getUsers().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
}
/**
@@ -91,18 +92,6 @@ public final class AuthorityRule implements GlobalRule {
authorityRegistry = provider.buildAuthorityRegistry(databases, users);
}
- /**
- * Get authenticator type.
- *
- * @param user user
- * @return authenticator type
- */
- public String getAuthenticatorType(final ShardingSphereUser user) {
- return authenticatorConfig.containsKey(user.getAuthenticationMethodName())
- ? authenticatorConfig.get(user.getAuthenticationMethodName()).getType()
- : Optional.ofNullable(defaultAuthenticator).orElse("");
- }
-
@Override
public String getType() {
return AuthorityRule.class.getSimpleName();