You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/02/01 06:07:39 UTC
[shardingsphere] branch master updated: Refactor sharding sphere
user (#9241)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 0372707 Refactor sharding sphere user (#9241)
0372707 is described below
commit 03727070b7e6a8b8cece126f227c39a721895d50
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Mon Feb 1 14:06:59 2021 +0800
Refactor sharding sphere user (#9241)
* fill SchemaPrivilege
* revert
* typo
* typo
* typo
* Refactor AuthenticationYamlSwapper
---
.../core/facade/GovernanceFacadeTest.java | 4 +-
.../infra/auth/ShardingSphereUser.java | 11 +++++
.../infra/auth/builtin/DefaultAuthentication.java | 12 ++---
.../yaml/swapper/AuthenticationYamlSwapper.java | 29 +++++++++--
.../auth/builtin/yaml/swapper/UserYamlSwapper.java | 52 --------------------
.../infra/auth/{ => privilege}/PrivilegeType.java | 2 +-
.../auth/{ => privilege}/SchemaPrivilege.java | 2 +-
.../infra/auth/{ => privilege}/TablePrivilege.java | 2 +-
.../swapper/AuthenticationYamlSwapperTest.java | 4 +-
.../builtin/yaml/swapper/UserYamlSwapperTest.java | 56 ----------------------
.../mysql/executor/ShowDatabasesExecutorTest.java | 3 +-
.../mysql/executor/ShowTablesExecutorTest.java | 3 +-
.../mysql/executor/UseDatabaseExecutorTest.java | 3 +-
.../SchemaAssignedDatabaseBackendHandlerTest.java | 3 +-
.../impl/UnicastDatabaseBackendHandlerTest.java | 3 +-
.../frontend/mysql/MySQLFrontendEngineTest.java | 8 ++--
.../mysql/auth/MySQLAuthenticationHandlerTest.java | 12 ++---
.../auth/PostgreSQLAuthenticationEngineTest.java | 2 +-
18 files changed, 63 insertions(+), 148 deletions(-)
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 969c548..f96dafd 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
@@ -74,9 +74,9 @@ public final class GovernanceFacadeTest {
public void assertOnlineInstanceWithParameters() {
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", "", Collections.singleton("db1"));
+ ShardingSphereUser user = new ShardingSphereUser("root", "root", "", Collections.singleton("db1"));
DefaultAuthentication authentication = new DefaultAuthentication();
- authentication.getUsers().put("root", user);
+ authentication.getUsers().add(user);
Properties props = new Properties();
governanceFacade.onlineInstance(Collections.singletonMap("sharding_db", dataSourceConfigMap), ruleConfigurationMap, authentication, props);
verify(configCenter).persistConfigurations("sharding_db", dataSourceConfigMap, ruleConfigurationMap.get("sharding_db"), false);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/ShardingSphereUser.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/ShardingSphereUser.java
index c1cc034..7fb7203 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/ShardingSphereUser.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/ShardingSphereUser.java
@@ -29,9 +29,20 @@ import java.util.Collection;
@Getter
public final class ShardingSphereUser {
+ private final String username;
+
private final String password;
private final String hostname;
private final Collection<String> authorizedSchemas;
+
+ /**
+ * Get grantee.
+ *
+ * @return grantee
+ */
+ public Grantee getGrantee() {
+ return new Grantee(username, hostname);
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/DefaultAuthentication.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/DefaultAuthentication.java
index 52557f0..997ad4e 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/DefaultAuthentication.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/DefaultAuthentication.java
@@ -23,9 +23,8 @@ import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.auth.Grantee;
import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Collection;
+import java.util.LinkedHashSet;
import java.util.Optional;
/**
@@ -34,12 +33,11 @@ import java.util.Optional;
@Getter
public final class DefaultAuthentication implements Authentication {
- private final Map<String, ShardingSphereUser> users = new LinkedHashMap<>();
+ private final Collection<ShardingSphereUser> users = new LinkedHashSet<>();
@Override
public Optional<ShardingSphereUser> findUser(final Grantee grantee) {
- Optional<Entry<String, ShardingSphereUser>> result = users.entrySet().stream().filter(entry -> entry.getKey().equals(grantee.getUsername())
- && (entry.getValue().getHostname().equals(grantee.getHostname()) || Strings.isNullOrEmpty(entry.getValue().getHostname()))).findFirst();
- return result.map(Entry::getValue);
+ return users.stream().filter(entry -> entry.getUsername().equals(grantee.getUsername())
+ && (entry.getHostname().equals(grantee.getHostname()) || Strings.isNullOrEmpty(entry.getHostname()))).findFirst();
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapper.java
index 2a10b0c..44d1626 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapper.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapper.java
@@ -17,12 +17,16 @@
package org.apache.shardingsphere.infra.auth.builtin.yaml.swapper;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlAuthenticationConfiguration;
import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlUserConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -32,19 +36,26 @@ import java.util.Map.Entry;
*/
public final class AuthenticationYamlSwapper implements YamlSwapper<YamlAuthenticationConfiguration, DefaultAuthentication> {
- private final UserYamlSwapper userYamlSwapper = new UserYamlSwapper();
-
@Override
public YamlAuthenticationConfiguration swapToYamlConfiguration(final DefaultAuthentication data) {
YamlAuthenticationConfiguration result = new YamlAuthenticationConfiguration();
Map<String, YamlUserConfiguration> users = new LinkedHashMap<>();
- for (Entry<String, ShardingSphereUser> entry : data.getUsers().entrySet()) {
- users.put(entry.getKey(), userYamlSwapper.swapToYamlConfiguration(entry.getValue()));
+ for (ShardingSphereUser each : data.getUsers()) {
+ users.put(each.getUsername(), swapToYamlConfiguration(each));
}
result.setUsers(users);
return result;
}
+ private YamlUserConfiguration swapToYamlConfiguration(final ShardingSphereUser data) {
+ YamlUserConfiguration result = new YamlUserConfiguration();
+ result.setHostname(data.getHostname());
+ result.setPassword(data.getPassword());
+ String authorizedSchemas = null == data.getAuthorizedSchemas() ? "" : Joiner.on(',').join(data.getAuthorizedSchemas());
+ result.setAuthorizedSchemas(authorizedSchemas);
+ return result;
+ }
+
@Override
public DefaultAuthentication swapToObject(final YamlAuthenticationConfiguration yamlConfig) {
DefaultAuthentication result = new DefaultAuthentication();
@@ -52,8 +63,16 @@ public final class AuthenticationYamlSwapper implements YamlSwapper<YamlAuthenti
return result;
}
for (Entry<String, YamlUserConfiguration> entry : yamlConfig.getUsers().entrySet()) {
- result.getUsers().put(entry.getKey(), userYamlSwapper.swapToObject(entry.getValue()));
+ result.getUsers().add(swapToObject(entry.getKey(), entry.getValue()));
}
return result;
}
+
+ private ShardingSphereUser swapToObject(final String username, final YamlUserConfiguration yamlConfig) {
+ if (Strings.isNullOrEmpty(yamlConfig.getAuthorizedSchemas())) {
+ return new ShardingSphereUser(username, yamlConfig.getPassword(), null == yamlConfig.getHostname() ? "" : yamlConfig.getHostname(), Collections.emptyList());
+ }
+ return new ShardingSphereUser(username, yamlConfig.getPassword(), null == yamlConfig.getHostname() ? "" : yamlConfig.getHostname(),
+ Splitter.on(',').trimResults().splitToList(yamlConfig.getAuthorizedSchemas()));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapper.java
deleted file mode 100644
index 5742b40..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapper.java
+++ /dev/null
@@ -1,52 +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.auth.builtin.yaml.swapper;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
-import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlUserConfiguration;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
-
-import java.util.Collections;
-
-/**
- * User YAML swapper.
- */
-public final class UserYamlSwapper implements YamlSwapper<YamlUserConfiguration, ShardingSphereUser> {
-
- @Override
- public YamlUserConfiguration swapToYamlConfiguration(final ShardingSphereUser data) {
- YamlUserConfiguration result = new YamlUserConfiguration();
- result.setHostname(data.getHostname());
- result.setPassword(data.getPassword());
- String authorizedSchemas = null == data.getAuthorizedSchemas() ? "" : Joiner.on(',').join(data.getAuthorizedSchemas());
- result.setAuthorizedSchemas(authorizedSchemas);
- return result;
- }
-
- @Override
- public ShardingSphereUser swapToObject(final YamlUserConfiguration yamlConfig) {
- if (Strings.isNullOrEmpty(yamlConfig.getAuthorizedSchemas())) {
- return new ShardingSphereUser(yamlConfig.getPassword(), null == yamlConfig.getHostname() ? "" : yamlConfig.getHostname(), Collections.emptyList());
- }
- return new ShardingSphereUser(yamlConfig.getPassword(), null == yamlConfig.getHostname() ? "" : yamlConfig.getHostname(),
- Splitter.on(',').trimResults().splitToList(yamlConfig.getAuthorizedSchemas()));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/PrivilegeType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/PrivilegeType.java
similarity index 95%
rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/PrivilegeType.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/PrivilegeType.java
index 348eb73..671ecf9 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/PrivilegeType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/PrivilegeType.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.auth;
+package org.apache.shardingsphere.infra.auth.privilege;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/SchemaPrivilege.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/SchemaPrivilege.java
similarity index 96%
rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/SchemaPrivilege.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/SchemaPrivilege.java
index 762b50d..6e1db40 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/SchemaPrivilege.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/SchemaPrivilege.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.auth;
+package org.apache.shardingsphere.infra.auth.privilege;
import lombok.Getter;
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/TablePrivilege.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/TablePrivilege.java
similarity index 96%
rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/TablePrivilege.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/TablePrivilege.java
index 7d83752..af8c56c 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/TablePrivilege.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/auth/privilege/TablePrivilege.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.auth;
+package org.apache.shardingsphere.infra.auth.privilege;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapperTest.java
index 9544872..0d780e1 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapperTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/AuthenticationYamlSwapperTest.java
@@ -38,8 +38,8 @@ public final class AuthenticationYamlSwapperTest {
@Test
public void assertSwapToYaml() {
DefaultAuthentication authentication = new DefaultAuthentication();
- authentication.getUsers().put("user1", new ShardingSphereUser("pwd1", "127.0.0.1", Collections.singleton("db1")));
- authentication.getUsers().put("user2", new ShardingSphereUser("pwd2", "127.0.0.2", Collections.singleton("db2")));
+ authentication.getUsers().add(new ShardingSphereUser("user1", "pwd1", "127.0.0.1", Collections.singleton("db1")));
+ authentication.getUsers().add(new ShardingSphereUser("user2", "pwd2", "127.0.0.2", Collections.singleton("db2")));
YamlAuthenticationConfiguration actual = new AuthenticationYamlSwapper().swapToYamlConfiguration(authentication);
assertThat(actual.getUsers().size(), is(2));
assertThat(actual.getUsers().get("user1").getPassword(), is("pwd1"));
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapperTest.java
deleted file mode 100644
index afb33a9..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/auth/builtin/yaml/swapper/UserYamlSwapperTest.java
+++ /dev/null
@@ -1,56 +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.auth.builtin.yaml.swapper;
-
-import org.apache.shardingsphere.infra.auth.ShardingSphereUser;
-import org.apache.shardingsphere.infra.auth.builtin.yaml.config.YamlUserConfiguration;
-import org.junit.Test;
-
-import java.util.Collections;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class UserYamlSwapperTest {
-
- @Test
- public void assertSwapToYaml() {
- YamlUserConfiguration actual = new UserYamlSwapper().swapToYamlConfiguration(new ShardingSphereUser("pwd", "127.0.0.1", Collections.singleton("db1")));
- assertThat(actual.getAuthorizedSchemas(), is("db1"));
- assertThat(actual.getPassword(), is("pwd"));
- assertThat(actual.getHostname(), is("127.0.0.1"));
- }
-
- @Test
- public void assertSwapToObject() {
- YamlUserConfiguration yamlUserConfig = new YamlUserConfiguration();
- yamlUserConfig.setAuthorizedSchemas("db1");
- yamlUserConfig.setPassword("pwd");
- ShardingSphereUser actual = new UserYamlSwapper().swapToObject(yamlUserConfig);
- assertThat(actual.getAuthorizedSchemas().iterator().next(), is("db1"));
- assertThat(actual.getPassword(), is("pwd"));
- }
-
- @Test
- public void assertSwapToObjectWithoutAuthorizedSchemas() {
- YamlUserConfiguration yamlUserConfig = new YamlUserConfiguration();
- yamlUserConfig.setPassword("pwd");
- ShardingSphereUser actual = new UserYamlSwapper().swapToObject(yamlUserConfig);
- assertThat(actual.getAuthorizedSchemas().size(), is(0));
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
index 61c968c..561d515 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
@@ -75,9 +75,8 @@ public final class ShowDatabasesExecutorTest {
}
private DefaultAuthentication getAuthentication() {
- ShardingSphereUser user = new ShardingSphereUser("root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1)));
DefaultAuthentication result = new DefaultAuthentication();
- result.getUsers().put("root", user);
+ result.getUsers().add(new ShardingSphereUser("root", "root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1))));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
index 8d51d32..27c271a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
@@ -70,9 +70,8 @@ public final class ShowTablesExecutorTest {
}
private DefaultAuthentication getAuthentication() {
- ShardingSphereUser user = new ShardingSphereUser("root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1)));
DefaultAuthentication result = new DefaultAuthentication();
- result.getUsers().put("root", user);
+ result.getUsers().add(new ShardingSphereUser("root", "root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1))));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
index 3e6c1f7..1b30e0b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
@@ -74,9 +74,8 @@ public final class UseDatabaseExecutorTest {
}
private DefaultAuthentication getAuthentication() {
- ShardingSphereUser user = new ShardingSphereUser("root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1)));
DefaultAuthentication result = new DefaultAuthentication();
- result.getUsers().put("root", user);
+ result.getUsers().add(new ShardingSphereUser("root", "root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1))));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
index 33da425..eef9ad1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
@@ -107,9 +107,8 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
}
private DefaultAuthentication getAuthentication() {
- ShardingSphereUser user = new ShardingSphereUser("root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1)));
DefaultAuthentication result = new DefaultAuthentication();
- result.getUsers().put("root", user);
+ result.getUsers().add(new ShardingSphereUser("root", "root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1))));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
index 580c1b2..ba02019 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -97,9 +97,8 @@ public final class UnicastDatabaseBackendHandlerTest {
}
private DefaultAuthentication getAuthentication() {
- ShardingSphereUser user = new ShardingSphereUser("root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1)));
DefaultAuthentication result = new DefaultAuthentication();
- result.getUsers().put("root", user);
+ result.getUsers().add(new ShardingSphereUser("root", "root", "", Arrays.asList(String.format(SCHEMA_PATTERN, 0), String.format(SCHEMA_PATTERN, 1))));
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
index c33c495..82dac23 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
@@ -103,7 +103,7 @@ public final class MySQLFrontendEngineTest {
@Test
public void assertAuthWhenLoginSuccess() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
- ShardingSphereUser user = new ShardingSphereUser("", "", Collections.singleton("db1"));
+ ShardingSphereUser user = new ShardingSphereUser("root", "", "", Collections.singleton("db1"));
setAuthentication(user);
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringNulByBytes()).thenReturn("root".getBytes());
@@ -119,7 +119,7 @@ public final class MySQLFrontendEngineTest {
@Test
public void assertAuthWhenLoginFailure() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
- ShardingSphereUser user = new ShardingSphereUser("error", "", Collections.singleton("db1"));
+ ShardingSphereUser user = new ShardingSphereUser("root", "error", "", Collections.singleton("db1"));
setAuthentication(user);
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringNulByBytes()).thenReturn("root".getBytes());
@@ -135,7 +135,7 @@ public final class MySQLFrontendEngineTest {
@Test
public void assertErrorMsgWhenLoginFailure() throws UnknownHostException {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);
- ShardingSphereUser user = new ShardingSphereUser("error", "", Collections.singleton("db1"));
+ ShardingSphereUser user = new ShardingSphereUser("root", "error", "", Collections.singleton("db1"));
setAuthentication(user);
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringNulByBytes()).thenReturn("root".getBytes());
@@ -150,7 +150,7 @@ public final class MySQLFrontendEngineTest {
private void setAuthentication(final ShardingSphereUser user) {
DefaultAuthentication authentication = new DefaultAuthentication();
- authentication.getUsers().put("root", user);
+ authentication.getUsers().add(user);
initProxyContext(authentication);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
index 3f29874..c4dae36 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
@@ -72,35 +72,35 @@ public final class MySQLAuthenticationHandlerTest {
@Test
public void assertLoginWithPassword() {
- setAuthentication(new ShardingSphereUser("root", "", Collections.singleton("db1")));
+ setAuthentication(new ShardingSphereUser("root", "root", "", Collections.singleton("db1")));
byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86, -100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
assertFalse(authenticationHandler.login("root", "", authResponse, "db1").isPresent());
}
@Test
public void assertLoginWithAbsentUser() {
- setAuthentication(new ShardingSphereUser("root", "", Collections.singleton("db1")));
+ setAuthentication(new ShardingSphereUser("root", "root", "", Collections.singleton("db1")));
byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86, -100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
assertThat(authenticationHandler.login("root1", "", authResponse, "db1").orElse(null), is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR));
}
@Test
public void assertLoginWithIncorrectPassword() {
- setAuthentication(new ShardingSphereUser("root", "", Collections.singleton("db1")));
+ setAuthentication(new ShardingSphereUser("root", "root", "", Collections.singleton("db1")));
byte[] authResponse = {0, 89, -20, -27, 65, -120, -64, -101, 86, -100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
assertThat(authenticationHandler.login("root", "", authResponse, "db1").orElse(null), is(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR));
}
@Test
public void assertLoginWithoutPassword() {
- setAuthentication(new ShardingSphereUser(null, "", null));
+ setAuthentication(new ShardingSphereUser("root", null, "", null));
byte[] authResponse = {};
assertFalse(authenticationHandler.login("root", "", authResponse, "db1").isPresent());
}
@Test
public void assertLoginWithUnauthorizedSchema() {
- setAuthentication(new ShardingSphereUser("root", "", Collections.singleton("db1")));
+ setAuthentication(new ShardingSphereUser("root", "root", "", Collections.singleton("db1")));
byte[] authResponse = {-27, 89, -20, -27, 65, -120, -64, -101, 86, -100, -108, -100, 6, -125, -37, 117, 14, -43, 95, -113};
assertThat(authenticationHandler.login("root", "", authResponse, "db2").orElse(null), is(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR));
}
@@ -112,7 +112,7 @@ public final class MySQLAuthenticationHandlerTest {
private void setAuthentication(final ShardingSphereUser user) {
DefaultAuthentication authentication = new DefaultAuthentication();
- authentication.getUsers().put("root", user);
+ authentication.getUsers().add(user);
initProxyContext(authentication);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
index e01d5a9..592d783 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
@@ -126,7 +126,7 @@ public final class PostgreSQLAuthenticationEngineTest {
ProxyContext proxyContext = ProxyContext.getInstance();
StandardMetaDataContexts standardMetaDataContexts = new StandardMetaDataContexts();
- ((DefaultAuthentication) standardMetaDataContexts.getAuthentication()).getUsers().put(username, new ShardingSphereUser(password, "", null));
+ ((DefaultAuthentication) standardMetaDataContexts.getAuthentication()).getUsers().add(new ShardingSphereUser(username, password, "", null));
proxyContext.init(standardMetaDataContexts, mock(TransactionContexts.class));
actual = engine.auth(channelHandlerContext, payload);
assertThat(actual.isFinished(), is(password.equals(inputPassword)));