This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 8b60893 Remove ShardingSphereAuthority.getAllUsers() (#9975)
8b60893 is described below
commit 8b608930fc99a92c9c319e4d7bbd4af60f4ccbbb
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 7 21:00:34 2021 +0800
Remove ShardingSphereAuthority.getAllUsers() (#9975)
---
.../authority/engine/ShardingSphereAuthority.java | 8 --------
.../authority/engine/impl/DefaultAuthority.java | 5 -----
.../context/metadata/GovernanceMetaDataContextsTest.java | 9 +++++----
.../governance/core/facade/GovernanceFacadeTest.java | 11 +++--------
.../governance/core/registry/RegistryCenterTest.java | 12 +-----------
5 files changed, 9 insertions(+), 36 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
index 3a7e329..70072ad 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
@@ -21,7 +21,6 @@ import
org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import java.util.Collection;
import java.util.Map;
import java.util.Optional;
@@ -45,13 +44,6 @@ public interface ShardingSphereAuthority {
Map<ShardingSphereUser, ShardingSpherePrivileges> getAuthority();
/**
- * Get all users.
- *
- * @return all users
- */
- Collection<ShardingSphereUser> getAllUsers();
-
- /**
* Find Privileges.
*
* @param grantee grantee
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
index 5c76961..09d7679 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
@@ -42,11 +42,6 @@ public final class DefaultAuthority implements
ShardingSphereAuthority {
}
@Override
- public Collection<ShardingSphereUser> getAllUsers() {
- return authority.keySet();
- }
-
- @Override
public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee
grantee) {
return authority.keySet().stream().filter(each ->
each.getGrantee().equals(grantee)).findFirst().map(authority::get);
}
diff --git
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
index fd08f13..ca911b1 100644
---
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
+++
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.governance.context.metadata;
+import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
import
org.apache.shardingsphere.governance.core.event.model.auth.UserRuleChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.metadata.MetaDataDeletedEvent;
@@ -35,10 +36,10 @@ import
org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataCon
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
import
org.apache.shardingsphere.readwrite.splitting.common.rule.ReadWriteSplittingRule;
import org.apache.shardingsphere.test.mock.MockedDataSource;
@@ -158,9 +159,9 @@ public final class GovernanceMetaDataContextsTest {
@Test
public void assertAuthorityChanged() {
DefaultAuthority authority = new DefaultAuthority();
- UserRuleChangedEvent event = new
UserRuleChangedEvent(authority.getAllUsers());
+ UserRuleChangedEvent event = new
UserRuleChangedEvent(Collections.singleton(mock(ShardingSphereUser.class)));
governanceMetaDataContexts.renew(event);
- assertThat(governanceMetaDataContexts.getUsers().getUsers().size(),
is(authority.getAuthority().size()));
+ assertThat(governanceMetaDataContexts.getUsers().getUsers().size(),
is(1));
}
@Test
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
index ad4d720..c567c04 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
@@ -23,11 +23,9 @@ import
org.apache.shardingsphere.governance.core.facade.util.FieldUtil;
import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
import
org.apache.shardingsphere.governance.repository.api.config.GovernanceCenterConfiguration;
import
org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,13 +69,10 @@ public final class GovernanceFacadeTest {
Map<String, DataSourceConfiguration> dataSourceConfigMap =
Collections.singletonMap("test_ds", mock(DataSourceConfiguration.class));
Map<String, Collection<RuleConfiguration>> ruleConfigurationMap =
Collections.singletonMap("sharding_db",
Collections.singletonList(mock(RuleConfiguration.class)));
ShardingSphereUser user = new ShardingSphereUser("root", "root", "");
- DefaultAuthority authority = new DefaultAuthority();
- authority.getAuthority().put(user, new ShardingSpherePrivileges());
Properties props = new Properties();
- governanceFacade.onlineInstance(
- Collections.singletonMap("sharding_db", dataSourceConfigMap),
ruleConfigurationMap, authority.getAllUsers(), props);
+
governanceFacade.onlineInstance(Collections.singletonMap("sharding_db",
dataSourceConfigMap), ruleConfigurationMap, Collections.singleton(user), props);
verify(registryCenter).persistConfigurations("sharding_db",
dataSourceConfigMap, ruleConfigurationMap.get("sharding_db"), false);
-
verify(registryCenter).persistGlobalConfiguration(authority.getAllUsers(),
props, false);
+
verify(registryCenter).persistGlobalConfiguration(Collections.singleton(user),
props, false);
verify(registryCenter).persistInstanceOnline();
verify(registryCenter).persistDataNodes();
verify(listenerManager).init();
diff --git
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index f5d3e74..524e2a2 100644
---
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -321,7 +321,7 @@ public final class RegistryCenterTest {
@Test
public void assertPersistGlobalConfiguration() {
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
-
registryCenter.persistGlobalConfiguration(createAuthentication().getAllUsers(),
createProperties(), true);
+ registryCenter.persistGlobalConfiguration(new
UsersYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(AUTHENTICATION_YAML),
YamlUsersConfiguration.class)), createProperties(), true);
verify(registryRepository, times(0)).persist("/authentication",
readYAML(AUTHENTICATION_YAML));
verify(registryRepository).persist("/props", PROPS_YAML);
}
@@ -371,16 +371,6 @@ public final class RegistryCenterTest {
return new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(readYAML(SHADOW_RULE_YAML),
YamlRootRuleConfigurations.class).getRules());
}
- private DefaultAuthority createAuthentication() {
- Collection<ShardingSphereUser> users =
- new
UsersYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(AUTHENTICATION_YAML),
YamlUsersConfiguration.class));
- DefaultAuthority result = new DefaultAuthority();
- for (ShardingSphereUser each : users) {
- result.getAuthority().put(each, new ShardingSpherePrivileges());
- }
- return result;
- }
-
private Properties createProperties() {
Properties result = new Properties();
result.put(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.FALSE);