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 2021/04/08 06:33:30 UTC
[shardingsphere] branch master updated: Issue#9326. New yaml
configuration for authentication of ShardingProxy (#9897)
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 c2166d6 Issue#9326. New yaml configuration for authentication of ShardingProxy (#9897)
c2166d6 is described below
commit c2166d61ec9450599278cae6254a5fc9399201fe
Author: huanghao495430759 <34...@users.noreply.github.com>
AuthorDate: Thu Apr 8 01:32:55 2021 -0500
Issue#9326. New yaml configuration for authentication of ShardingProxy (#9897)
* Add test case for PostgreSQLCommand #8439
* Add test case for UpdateResponseHeader #8440
* Add test case for PostgreSQLCommand #8439
* Add test case for UpdateResponseHeader #8440
* revert commit
* issue#9326.New yaml configuration for authentication of ShardingProxy.
* issue#9326.New yaml configuration for authentication of ShardingProxy.
* issue#9326.New yaml configuration for authentication of ShardingProxy.
* issue#9326.delete any unnecessary code.
* issue#9326.fix authentication documents error.
* issue#9326.fix any documents error and code error.
* issue#9326.Renaming YamlUserConfigurationConverter.convertYamlUserConfigurationFormattings to YamlUserConfigurationConverter.convertYamlUserConfigurations.
* issue#9326.Resolve RegistryCenter conflict.
* issue#9845.fix any javadoc of YamlUserConfigurationConverter.
* issue#9845.fix any conflict file error.
* issue#9845.fix any conflict file error.
* issue#9845.fix any conflict file error.
Co-authored-by: huanghao-jk <hu...@360jinrong.net>
---
.../governance/management/config-center.cn.md | 8 +-
.../governance/management/config-center.en.md | 12 +--
.../configuration/authentication.cn.md | 8 +-
.../configuration/authentication.en.md | 10 +--
.../sharding-proxy/sharding/conf/server.yaml | 5 +-
.../src/main/resources/conf/server.yaml | 10 +--
.../src/main/resources/conf/server.yaml | 6 +-
.../src/main/resources/conf/server.yaml | 10 +--
.../governance/core/registry/RegistryCenter.java | 42 +++++-----
.../core/registry/RegistryCenterNode.java | 14 ++--
.../listener/AuthenticationChangedListener.java | 4 +-
.../listener/PrivilegeNodeChangedListener.java | 2 +-
.../yaml/config/YamlConfigurationConverter.java | 10 +--
.../core/registry/RegistryCenterNodeTest.java | 4 +-
.../core/registry/RegistryCenterTest.java | 17 ++--
.../AuthenticationChangedListenerTest.java | 2 +-
.../{data-authentication.yaml => data-users.yaml} | 8 +-
.../user/yaml/config/YamlUserConfiguration.java | 7 ++
.../config/YamlUserConfigurationConverter.java | 91 ++++++++++++++++++++++
.../user/yaml/config/YamlUsersConfiguration.java | 34 --------
.../user/yaml/swapper/UserYamlSwapper.java | 50 ++++++++++++
.../user/yaml/swapper/UsersYamlSwapper.java | 69 ----------------
.../user/yaml/swapper/UserYamlSwapperTest.java | 60 ++++++++++++++
.../user/yaml/swapper/UsersYamlSwapperTest.java | 74 ------------------
.../impl/GovernanceBootstrapInitializer.java | 12 +--
.../src/main/resources/conf/server.yaml | 16 ++--
.../impl/GovernanceBootstrapInitializerTest.java | 4 +-
.../impl/StandardBootstrapInitializerTest.java | 20 +----
.../src/test/resources/conf/local/server.yaml | 9 +--
.../reg_center/{authentication.yaml => users.yaml} | 7 +-
.../proxy/config/ProxyConfigurationLoader.java | 2 +-
.../config/yaml/YamlProxyServerConfiguration.java | 5 +-
.../swapper/YamlProxyConfigurationSwapper.java | 6 +-
.../swapper/YamlProxyConfigurationSwapperTest.java | 17 ++--
.../src/test/resources/conf/server.yaml | 6 +-
.../junit/processor/AuthenticationProcessor.java | 13 +++-
.../resources/docker/db/proxy/conf/server.yaml | 6 +-
.../proxy/conf/server.yaml | 6 +-
.../proxy/conf/server.yaml | 6 +-
.../docker/encrypt/proxy/conf/server.yaml | 6 +-
.../read_write_splitting/proxy/conf/server.yaml | 6 +-
.../sharding_governance/proxy/conf/server.yaml | 6 +-
.../resources/docker/tbl/proxy/conf/server.yaml | 6 +-
43 files changed, 346 insertions(+), 370 deletions(-)
diff --git a/docs/document/content/features/governance/management/config-center.cn.md b/docs/document/content/features/governance/management/config-center.cn.md
index 819b22d..adee9ea 100644
--- a/docs/document/content/features/governance/management/config-center.cn.md
+++ b/docs/document/content/features/governance/management/config-center.cn.md
@@ -15,7 +15,7 @@ weight = 1
```
namespace
- ├──authentication # 权限配置
+ ├──users # 权限配置
├──props # 属性配置
├──schemas # Schema 配置
├ ├──${schema_1} # Schema 名称1
@@ -28,13 +28,13 @@ namespace
├ ├ ├──table # 表结构配置
```
-### /authentication
+### /users
权限配置,可配置访问 ShardingSphere-Proxy 的用户名和密码。
```yaml
-username: root
-password: root
+- root@127.0.0.1:root
+- sharding@%:sharding
```
### /props
diff --git a/docs/document/content/features/governance/management/config-center.en.md b/docs/document/content/features/governance/management/config-center.en.md
index 8f46a71..ef92824 100644
--- a/docs/document/content/features/governance/management/config-center.en.md
+++ b/docs/document/content/features/governance/management/config-center.en.md
@@ -11,11 +11,11 @@ weight = 1
## Structure in Configuration Center
-Under defined namespace, configuration center stores data sources, rule configurations, authentication configuration, and properties in YAML. Modifying nodes can dynamically refresh configurations.
+Under defined namespace, configuration center stores data sources, rule configurations, user configurations, and properties in YAML. Modifying nodes can dynamically refresh configurations.
```
namespace
- ├──authentication # Authentication configuration
+ ├──users # Users configuration
├──props # Properties configuration
├──schemas # Schema configuration
├ ├──${schema_1} # Schema name 1
@@ -28,13 +28,13 @@ namespace
├ ├ ├──table # Table configuration
```
-### /authentication
+### /users
-Authentication configuration. Can configure username and password for ShardingSphere-Proxy.
+user configurations. Can configure username and password for ShardingSphere-Proxy.
```yaml
-username: root
-password: root
+- root@127.0.0.1:root
+- sharding@%:sharding
```
### /props
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.cn.md
index 416a222..d7117f5 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.cn.md
@@ -7,11 +7,7 @@ weight = 2
配置用户名、密码、可访问的数据库后,必须使用正确的用户名、密码才可登录。
```yaml
-authentication:
users:
- root: # 自定义用户名
- password: root # 自定义密码
- sharding: # 自定义用户名
- password: sharding # 自定义密码
- hostname: '%' # 允许访问Sharding Proxy的主机。
+ - root@:root # <username>@<hostname>:<password>
+ - sharding@%:sharding
```
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.en.md b/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.en.md
index 953ef47..2540919 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/configuration/authentication.en.md
@@ -6,11 +6,7 @@ weight = 2
It is used to verify the authentication to log in ShardingSphere-Proxy, which must use correct user name and password after the configuration of them.
```yaml
-authentication:
- users:
- root: # Self-defined username
- password: root # Self-defined password
- sharding: # Self-defined username
- password: sharding # Self-defined password
- hostname: '%' # Which host can be allowed to access the Sharding Proxy.
+users:
+ - root@:root # <username>@<hostname>:<password>
+ - sharding@%:sharding
```
diff --git a/examples/docker/sharding-proxy/sharding/conf/server.yaml b/examples/docker/sharding-proxy/sharding/conf/server.yaml
index cbe6417..8544fab 100644
--- a/examples/docker/sharding-proxy/sharding/conf/server.yaml
+++ b/examples/docker/sharding-proxy/sharding/conf/server.yaml
@@ -28,9 +28,8 @@
# serverLists: localhost:2181
# overwrite: false
-authentication:
- username: root
- password: root
+users:
+ - root@%:root
props:
max-connections-size-per-query: 1
diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml
index f0c52c5..f07d391 100644
--- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml
+++ b/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/server.yaml
@@ -33,13 +33,9 @@
# operationTimeoutMilliseconds: 500
# overwrite: false
-authentication:
- users:
- root:
- password: root
- sharding:
- password: sharding
- hostname: '%'
+users:
+ - root@:root
+ - sharding@%:sharding
props:
max-connections-size-per-query: 1
diff --git a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml
index b3d366e..b03947f 100644
--- a/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml
+++ b/examples/shardingsphere-proxy-example/shardingsphere-proxy-hint-example/src/main/resources/conf/server.yaml
@@ -33,10 +33,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: false
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
index e3fdbb4..9ddd6b6 100644
--- a/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
+++ b/shardingsphere-distribution/shardingsphere-proxy-distribution/src/main/resources/conf/server.yaml
@@ -33,13 +33,9 @@
# operationTimeoutMilliseconds: 500
# overwrite: false
-#authentication:
-# users:
-# root:
-# password: root
-# hostname: '%'
-# sharding:
-# password: sharding
+#users:
+# - root@%:root
+# - sharding@:sharding
#scaling:
# blockQueueSize: 10000
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index cb47b25..a5077d8 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -42,13 +42,12 @@ import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
import org.apache.shardingsphere.infra.metadata.mapper.event.dcl.impl.CreateUserStatementEvent;
import org.apache.shardingsphere.infra.metadata.mapper.event.dcl.impl.GrantStatementEvent;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
@@ -122,7 +121,7 @@ public final class RegistryCenter {
* @param isOverwrite is overwrite config center's configuration
*/
public void persistGlobalConfiguration(final Collection<ShardingSphereUser> users, final Properties props, final boolean isOverwrite) {
- persistAuthentication(users, isOverwrite);
+ persistUsers(users, isOverwrite);
persistProperties(props, isOverwrite);
}
@@ -190,24 +189,25 @@ public final class RegistryCenter {
result.setRules(new YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs));
return result;
}
-
- private void persistAuthentication(final Collection<ShardingSphereUser> users, final boolean isOverwrite) {
- if (!users.isEmpty() && (isOverwrite || !hasAuthentication())) {
- repository.persist(node.getAuthenticationPath(), YamlEngine.marshal(new UsersYamlSwapper().swapToYamlConfiguration(users)));
+
+ private void persistUsers(final Collection<ShardingSphereUser> users, final boolean isOverwrite) {
+ if (!users.isEmpty() && (isOverwrite || !hasUsers())) {
+ repository.persist(node.getUsersNode(), YamlEngine.marshal(YamlUserConfigurationConverter.convertYamlUserConfigurations(users)));
}
}
-
+
private void persistNewUsers(final Collection<ShardingSphereUser> users) {
if (!users.isEmpty()) {
- YamlUsersConfiguration yamlUserConfig = YamlEngine.unmarshal(repository.get(node.getAuthenticationPath()), YamlUsersConfiguration.class);
- yamlUserConfig.getUsers().putAll(new UsersYamlSwapper().swapToYamlConfiguration(users).getUsers());
- repository.persist(node.getAuthenticationPath(), YamlEngine.marshal(yamlUserConfig));
+ Collection<String> yamlUsers = YamlEngine.unmarshal(repository.get(node.getUsersNode()), Collection.class);
+ Collection<String> newUsers = new LinkedHashSet<>(YamlUserConfigurationConverter.convertYamlUserConfigurations(users));
+ newUsers.addAll(yamlUsers);
+ repository.persist(node.getUsersNode(), YamlEngine.marshal(newUsers));
}
}
private void persistChangedPrivilege(final Collection<ShardingSphereUser> users) {
if (!users.isEmpty()) {
- repository.persist(node.getPrivilegeNodePath(), YamlEngine.marshal(new UsersYamlSwapper().swapToYamlConfiguration(users)));
+ repository.persist(node.getPrivilegeNodePath(), YamlEngine.marshal(YamlUserConfigurationConverter.convertYamlUserConfigurations(users)));
}
}
@@ -235,7 +235,7 @@ public final class RegistryCenter {
newArrayList.add(schemaName);
repository.persist(node.getMetadataNodePath(), Joiner.on(",").join(newArrayList));
}
-
+
/**
* Load data source configurations.
*
@@ -258,12 +258,14 @@ public final class RegistryCenter {
}
/**
- * Load user rule.
+ * Load users.
*
* @return authority
*/
- public Collection<ShardingSphereUser> loadUserRule() {
- return hasAuthentication() ? YamlConfigurationConverter.convertUserRule(repository.get(node.getAuthenticationPath())) : Collections.emptyList();
+ public Collection<ShardingSphereUser> loadUsers() {
+ return hasUsers()
+ ? YamlConfigurationConverter.convertUsers(repository.get(node.getUsersNode()))
+ : Collections.emptyList();
}
/**
@@ -337,9 +339,9 @@ public final class RegistryCenter {
public void deleteSchema(final String schemaName) {
repository.delete(node.getSchemaNamePath(schemaName));
}
-
- private boolean hasAuthentication() {
- return !Strings.isNullOrEmpty(repository.get(node.getAuthenticationPath()));
+
+ private boolean hasUsers() {
+ return !Strings.isNullOrEmpty(repository.get(node.getUsersNode()));
}
/**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNode.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNode.java
index e8a2c95..dc60f84 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNode.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNode.java
@@ -53,7 +53,7 @@ public final class RegistryCenterNode {
private static final String SCHEMA_NODE = "schema";
- private static final String AUTHENTICATION_NODE = "authentication";
+ private static final String USERS_NODE = "users";
private static final String PRIVILEGE_NODE = "privilegenode";
@@ -243,16 +243,16 @@ public final class RegistryCenterNode {
public String getMetadataSchemaPath(final String schemaName) {
return getFullMetadataPath(schemaName, SCHEMA_NODE);
}
-
+
/**
- * Get authentication path.
+ * Get users path.
*
- * @return authentication path
+ * @return users path
*/
- public String getAuthenticationPath() {
- return getFullPath(AUTHENTICATION_NODE);
+ public String getUsersNode() {
+ return getFullPath(USERS_NODE);
}
-
+
/**
* Get privilege node path.
*
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListener.java
index 162c432..64ff6b0 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListener.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListener.java
@@ -34,11 +34,11 @@ import java.util.Optional;
public final class AuthenticationChangedListener extends PostGovernanceRepositoryEventListener<GovernanceEvent> {
public AuthenticationChangedListener(final RegistryRepository registryRepository) {
- super(registryRepository, Collections.singletonList(new RegistryCenterNode().getAuthenticationPath()));
+ super(registryRepository, Collections.singletonList(new RegistryCenterNode().getUsersNode()));
}
@Override
protected Optional<GovernanceEvent> createEvent(final DataChangedEvent event) {
- return Optional.of(new UserRuleChangedEvent(YamlConfigurationConverter.convertUserRule(event.getValue())));
+ return Optional.of(new UserRuleChangedEvent(YamlConfigurationConverter.convertUsers(event.getValue())));
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/PrivilegeNodeChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/PrivilegeNodeChangedListener.java
index 3b7dc8a..67e0c4b 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/PrivilegeNodeChangedListener.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/PrivilegeNodeChangedListener.java
@@ -39,6 +39,6 @@ public final class PrivilegeNodeChangedListener extends PostGovernanceRepository
@Override
protected Optional<GovernanceEvent> createEvent(final DataChangedEvent event) {
- return Optional.of(new PrivilegeChangedEvent(YamlConfigurationConverter.convertUserRule(event.getValue())));
+ return Optional.of(new PrivilegeChangedEvent(YamlConfigurationConverter.convertUsers(event.getValue())));
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
index 7b5179a..dff9f76 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/yaml/config/YamlConfigurationConverter.java
@@ -22,8 +22,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
@@ -107,13 +106,14 @@ public final class YamlConfigurationConverter {
}
/**
- * Convert user rule from YAML content.
+ * Convert users from YAML content.
*
* @param yamlContent YAML content
* @return users
*/
- public static Collection<ShardingSphereUser> convertUserRule(final String yamlContent) {
- return new UsersYamlSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlUsersConfiguration.class));
+ public static Collection<ShardingSphereUser> convertUsers(final String yamlContent) {
+ Collection<String> users = YamlEngine.unmarshal(yamlContent, Collection.class);
+ return YamlUserConfigurationConverter.convertShardingSphereUser(users);
}
/**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNodeTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNodeTest.java
index 75279c8..5d0b961 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNodeTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterNodeTest.java
@@ -79,8 +79,8 @@ public final class RegistryCenterNodeTest {
}
@Test
- public void assertGetAuthenticationPath() {
- assertThat(registryCenterNode.getAuthenticationPath(), is("/authentication"));
+ public void assertGetUsersNodePath() {
+ assertThat(registryCenterNode.getUsersNode(), is("/users"));
}
@Test
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 be300cf..4a72057 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
@@ -39,8 +39,7 @@ import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
@@ -99,7 +98,7 @@ public final class RegistryCenterTest {
private static final String SHADOW_RULE_YAML = "yaml/registryCenter/data-shadow-rule.yaml";
- private static final String AUTHENTICATION_YAML = "yaml/registryCenter/data-authentication.yaml";
+ private static final String USERS_YAML = "yaml/registryCenter/data-users.yaml";
private static final String PROPS_YAML = ConfigurationPropertyKey.SQL_SHOW.getKey() + ": false\n";
@@ -319,8 +318,8 @@ public final class RegistryCenterTest {
@Test
public void assertPersistGlobalConfiguration() {
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
- registryCenter.persistGlobalConfiguration(new UsersYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(AUTHENTICATION_YAML), YamlUsersConfiguration.class)), createProperties(), true);
- verify(registryRepository, times(0)).persist("/authentication", readYAML(AUTHENTICATION_YAML));
+ registryCenter.persistGlobalConfiguration(YamlUserConfigurationConverter.convertShardingSphereUser(YamlEngine.unmarshal(readYAML(USERS_YAML), Collection.class)), createProperties(), true);
+ verify(registryRepository, times(0)).persist("/users", readYAML(USERS_YAML));
verify(registryRepository).persist("/props", PROPS_YAML);
}
@@ -368,7 +367,7 @@ public final class RegistryCenterTest {
private Collection<RuleConfiguration> createShadowRuleConfiguration() {
return new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(readYAML(SHADOW_RULE_YAML), YamlRootRuleConfigurations.class).getRules());
}
-
+
private Properties createProperties() {
Properties result = new Properties();
result.put(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.FALSE);
@@ -475,10 +474,10 @@ public final class RegistryCenterTest {
}
@Test
- public void assertLoadAuthentication() {
- when(registryRepository.get("/authentication")).thenReturn(readYAML(AUTHENTICATION_YAML));
+ public void assertLoadUsers() {
+ when(registryRepository.get("/users")).thenReturn(readYAML(USERS_YAML));
RegistryCenter registryCenter = new RegistryCenter(registryRepository);
- Collection<ShardingSphereUser> actual = registryCenter.loadUserRule();
+ Collection<ShardingSphereUser> actual = registryCenter.loadUsers();
Optional<ShardingSphereUser> user = actual.stream().filter(each -> each.getGrantee().equals(new Grantee("root1", ""))).findFirst();
assertTrue(user.isPresent());
assertThat(user.get().getPassword(), is("root1"));
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListenerTest.java
index ea8e592..2793a6d 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListenerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/AuthenticationChangedListenerTest.java
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class)
public final class AuthenticationChangedListenerTest {
- private static final String AUTHENTICATION_YAML = " users:\n" + " root1:\n password: root1\n" + " root2:\n" + " password: root2\n";
+ private static final String AUTHENTICATION_YAML = "- root1@:root1\n" + "- root2@:root2\n";
private AuthenticationChangedListener authenticationChangedListener;
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-authentication.yaml b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-users.yaml
similarity index 92%
rename from shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-authentication.yaml
rename to shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-users.yaml
index de99363..ce7545c 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-authentication.yaml
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/resources/yaml/registryCenter/data-users.yaml
@@ -15,8 +15,6 @@
# limitations under the License.
#
-users:
- root1:
- password: root1
- root2:
- password: root2;
+- root@%:root
+- sharding@:sharding
+- root1@:root1
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfiguration.java
index 59d4919..55bdd27 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfiguration.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfiguration.java
@@ -27,8 +27,15 @@ import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
@Getter
@Setter
public final class YamlUserConfiguration implements YamlConfiguration {
+
+ private String username;
private String hostname;
private String password;
+
+ @Override
+ public String toString() {
+ return username + "@" + (null == hostname ? "%" : hostname) + ":" + password;
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfigurationConverter.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfigurationConverter.java
new file mode 100644
index 0000000..b920fa1
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUserConfigurationConverter.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.user.yaml.config;
+
+import com.google.common.base.Preconditions;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UserYamlSwapper;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.stream.Collectors;
+
+/**
+ * Configuration converter for YAML User content.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class YamlUserConfigurationConverter {
+
+ private static final UserYamlSwapper USER_YAML_SWAPPER = new UserYamlSwapper();
+
+ /**
+ * Convert to users yaml content.
+ *
+ * @param users sharding sphere users
+ * @return users yaml content
+ */
+ public static Collection<String> convertYamlUserConfigurations(final Collection<ShardingSphereUser> users) {
+ Collection<String> result = new LinkedList<>();
+ users.stream().map(user -> USER_YAML_SWAPPER.swapToYamlConfiguration(user)).forEach(user -> result.add(user.toString()));
+ return result;
+ }
+
+ /**
+ * Convert to sharding sphere users.
+ *
+ * @param users users yaml content
+ * @return sharding sphere users
+ */
+ public static Collection<ShardingSphereUser> convertShardingSphereUser(final Collection<String> users) {
+ Collection<YamlUserConfiguration> yamlUsers = convertYamlUserConfiguration(users);
+ return yamlUsers.stream().map(yamlUser -> USER_YAML_SWAPPER.swapToObject(yamlUser)).collect(Collectors.toList());
+ }
+
+ /**
+ * Convert to yaml user configurations.
+ *
+ * @param users users yaml content
+ * @return yaml user configurations
+ */
+ public static Collection<YamlUserConfiguration> convertYamlUserConfiguration(final Collection<String> users) {
+ return users.stream().map(user -> convertYamlUserConfiguration(user)).collect(Collectors.toList());
+ }
+
+ /**
+ * Convert to yaml user configuration.
+ *
+ * @param yamlUser user yaml content
+ * @return yaml user configuration
+ */
+ private static YamlUserConfiguration convertYamlUserConfiguration(final String yamlUser) {
+ Preconditions.checkArgument(0 < yamlUser.indexOf("@") && 0 < yamlUser.indexOf(":") && yamlUser.indexOf(":") <= yamlUser.length() - 1,
+ "user configuration `%s` is invalid, the configuration format should be like `username@hostname:password`", yamlUser);
+ Preconditions.checkArgument(yamlUser.indexOf("@") < yamlUser.indexOf(":"),
+ "user configuration `%s` is invalid, the configuration format should be like `username@hostname:password`", yamlUser);
+ String username = yamlUser.substring(0, yamlUser.indexOf("@"));
+ String hostname = yamlUser.substring(yamlUser.indexOf("@") + 1, yamlUser.indexOf(":"));
+ String password = yamlUser.substring(yamlUser.indexOf(":") + 1);
+ YamlUserConfiguration result = new YamlUserConfiguration();
+ result.setUsername(username);
+ result.setHostname(hostname);
+ result.setPassword(password);
+ return result;
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUsersConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUsersConfiguration.java
deleted file mode 100644
index 59df5e2..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/config/YamlUsersConfiguration.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.user.yaml.config;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
-
-import java.util.Map;
-
-/**
- * Users configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlUsersConfiguration implements YamlConfiguration {
-
- private Map<String, YamlUserConfiguration> users;
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapper.java
new file mode 100644
index 0000000..df78e1c
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapper.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.user.yaml.swapper;
+
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlConfigurationSwapper;
+
+import java.util.Objects;
+
+/**
+ * User YAML swapper.
+ */
+public final class UserYamlSwapper implements YamlConfigurationSwapper<YamlUserConfiguration, ShardingSphereUser> {
+
+ @Override
+ public YamlUserConfiguration swapToYamlConfiguration(final ShardingSphereUser data) {
+ if (Objects.isNull(data)) {
+ return null;
+ }
+ YamlUserConfiguration result = new YamlUserConfiguration();
+ result.setUsername(data.getGrantee().getUsername());
+ result.setHostname(data.getGrantee().getHostname());
+ result.setPassword(data.getPassword());
+ return result;
+ }
+
+ @Override
+ public ShardingSphereUser swapToObject(final YamlUserConfiguration yamlConfig) {
+ if (Objects.isNull(yamlConfig)) {
+ return null;
+ }
+ return new ShardingSphereUser(yamlConfig.getUsername(), yamlConfig.getPassword(), null == yamlConfig.getHostname() ? "%" : yamlConfig.getHostname());
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapper.java
deleted file mode 100644
index 14ca3c2..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapper.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.user.yaml.swapper;
-
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlConfigurationSwapper;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * User YAML swapper.
- */
-public final class UsersYamlSwapper implements YamlConfigurationSwapper<YamlUsersConfiguration, Collection<ShardingSphereUser>> {
-
- @Override
- public YamlUsersConfiguration swapToYamlConfiguration(final Collection<ShardingSphereUser> data) {
- YamlUsersConfiguration result = new YamlUsersConfiguration();
- Map<String, YamlUserConfiguration> users = new LinkedHashMap<>(data.size(), 1);
- for (ShardingSphereUser each : data) {
- users.put(each.getGrantee().getUsername(), swapToYamlConfiguration(each));
- }
- result.setUsers(users);
- return result;
- }
-
- private YamlUserConfiguration swapToYamlConfiguration(final ShardingSphereUser data) {
- YamlUserConfiguration result = new YamlUserConfiguration();
- result.setHostname(data.getGrantee().getHostname());
- result.setPassword(data.getPassword());
- return result;
- }
-
- @Override
- public Collection<ShardingSphereUser> swapToObject(final YamlUsersConfiguration yamlConfig) {
- Collection<ShardingSphereUser> result = new LinkedHashSet<>();
- if (null == yamlConfig) {
- return result;
- }
- for (Entry<String, YamlUserConfiguration> entry : yamlConfig.getUsers().entrySet()) {
- result.add(swapToObject(entry.getKey(), entry.getValue()));
- }
- return result;
- }
-
- private ShardingSphereUser swapToObject(final String username, final YamlUserConfiguration yamlConfig) {
- return new ShardingSphereUser(username, yamlConfig.getPassword(), (null == yamlConfig.getHostname() || "%".equals(yamlConfig.getHostname())) ? "%" : yamlConfig.getHostname());
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java
new file mode 100644
index 0000000..59c74cb
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UserYamlSwapperTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.user.yaml.swapper;
+
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
+import org.junit.Test;
+
+import java.util.Objects;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class UserYamlSwapperTest {
+
+ @Test
+ public void assertSwapToYaml() {
+ ShardingSphereUser shardingSphereUser = new ShardingSphereUser("user1", "pwd1", "127.0.0.1");
+ YamlUserConfiguration yamlUser = new UserYamlSwapper().swapToYamlConfiguration(shardingSphereUser);
+ assertThat(yamlUser.getPassword(), is("pwd1"));
+ assertThat(yamlUser.getHostname(), is("127.0.0.1"));
+ assertThat(yamlUser.getUsername(), is("user1"));
+ }
+
+ @Test
+ public void assertSwapToObject() {
+ YamlUserConfiguration user1 = new YamlUserConfiguration();
+ user1.setUsername("user1");
+ user1.setPassword("pwd1");
+ user1.setHostname("127.0.0.1");
+ ShardingSphereUser actualUser = new UserYamlSwapper().swapToObject(user1);
+ assertThat(actualUser.getPassword(), is("pwd1"));
+ assertThat(actualUser.getGrantee().getHostname(), is("127.0.0.1"));
+ assertThat(actualUser.getGrantee().getUsername(), is("user1"));
+ }
+
+ @Test
+ public void assertSwapToObjectForNull() {
+ ShardingSphereUser actual = new UserYamlSwapper().swapToObject(null);
+ assertTrue(Objects.isNull(actual));
+ YamlUserConfiguration actualYamlUser = new UserYamlSwapper().swapToYamlConfiguration(null);
+ assertTrue(Objects.isNull(actualYamlUser));
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapperTest.java
deleted file mode 100644
index dff4a88..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/UsersYamlSwapperTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.user.yaml.swapper;
-
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class UsersYamlSwapperTest {
-
- @Test
- public void assertSwapToYaml() {
- Collection<ShardingSphereUser> users = new LinkedList<>();
- users.add(new ShardingSphereUser("user1", "pwd1", "127.0.0.1"));
- users.add(new ShardingSphereUser("user2", "pwd2", "127.0.0.2"));
- YamlUsersConfiguration actual = new UsersYamlSwapper().swapToYamlConfiguration(users);
- assertThat(actual.getUsers().size(), is(2));
- assertThat(actual.getUsers().get("user1").getPassword(), is("pwd1"));
- assertThat(actual.getUsers().get("user1").getHostname(), is("127.0.0.1"));
- assertThat(actual.getUsers().get("user2").getPassword(), is("pwd2"));
- assertThat(actual.getUsers().get("user2").getHostname(), is("127.0.0.2"));
- }
-
- @Test
- public void assertSwapToObject() {
- YamlUserConfiguration user1 = new YamlUserConfiguration();
- user1.setPassword("pwd1");
- YamlUserConfiguration user2 = new YamlUserConfiguration();
- user2.setPassword("pwd2");
- Map<String, YamlUserConfiguration> users = new HashMap<>(2, 1);
- users.put("user1", user1);
- users.put("user2", user2);
- YamlUsersConfiguration yamlConfig = new YamlUsersConfiguration();
- yamlConfig.setUsers(users);
- Collection<ShardingSphereUser> actual = new UsersYamlSwapper().swapToObject(yamlConfig);
- Optional<ShardingSphereUser> actualUser1 = actual.stream().filter(each -> each.getGrantee().equals(new Grantee("user1", ""))).findFirst();
- assertTrue(actualUser1.isPresent());
- Optional<ShardingSphereUser> actualUser2 = actual.stream().filter(each -> each.getGrantee().equals(new Grantee("user2", ""))).findFirst();
- assertTrue(actualUser2.isPresent());
- }
-
- @Test
- public void assertSwapToObjectForNull() {
- Collection<ShardingSphereUser> actual = new UsersYamlSwapper().swapToObject(null);
- assertTrue(actual.isEmpty());
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
index 8894ad3..37085e8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
@@ -21,12 +21,12 @@ import org.apache.shardingsphere.governance.context.metadata.GovernanceMetaDataC
import org.apache.shardingsphere.governance.context.transaction.GovernanceTransactionContexts;
import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
import org.apache.shardingsphere.governance.core.yaml.swapper.GovernanceConfigurationYamlSwapper;
-import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -66,13 +66,13 @@ public final class GovernanceBootstrapInitializer extends AbstractBootstrapIniti
if (isEmptyLocalConfiguration(serverConfig, ruleConfigs)) {
governanceFacade.onlineInstance();
} else {
- governanceFacade.onlineInstance(
- getDataSourceConfigurationMap(ruleConfigs), getRuleConfigurations(ruleConfigs), new UsersYamlSwapper().swapToObject(serverConfig.getAuthentication()), serverConfig.getProps());
+ governanceFacade.onlineInstance(getDataSourceConfigurationMap(ruleConfigs),
+ getRuleConfigurations(ruleConfigs), YamlUserConfigurationConverter.convertShardingSphereUser(serverConfig.getUsers()), serverConfig.getProps());
}
}
private boolean isEmptyLocalConfiguration(final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
- return ruleConfigs.isEmpty() && null == serverConfig.getAuthentication() && serverConfig.getProps().isEmpty();
+ return ruleConfigs.isEmpty() && serverConfig.getUsers().isEmpty() && serverConfig.getProps().isEmpty();
}
private Map<String, Map<String, DataSourceConfiguration>> getDataSourceConfigurationMap(final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
@@ -89,13 +89,13 @@ public final class GovernanceBootstrapInitializer extends AbstractBootstrapIniti
return yamlRuleConfigurations.entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> swapperEngine.swapToRuleConfigurations(entry.getValue().getRules()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
}
-
+
private ProxyConfiguration loadProxyConfiguration() {
Collection<String> schemaNames = governanceFacade.getRegistryCenter().getAllSchemaNames();
Map<String, Map<String, DataSourceParameter>> schemaDataSources = loadDataSourceParametersMap(schemaNames);
Map<String, Collection<RuleConfiguration>> schemaRules = loadSchemaRules(schemaNames);
Properties props = governanceFacade.getRegistryCenter().loadProperties();
- return new ProxyConfiguration(schemaDataSources, schemaRules, governanceFacade.getRegistryCenter().loadUserRule(), props);
+ return new ProxyConfiguration(schemaDataSources, schemaRules, governanceFacade.getRegistryCenter().loadUsers(), props);
}
private Map<String, Map<String, DataSourceParameter>> loadDataSourceParametersMap(final Collection<String> schemaNames) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index 6c6f534..9ddd6b6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -32,19 +32,15 @@
# maxRetries: 3
# operationTimeoutMilliseconds: 500
# overwrite: false
-#
-#authentication:
-# users:
-# root:
-# password: root
-# hostname: '%'
-# sharding:
-# password: sharding
-#
+
+#users:
+# - root@%:root
+# - sharding@:sharding
+
#scaling:
# blockQueueSize: 10000
# workerThread: 40
-#
+
#props:
# max-connections-size-per-query: 1
# executor-size: 16 # Infinite by default.
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
index 4380c4c..8003ead 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
@@ -67,7 +67,7 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
private static final String SHARDING_RULE_YAML = "conf/reg_center/sharding-rule.yaml";
- private static final String AUTHENTICATION_YAML = "conf/reg_center/authentication.yaml";
+ private static final String USERS_YAML = "conf/reg_center/users.yaml";
private static final String PROPS_YAML = "conf/reg_center/props.yaml";
@@ -83,7 +83,7 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
private void initConfigCenter() {
RegistryCenterNode node = new RegistryCenterNode();
- registryRepository.persist(node.getAuthenticationPath(), readYAML(AUTHENTICATION_YAML));
+ registryRepository.persist(node.getUsersNode(), readYAML(USERS_YAML));
registryRepository.persist(node.getPropsPath(), readYAML(PROPS_YAML));
registryRepository.persist(node.getMetadataNodePath(), "db");
registryRepository.persist(node.getMetadataDataSourcePath("db"), readYAML(DATA_SOURCE_YAML));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
index ef379ec..71a9ff5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
@@ -23,8 +23,6 @@ import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
@@ -156,7 +154,7 @@ public final class StandardBootstrapInitializerTest extends AbstractBootstrapIni
private YamlProxyServerConfiguration createYamlProxyServerConfiguration() {
YamlProxyServerConfiguration result = new YamlProxyServerConfiguration();
- result.setAuthentication(createYamlUserRuleConfiguration());
+ result.getUsers().add("root@:root");
result.setProps(createProperties());
return result;
}
@@ -167,21 +165,7 @@ public final class StandardBootstrapInitializerTest extends AbstractBootstrapIni
result.setProperty("beta-2", "beta-B");
return result;
}
-
- private YamlUsersConfiguration createYamlUserRuleConfiguration() {
- Map<String, YamlUserConfiguration> users = new HashMap<>(1, 1);
- users.put("root", createYamlUserConfiguration());
- YamlUsersConfiguration result = new YamlUsersConfiguration();
- result.setUsers(users);
- return result;
- }
-
- private YamlUserConfiguration createYamlUserConfiguration() {
- YamlUserConfiguration result = new YamlUserConfiguration();
- result.setPassword("root");
- return result;
- }
-
+
@Test
public void assertDecorateMetaDataContexts() {
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/local/server.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/local/server.yaml
index e611a3f..e229a8a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/local/server.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/local/server.yaml
@@ -27,12 +27,9 @@ governance:
operationTimeoutMilliseconds: 500
overwrite: false
-authentication:
- users:
- root:
- password: root
- sharding:
- password: sharding
+users:
+ - root@:root
+ - sharding@:sharding
props:
alpha-1: alpha-A
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/authentication.yaml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml
similarity index 91%
rename from shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/authentication.yaml
rename to shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml
index be3a01c..7b9f5ba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/authentication.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/resources/conf/reg_center/users.yaml
@@ -15,8 +15,5 @@
# limitations under the License.
#
-users:
- root:
- password: root
- sharding:
- password: sharding
+- root@%:root
+- sharding@:sharding
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
index 4e601b5..a20a3a3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
@@ -73,7 +73,7 @@ public final class ProxyConfigurationLoader {
YamlProxyServerConfiguration result = YamlEngine.unmarshal(yamlFile, YamlProxyServerConfiguration.class);
Preconditions.checkNotNull(result, "Server configuration file `%s` is invalid.", yamlFile.getName());
Preconditions.checkState(
- AuthorityEngine.findSPIAuthority().isPresent() || null != result.getAuthentication() || null != result.getGovernance(), "Authority configuration is invalid.");
+ AuthorityEngine.findSPIAuthority().isPresent() || !result.getUsers().isEmpty() || null != result.getGovernance(), "Authority configuration is invalid.");
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
index 262d3c8..dcc15bb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
@@ -21,9 +21,10 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlScalingConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
+import java.util.Collection;
+import java.util.LinkedList;
import java.util.Properties;
/**
@@ -33,7 +34,7 @@ import java.util.Properties;
@Setter
public final class YamlProxyServerConfiguration implements YamlConfiguration {
- private YamlUsersConfiguration authentication;
+ private Collection<String> users = new LinkedList<>();
private YamlGovernanceConfiguration governance;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
index 61584cd..d605180 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.proxy.config.yaml.swapper;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -48,7 +48,7 @@ public final class YamlProxyConfigurationSwapper {
public ProxyConfiguration swap(final YamlProxyConfiguration yamlConfig) {
Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(yamlConfig.getRuleConfigurations());
Map<String, Collection<RuleConfiguration>> schemaRules = getRuleConfigurations(yamlConfig.getRuleConfigurations());
- Collection<ShardingSphereUser> users = new UsersYamlSwapper().swapToObject(yamlConfig.getServerConfiguration().getAuthentication());
+ Collection<ShardingSphereUser> users = YamlUserConfigurationConverter.convertShardingSphereUser(yamlConfig.getServerConfiguration().getUsers());
Properties props = yamlConfig.getServerConfiguration().getProps();
return new ProxyConfiguration(schemaDataSources, schemaRules, users, props);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
index a548410..d3ac454 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.config.yaml.swapper;
+import com.google.common.collect.Lists;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.core.yaml.config.YamlGovernanceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -24,8 +25,6 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -196,15 +195,13 @@ public final class YamlProxyConfigurationSwapperTest {
}
private void prepareAuthentication(final YamlProxyServerConfiguration yamlProxyServerConfig) {
- Map<String, YamlUserConfiguration> yamlUserConfigurationMap = new HashMap<>(1, 1);
- YamlUserConfiguration yamlUserConfig = mock(YamlUserConfiguration.class);
- when(yamlUserConfig.getPassword()).thenReturn("pass");
- yamlUserConfigurationMap.put("user1", yamlUserConfig);
- YamlUsersConfiguration userRuleConfiguration = mock(YamlUsersConfiguration.class);
- when(userRuleConfiguration.getUsers()).thenReturn(yamlUserConfigurationMap);
- when(yamlProxyServerConfig.getAuthentication()).thenReturn(userRuleConfiguration);
+ when(yamlProxyServerConfig.getUsers()).thenReturn(getUsers());
}
-
+
+ private Collection<String> getUsers() {
+ return Lists.newArrayList("user1@:pass");
+ }
+
private YamlProxyServerConfiguration getYamlProxyServerConfiguration(final YamlProxyConfiguration yamlProxyConfig) {
YamlProxyServerConfiguration result = mock(YamlProxyServerConfiguration.class);
when(yamlProxyConfig.getServerConfiguration()).thenReturn(result);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/resources/conf/server.yaml b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/resources/conf/server.yaml
index 81b932d..3796403 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/resources/conf/server.yaml
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/resources/conf/server.yaml
@@ -22,10 +22,8 @@ governance:
serverLists: localhost:2181
overwrite: false
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/processor/AuthenticationProcessor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/processor/AuthenticationProcessor.java
index 9477a58..66150c8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/processor/AuthenticationProcessor.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/processor/AuthenticationProcessor.java
@@ -22,10 +22,14 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
+import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigurationConverter;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
import java.io.InputStream;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
/**
* Authentication processor.
@@ -36,10 +40,15 @@ public final class AuthenticationProcessor implements Processor<AuthenticationPr
@SneakyThrows
public Authentication process(final InputStream stream) {
YamlProxyServerConfiguration configuration = YamlEngine.unmarshal(ByteStreams.toByteArray(stream), YamlProxyServerConfiguration.class);
- YamlUserConfiguration user = configuration.getAuthentication().getUsers().get("root");
+ YamlUserConfiguration user = getYamlUserConfigurations(configuration).get("root");
return new Authentication("root", user.getPassword());
}
-
+
+ private Map<String, YamlUserConfiguration> getYamlUserConfigurations(final YamlProxyServerConfiguration configuration) {
+ Collection<YamlUserConfiguration> users = YamlUserConfigurationConverter.convertYamlUserConfiguration(configuration.getUsers());
+ return users.stream().collect(Collectors.toMap(YamlUserConfiguration::getUsername, val -> val));
+ }
+
@RequiredArgsConstructor
@Getter
public static class Authentication {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/db/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting_and_encrypt/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting_and_encrypt/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting_and_encrypt/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/dbtbl_with_read_write_splitting_and_encrypt/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/encrypt/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/encrypt/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/encrypt/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/encrypt/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/read_write_splitting/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/read_write_splitting/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/read_write_splitting/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/read_write_splitting/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/sharding_governance/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/sharding_governance/proxy/conf/server.yaml
index f4d424c..79827b6 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/sharding_governance/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/sharding_governance/proxy/conf/server.yaml
@@ -27,10 +27,8 @@ governance:
operationTimeoutMilliseconds: 500
overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/proxy/conf/server.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/proxy/conf/server.yaml
index 9d9f2af..071d334 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/proxy/conf/server.yaml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/docker/tbl/proxy/conf/server.yaml
@@ -27,10 +27,8 @@
# operationTimeoutMilliseconds: 500
# overwrite: true
-authentication:
- users:
- root:
- password: root
+users:
+ - root@:root
props:
max-connections-size-per-query: 1