You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/06/30 02:29:19 UTC
[shardingsphere] branch master updated: Remove native authority (#18694)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 a16275ea28b Remove native authority (#18694)
a16275ea28b is described below
commit a16275ea28b11b0e4a9fe1ae3d28a4497128e7d0
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Thu Jun 30 10:29:12 2022 +0800
Remove native authority (#18694)
* Remove NativeAuthorityProviderAlgorithm related class.
* Adjust unit tests.
* Adjust doc.
---
docs/document/content/dev-manual/proxy.cn.md | 9 +-
docs/document/content/dev-manual/proxy.en.md | 9 +-
.../privilege/DatabasePermittedPrivileges.java | 2 +-
.../model/subject/DatabaseAccessSubject.java | 2 +-
.../natived/NativeAuthorityProviderAlgorithm.java | 58 ----
.../natived/builder/StoragePrivilegeBuilder.java | 160 ---------
.../natived/builder/StoragePrivilegeHandler.java | 73 -----
.../builder/StoragePrivilegeHandlerFactory.java | 46 ---
.../natived/builder/StoragePrivilegeMerger.java | 105 ------
.../builder/dialect/MySQLPrivilegeHandler.java | 285 ----------------
.../builder/dialect/OraclePrivilegeHandler.java | 226 -------------
.../dialect/PostgreSQLPrivilegeHandler.java | 237 --------------
.../builder/dialect/SQLServerPrivilegeHandler.java | 360 ---------------------
.../natived/model/privilege/NativePrivileges.java | 85 -----
.../privilege/admin/AdministrativePrivileges.java | 45 ---
.../privilege/database/DatabasePrivileges.java | 79 -----
.../model/privilege/database/SchemaPrivileges.java | 77 -----
.../model/privilege/database/TablePrivileges.java | 48 ---
.../natived/model/subject/TableAccessSubject.java | 34 --
...rovider.natived.builder.StoragePrivilegeHandler | 21 --
...sphere.authority.spi.AuthorityProviderAlgorithm | 1 -
.../authority/checker/AuthorityCheckerTest.java | 81 +----
.../fixture/FixtureStoragePrivilegeHandler.java | 53 ---
.../NativeAuthorityProviderAlgorithmTest.java | 167 ----------
.../builder/StoragePrivilegeBuilderTest.java | 172 ----------
.../StoragePrivilegeHandlerFactoryTest.java | 37 ---
.../builder/StoragePrivilegeMergerTest.java | 79 -----
.../builder/dialect/MySQLPrivilegeHandlerTest.java | 241 --------------
.../dialect/OraclePrivilegeHandlerTest.java | 176 ----------
.../dialect/PostgreSQLPrivilegeHandlerTest.java | 182 -----------
.../dialect/SQLServerPrivilegeHandlerTest.java | 215 ------------
.../privilege/database/DatabasePrivilegesTest.java | 101 ------
...llPermittedPrivilegesProviderAlgorithmTest.java | 2 +-
...rovider.natived.builder.StoragePrivilegeHandler | 18 --
.../ClusterContextManagerCoordinatorTest.java | 2 +-
.../frontend/mysql/MySQLFrontendEngineTest.java | 2 +-
.../MySQLAuthenticationHandlerTest.java | 2 +-
.../OpenGaussAuthenticationEngineTest.java | 2 +-
.../OpenGaussAuthenticationHandlerTest.java | 2 +-
.../PostgreSQLAuthenticationEngineTest.java | 2 +-
.../PostgreSQLAuthenticationHandlerTest.java | 2 +-
41 files changed, 20 insertions(+), 3480 deletions(-)
diff --git a/docs/document/content/dev-manual/proxy.cn.md b/docs/document/content/dev-manual/proxy.cn.md
index 503e36a609b..2e26a4ba5a1 100644
--- a/docs/document/content/dev-manual/proxy.cn.md
+++ b/docs/document/content/dev-manual/proxy.cn.md
@@ -23,8 +23,7 @@ chapter = true
| ------------------------------- | ---------------------------- |
| AuthorityProviderAlgorithm | 用户权限加载逻辑 |
-| *已知实现类* | *Type* | *详细说明* |
-|-----------------------------------------------------| ---------------- |----------------------------------------------------------------------------------- |
-| NativeAuthorityProviderAlgorithm(已弃用) | NATIVE | 基于后端数据库存取 server.yaml 中配置的权限信息。如果用户不存在,则自动创建用户并默认赋予最高权限 |
-| AllPermittedPrivilegesProviderAlgorithm | ALL_PERMITTED | 默认授予所有权限(不鉴权),不会与实际数据库交互 |
-| SchemaPermittedPrivilegesProviderAlgorithm | DATABASE_PERMITTED| 通过属性 user-database-mappings 配置的权限 |
+| *已知实现类* | *Type* | *详细说明* |
+|------------------------------------| ---------------- |----------------------------------------------------------------------------------- |
+| AllPermittedProviderAlgorithm | ALL_PERMITTED | 默认授予所有权限(不鉴权),不会与实际数据库交互 |
+| DatabasePermittedProviderAlgorithm | DATABASE_PERMITTED| 通过属性 user-database-mappings 配置的权限 |
diff --git a/docs/document/content/dev-manual/proxy.en.md b/docs/document/content/dev-manual/proxy.en.md
index 2ea8cffe529..4754e08c6f5 100644
--- a/docs/document/content/dev-manual/proxy.en.md
+++ b/docs/document/content/dev-manual/proxy.en.md
@@ -23,8 +23,7 @@ chapter = true
| ------------------------------- | ------------------------------ |
| AuthorityProviderAlgorithm | User authority loading logic |
-| *Implementation Class* | *Type* | *Description* |
-|-----------------------------------------------------| ---------------- | --------------------------------------------------------------------------------------------------------------------- |
-| NativeAuthorityProviderAlgorithm (Deprecated) | NATIVE | Persist user authority defined in server.yaml into the backend database. An admin user will be created if not existed |
-| AllPermittedPrivilegesProviderAlgorithm | ALL_PERMITTED | All privileges granted to user by default (No authentication). Will not interact with the actual database |
-| SchemaPermittedPrivilegesProviderAlgorithm | DATABASE_PERMITTED | Permissions configured through the attribute user-database-mappings |
+| *Implementation Class* | *Type* | *Description* |
+|----------------------------------------------| ---------------- | --------------------------------------------------------------------------------------------------------------------- |
+| AllPermittedProviderAlgorithm | ALL_PERMITTED | All privileges granted to user by default (No authentication). Will not interact with the actual database |
+| DatabasePermittedProviderAlgorithm | DATABASE_PERMITTED | Permissions configured through the attribute user-database-mappings |
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
index f585cc7857b..9bee76f3941 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
@@ -21,7 +21,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.authority.model.AccessSubject;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.subject.DatabaseAccessSubject;
+import org.apache.shardingsphere.authority.provider.database.model.subject.DatabaseAccessSubject;
import java.util.Collection;
import java.util.Set;
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/DatabaseAccessSubject.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
similarity index 93%
rename from shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/DatabaseAccessSubject.java
rename to shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
index 3524f2d4c9c..737a68cb1ac 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/DatabaseAccessSubject.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.provider.natived.model.subject;
+package org.apache.shardingsphere.authority.provider.database.model.subject;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java
deleted file mode 100644
index 18763d5035b..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java
+++ /dev/null
@@ -1,58 +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.authority.provider.natived;
-
-import lombok.Getter;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeBuilder;
-import org.apache.shardingsphere.authority.registry.UserPrivilegeMapAuthorityRegistry;
-import org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Native authority provide algorithm.
- *
- * @deprecated This algorithm will be removed in a future version.
-*/
-@Deprecated
-public final class NativeAuthorityProviderAlgorithm implements AuthorityProviderAlgorithm {
-
- @Getter
- private Properties props;
-
- @Override
- public void init(final Properties props) {
- this.props = props;
- }
-
- @Override
- public AuthorityRegistry buildAuthorityRegistry(final Map<String, ShardingSphereDatabase> databases, final Collection<ShardingSphereUser> users) {
- return new UserPrivilegeMapAuthorityRegistry(StoragePrivilegeBuilder.build(new LinkedList<>(databases.values()), users));
- }
-
- @Override
- public String getType() {
- return "NATIVE";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java
deleted file mode 100644
index b6c54f43993..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilder.java
+++ /dev/null
@@ -1,160 +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.authority.provider.natived.builder;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * Storage privilege builder.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StoragePrivilegeBuilder {
-
- private static final long FUTURE_GET_TIME_OUT_MILLISECONDS = 5000L;
-
- /**
- * Build privileges.
- *
- * @param databases databases
- * @param users users
- * @return privileges
- */
- public static Map<ShardingSphereUser, NativePrivileges> build(final Collection<ShardingSphereDatabase> databases, final Collection<ShardingSphereUser> users) {
- return databases.isEmpty() ? buildPrivilegesInCache(users) : buildPrivilegesInStorage(databases, users);
- }
-
- private static Map<ShardingSphereUser, NativePrivileges> buildPrivilegesInCache(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>(users.size(), 1);
- NativePrivileges privileges = new NativePrivileges();
- privileges.setSuperPrivilege();
- users.forEach(each -> result.put(each, privileges));
- return result;
- }
-
- private static Map<ShardingSphereUser, NativePrivileges> buildPrivilegesInStorage(final Collection<ShardingSphereDatabase> databases, final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>(users.size(), 1);
- databases.stream().map(each -> buildPrivilegesInStorage(each, users)).forEach(result::putAll);
- return result;
- }
-
- private static Map<ShardingSphereUser, NativePrivileges> buildPrivilegesInStorage(final ShardingSphereDatabase database, final Collection<ShardingSphereUser> users) {
- DatabaseType databaseType = DatabaseTypeEngine.getDatabaseType(database.getResource().getAllInstanceDataSources());
- Optional<StoragePrivilegeHandler> handler = StoragePrivilegeHandlerFactory.findInstance(databaseType.getType());
- if (!handler.isPresent()) {
- return buildPrivilegesInCache(users);
- }
- save(database.getResource().getAllInstanceDataSources(), users, handler.get());
- Map<ShardingSphereUser, Collection<NativePrivileges>> result = load(database.getResource().getAllInstanceDataSources(), users, handler.get());
- checkConsistent(result);
- return StoragePrivilegeMerger.merge(result, database.getName(), database.getRuleMetaData().getRules());
- }
-
- private static void save(final Collection<DataSource> dataSources,
- final Collection<ShardingSphereUser> users, final StoragePrivilegeHandler handler) {
- // TODO ExecutorEngine.execute and callback
- ExecutorService executorService = ExecutorEngine.createExecutorEngineWithCPUAndResources(dataSources.size()).getExecutorServiceManager().getExecutorService();
- Collection<Future<?>> tasks = new HashSet<>();
- for (DataSource each : dataSources) {
- tasks.add(executorService.submit(() -> save(each, users, handler)));
- }
- tasks.forEach(each -> {
- try {
- each.get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS);
- } catch (final InterruptedException | ExecutionException | TimeoutException ex) {
- throw new IllegalStateException(String.format("Error while loading privilege with %s", each), ex);
- }
- });
- executorService.shutdownNow();
- }
-
- private static void save(final DataSource dataSource, final Collection<ShardingSphereUser> users, final StoragePrivilegeHandler handler) {
- try {
- Collection<ShardingSphereUser> noneExisted = handler.diff(users, dataSource);
- if (!noneExisted.isEmpty()) {
- handler.create(noneExisted, dataSource);
- handler.grantAll(noneExisted, dataSource);
- }
- } catch (final SQLException ex) {
- throw new ShardingSphereException(ex);
- }
- }
-
- private static Map<ShardingSphereUser, Collection<NativePrivileges>> load(final Collection<DataSource> dataSources,
- final Collection<ShardingSphereUser> users, final StoragePrivilegeHandler handler) {
- Map<ShardingSphereUser, Collection<NativePrivileges>> result = new LinkedHashMap<>(users.size(), 1);
- // TODO ExecutorEngine.execute and callback
- ExecutorService executorService = ExecutorEngine.createExecutorEngineWithCPUAndResources(dataSources.size()).getExecutorServiceManager().getExecutorService();
- Collection<Future<Map<ShardingSphereUser, NativePrivileges>>> futures = new HashSet<>(dataSources.size(), 1);
- for (DataSource each : dataSources) {
- futures.add(executorService.submit(() -> handler.load(users, each)));
- }
- futures.forEach(each -> {
- try {
- fillPrivileges(result, each);
- } catch (final InterruptedException | ExecutionException | TimeoutException ex) {
- throw new IllegalStateException(String.format("Error while loading privilege with %s", each), ex);
- }
- });
- executorService.shutdownNow();
- return result;
- }
-
- private static void fillPrivileges(final Map<ShardingSphereUser, Collection<NativePrivileges>> userPrivilegeMap,
- final Future<Map<ShardingSphereUser, NativePrivileges>> future) throws InterruptedException, ExecutionException, TimeoutException {
- for (Entry<ShardingSphereUser, NativePrivileges> entry : future.get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS).entrySet()) {
- if (!userPrivilegeMap.containsKey(entry.getKey())) {
- userPrivilegeMap.put(entry.getKey(), new LinkedHashSet<>());
- }
- userPrivilegeMap.get(entry.getKey()).add(entry.getValue());
- }
- }
-
- private static void checkConsistent(final Map<ShardingSphereUser, Collection<NativePrivileges>> userPrivilegeMap) {
- userPrivilegeMap.forEach(StoragePrivilegeBuilder::checkConsistent);
- }
-
- private static void checkConsistent(final ShardingSphereUser user, final Collection<NativePrivileges> privileges) {
- NativePrivileges sample = privileges.iterator().next();
- Preconditions.checkState(
- privileges.stream().allMatch(each -> each.equals(sample)), "Different physical instances have different privileges for user %s", user.getGrantee().toString().replaceAll("%", "%%"));
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandler.java
deleted file mode 100644
index 4b431a0ec57..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandler.java
+++ /dev/null
@@ -1,73 +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.authority.provider.natived.builder;
-
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.spi.annotation.SingletonSPI;
-import org.apache.shardingsphere.spi.type.typed.TypedSPI;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Storage privilege handler.
- */
-@SingletonSPI
-public interface StoragePrivilegeHandler extends TypedSPI {
-
- /**
- * Differentiate users between storage and exterior.
- *
- * @param users users from exterior
- * @param dataSource target data source
- * @return users non-existing in storage
- * @throws SQLException SQL exception
- */
- Collection<ShardingSphereUser> diff(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
-
- /**
- * Create users in storage.
- *
- * @param users users to be created
- * @param dataSource target data source
- * @throws SQLException SQL exception
- */
- void create(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
-
- /**
- * Grant all privileges to users.
- *
- * @param users users to be granted
- * @param dataSource target data source
- * @throws SQLException SQL exception
- */
- void grantAll(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
-
- /**
- * Load privileges from storage.
- *
- * @param users users to be loaded
- * @param dataSource target data source
- * @return map of user and privilege
- * @throws SQLException SQL exception
- */
- Map<ShardingSphereUser, NativePrivileges> load(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactory.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactory.java
deleted file mode 100644
index b3366925bfa..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactory.java
+++ /dev/null
@@ -1,46 +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.authority.provider.natived.builder;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-
-/**
- * Storage privilege handler factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StoragePrivilegeHandlerFactory {
-
- static {
- ShardingSphereServiceLoader.register(StoragePrivilegeHandler.class);
- }
-
- /**
- * Find instance of storage privilege handler.
- *
- * @param type type of storage privilege handler
- * @return found instance
- */
- public static Optional<StoragePrivilegeHandler> findInstance(final String type) {
- return TypedSPIRegistry.findRegisteredService(StoragePrivilegeHandler.class, type);
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMerger.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMerger.java
deleted file mode 100644
index 5a3685dc516..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMerger.java
+++ /dev/null
@@ -1,105 +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.authority.provider.natived.builder;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-
-/**
- * Storage privilege merger.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StoragePrivilegeMerger {
-
- /**
- * Merge privileges.
- *
- * @param privileges privileges
- * @param databaseName database name
- * @param rules rules
- * @return map of user and privilege
- */
- public static Map<ShardingSphereUser, NativePrivileges> merge(final Map<ShardingSphereUser, Collection<NativePrivileges>> privileges,
- final String databaseName, final Collection<ShardingSphereRule> rules) {
- Map<ShardingSphereUser, NativePrivileges> result = new HashMap<>(privileges.size(), 1);
- for (Entry<ShardingSphereUser, Collection<NativePrivileges>> entry : privileges.entrySet()) {
- result.put(entry.getKey(), merge(entry.getValue(), databaseName, rules));
- }
- return result;
- }
-
- private static NativePrivileges merge(final Collection<NativePrivileges> privileges, final String databaseName, final Collection<ShardingSphereRule> rules) {
- return privileges.isEmpty() ? new NativePrivileges() : getMergedPrivileges(privileges.iterator().next(), databaseName, rules);
- }
-
- private static NativePrivileges getMergedPrivileges(final NativePrivileges privilege, final String databaseName, final Collection<ShardingSphereRule> rules) {
- NativePrivileges result = new NativePrivileges();
- result.getAdministrativePrivileges().getPrivileges().addAll(privilege.getAdministrativePrivileges().getPrivileges());
- result.getDatabasePrivileges().getGlobalPrivileges().addAll(privilege.getDatabasePrivileges().getGlobalPrivileges());
- result.getDatabasePrivileges().getSpecificPrivileges().putAll(getMergedSchemaPrivileges(privilege, databaseName, rules));
- return result;
- }
-
- private static Map<String, SchemaPrivileges> getMergedSchemaPrivileges(final NativePrivileges privilege, final String databaseName, final Collection<ShardingSphereRule> rules) {
- Map<String, SchemaPrivileges> result = new HashMap<>(privilege.getDatabasePrivileges().getSpecificPrivileges().size(), 1);
- for (Entry<String, SchemaPrivileges> entry : privilege.getDatabasePrivileges().getSpecificPrivileges().entrySet()) {
- if (!result.containsKey(databaseName)) {
- SchemaPrivileges schemaPrivileges = new SchemaPrivileges(databaseName);
- schemaPrivileges.getGlobalPrivileges().addAll(entry.getValue().getGlobalPrivileges());
- schemaPrivileges.getSpecificPrivileges().putAll(getMergedTablePrivileges(entry.getValue(), rules));
- result.put(databaseName, schemaPrivileges);
- }
- }
- return result;
- }
-
- private static Map<String, TablePrivileges> getMergedTablePrivileges(final SchemaPrivileges privilege, final Collection<ShardingSphereRule> rules) {
- Map<String, TablePrivileges> result = new HashMap<>(privilege.getSpecificPrivileges().size(), 1);
- for (Entry<String, TablePrivileges> entry : privilege.getSpecificPrivileges().entrySet()) {
- Optional<String> logicalTable = findLogicalTable(entry, rules);
- if (logicalTable.isPresent() && !result.containsKey(logicalTable.get())) {
- result.put(logicalTable.get(), new TablePrivileges(logicalTable.get(), entry.getValue().getPrivileges()));
- }
- }
- return result;
- }
-
- private static Optional<String> findLogicalTable(final Entry<String, TablePrivileges> privilege, final Collection<ShardingSphereRule> rules) {
- for (ShardingSphereRule each : rules) {
- if (each instanceof DataNodeContainedRule) {
- Optional<String> logicalTable = ((DataNodeContainedRule) each).findLogicTableByActualTable(privilege.getKey());
- if (logicalTable.isPresent()) {
- return logicalTable;
- }
- }
- }
- return Optional.empty();
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandler.java
deleted file mode 100644
index b02568b175b..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandler.java
+++ /dev/null
@@ -1,285 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * MySQL privilege handler.
- */
-public final class MySQLPrivilegeHandler implements StoragePrivilegeHandler {
-
- private static final String CREATE_USER_SQL = "CREATE USER %s";
-
- private static final String GRANT_ALL_SQL = "GRANT ALL ON *.* TO %s";
-
- private static final String GLOBAL_PRIVILEGE_SQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
-
- private static final String SCHEMA_PRIVILEGE_SQL = "SELECT * FROM mysql.db WHERE (user, host) in (%s)";
-
- private static final String TABLE_PRIVILEGE_SQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
-
- @Override
- public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Collection<Grantee> grantees = new LinkedList<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
- while (resultSet.next()) {
- grantees.add(new Grantee(resultSet.getString("user"), resultSet.getString("host")));
- }
- }
- return users.stream().filter(each -> !grantees.contains(each.getGrantee())).collect(Collectors.toList());
- }
-
- @Override
- public void create(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- statement.execute(getCreateUsersSQL(users));
- }
- }
-
- private String getCreateUsersSQL(final Collection<ShardingSphereUser> users) {
- String createUsers = users.stream().map(each -> String.format("'%s'@'%s' IDENTIFIED BY '%s'",
- each.getGrantee().getUsername(), each.getGrantee().getHostname(), each.getPassword())).collect(Collectors.joining(", "));
- return String.format(CREATE_USER_SQL, createUsers);
- }
-
- @Override
- public void grantAll(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- statement.execute(getGrantAllSQL(users));
- }
- }
-
- private String getGrantAllSQL(final Collection<ShardingSphereUser> users) {
- String grantUsers = users.stream().map(each -> String.format("'%s'@'%s'",
- each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- return String.format(GRANT_ALL_SQL, grantUsers);
- }
-
- @Override
- public Map<ShardingSphereUser, NativePrivileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>();
- users.forEach(each -> result.put(each, new NativePrivileges()));
- fillGlobalPrivileges(result, dataSource, users);
- fillSchemaPrivileges(result, dataSource, users);
- fillTablePrivileges(result, dataSource, users);
- return result;
- }
-
- private void fillGlobalPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillGlobalPrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillGlobalPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadAdministrativePrivileges(resultSet));
- userPrivilegeMap.get(user.get()).getDatabasePrivileges().getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
- }
- }
-
- private void fillSchemaPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getSchemaPrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillSchemaPrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillSchemaPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- String db = resultSet.getString("Db");
- SchemaPrivileges schemaPrivileges = new SchemaPrivileges(db);
- schemaPrivileges.getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
- userPrivilegeMap.get(user.get()).getDatabasePrivileges().getSpecificPrivileges().put(db, schemaPrivileges);
- }
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillTablePrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- String db = resultSet.getString("Db");
- String tableName = resultSet.getString("Table_name");
- TablePrivileges tablePrivileges = new TablePrivileges(tableName, getPrivileges((String[]) resultSet.getArray("Table_priv").getArray()));
- NativePrivileges privileges = userPrivilegeMap.get(user.get());
- if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
- privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
- }
- privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
- }
- }
-
- private String getGlobalPrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- return String.format(GLOBAL_PRIVILEGE_SQL, userHostTuples);
- }
-
- private String getSchemaPrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname()))
- .collect(Collectors.joining(", "));
- return String.format(SCHEMA_PRIVILEGE_SQL, userHostTuples);
- }
-
- private String getTablePrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname()))
- .collect(Collectors.joining(", "));
- return String.format(TABLE_PRIVILEGE_SQL, userHostTuples);
- }
-
- private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, NativePrivileges> privileges, final ResultSet resultSet) throws SQLException {
- Grantee grantee = new Grantee(resultSet.getString("user"), resultSet.getString("host"));
- return privileges.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
- }
-
- private Collection<PrivilegeType> getPrivileges(final String[] privileges) {
- return Arrays.stream(privileges).map(this::getPrivilegeType).collect(Collectors.toSet());
- }
-
- private PrivilegeType getPrivilegeType(final String privilege) {
- switch (privilege) {
- case "Select":
- return PrivilegeType.SELECT;
- case "Insert":
- return PrivilegeType.INSERT;
- case "Update":
- return PrivilegeType.UPDATE;
- case "Delete":
- return PrivilegeType.DELETE;
- case "Create":
- return PrivilegeType.CREATE;
- case "Alter":
- return PrivilegeType.ALTER;
- case "Drop":
- return PrivilegeType.DROP;
- case "Grant":
- return PrivilegeType.GRANT;
- case "Index":
- return PrivilegeType.INDEX;
- case "References":
- return PrivilegeType.REFERENCES;
- case "Create View":
- return PrivilegeType.CREATE_VIEW;
- case "Show view":
- return PrivilegeType.SHOW_VIEW;
- case "Trigger":
- return PrivilegeType.TRIGGER;
- default:
- throw new UnsupportedOperationException(privilege);
- }
- }
-
- private Collection<PrivilegeType> loadAdministrativePrivileges(final ResultSet resultSet) throws SQLException {
- Collection<PrivilegeType> result = new LinkedList<>();
- addToPrivilegeTypesIfPresent(resultSet.getObject("Super_priv"), PrivilegeType.SUPER, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Reload_priv"), PrivilegeType.RELOAD, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Shutdown_priv"), PrivilegeType.SHUTDOWN, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Process_priv"), PrivilegeType.PROCESS, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("File_priv"), PrivilegeType.FILE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Show_db_priv"), PrivilegeType.SHOW_DB, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Repl_slave_priv"), PrivilegeType.REPL_SLAVE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Repl_client_priv"), PrivilegeType.REPL_CLIENT, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_user_priv"), PrivilegeType.CREATE_USER, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_tablespace_priv"), PrivilegeType.CREATE_TABLESPACE, result);
- return result;
- }
-
- private Collection<PrivilegeType> loadDatabaseGlobalPrivileges(final ResultSet resultSet) throws SQLException {
- Collection<PrivilegeType> result = new LinkedList<>();
- addToPrivilegeTypesIfPresent(resultSet.getObject("Select_priv"), PrivilegeType.SELECT, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Insert_priv"), PrivilegeType.INSERT, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Update_priv"), PrivilegeType.UPDATE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Delete_priv"), PrivilegeType.DELETE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_priv"), PrivilegeType.CREATE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Alter_priv"), PrivilegeType.ALTER, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Drop_priv"), PrivilegeType.DROP, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Grant_priv"), PrivilegeType.GRANT, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Index_priv"), PrivilegeType.INDEX, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("References_priv"), PrivilegeType.REFERENCES, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_tmp_table_priv"), PrivilegeType.CREATE_TMP, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Lock_tables_priv"), PrivilegeType.LOCK_TABLES, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Execute_priv"), PrivilegeType.EXECUTE, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_view_priv"), PrivilegeType.CREATE_VIEW, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Show_view_priv"), PrivilegeType.SHOW_VIEW, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Create_routine_priv"), PrivilegeType.CREATE_PROC, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Alter_routine_priv"), PrivilegeType.ALTER_PROC, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Event_priv"), PrivilegeType.EVENT, result);
- addToPrivilegeTypesIfPresent(resultSet.getObject("Trigger_priv"), PrivilegeType.TRIGGER, result);
- return result;
- }
-
- private void addToPrivilegeTypesIfPresent(final Object hasPrivilege, final PrivilegeType privilegeType, final Collection<PrivilegeType> target) {
- if ("Y".equals(hasPrivilege)) {
- target.add(privilegeType);
- }
- if (hasPrivilege instanceof Boolean && (boolean) hasPrivilege) {
- target.add(privilegeType);
- }
- }
-
- @Override
- public String getType() {
- return "MySQL";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandler.java
deleted file mode 100644
index 9705ca42ea5..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandler.java
+++ /dev/null
@@ -1,226 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Oracle privilege handler.
- */
-public final class OraclePrivilegeHandler implements StoragePrivilegeHandler {
-
- private static final String CREATE_USER_SQL = "CREATE USER %s IDENTIFIED BY %s";
-
- private static final String GRANT_ALL_SQL = "GRANT ALL PRIVILEGES TO %s";
-
- private static final String SYS_PRIVILEGE_SQL = "SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE IN (%s)";
-
- private static final String TABLE_PRIVILEGE_SQL = "SELECT GRANTEE, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE, GRANTABLE, INHERITED FROM ALL_TAB_PRIVS WHERE GRANTEE IN (%s)";
-
- @Override
- public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Collection<Grantee> grantees = new LinkedList<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getSysPrivilegesSQL(users))) {
- while (resultSet.next()) {
- grantees.add(new Grantee(resultSet.getString("GRANTEE"), ""));
- }
- }
- return users.stream().filter(each -> !grantees.contains(each.getGrantee())).collect(Collectors.toList());
- }
-
- @Override
- public void create(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- for (ShardingSphereUser each : users) {
- statement.execute(String.format(CREATE_USER_SQL, each.getGrantee().getUsername(), each.getPassword()));
- }
- }
- }
-
- @Override
- public void grantAll(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- for (ShardingSphereUser each : users) {
- statement.execute(String.format(GRANT_ALL_SQL, each.getGrantee().getUsername()));
- }
- }
- }
-
- @Override
- public Map<ShardingSphereUser, NativePrivileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>();
- users.forEach(each -> result.put(each, new NativePrivileges()));
- fillSysPrivileges(result, dataSource, users);
- fillTablePrivileges(result, dataSource, users);
- return result;
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final DataSource dataSource,
- final Collection<ShardingSphereUser> users) throws SQLException {
- Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache = new HashMap<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
- while (resultSet.next()) {
- collectTablePrivileges(privilegeCache, resultSet);
- }
- }
- fillTablePrivileges(privilegeCache, userPrivilegeMap);
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache,
- final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap) {
- for (Entry<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> entry : privilegeCache.entrySet()) {
- for (String db : entry.getValue().keySet()) {
- for (String tableName : entry.getValue().get(db).keySet()) {
- TablePrivileges tablePrivileges = new TablePrivileges(tableName, entry.getValue().get(db).get(tableName));
- NativePrivileges privileges = userPrivilegeMap.get(entry.getKey());
- if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
- privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
- }
- privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
- }
- }
- }
- }
-
- private void collectTablePrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final ResultSet resultSet) throws SQLException {
- String db = resultSet.getString("TABLE_SCHEMA");
- String tableName = resultSet.getString("TABLE_NAME");
- String privilegeType = resultSet.getString("PRIVILEGE");
- boolean hasPrivilege = "YES".equalsIgnoreCase(resultSet.getString("GRANTABLE"));
- String grantee = resultSet.getString("GRANTEE");
- if (hasPrivilege) {
- privilegeCache
- .computeIfAbsent(new ShardingSphereUser(grantee, "", ""), k -> new HashMap<>())
- .computeIfAbsent(db, k -> new HashMap<>())
- .computeIfAbsent(tableName, k -> new ArrayList<>())
- .add(getPrivilegeType(privilegeType));
- }
- }
-
- private void fillSysPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final DataSource dataSource,
- final Collection<ShardingSphereUser> users) throws SQLException {
- Map<ShardingSphereUser, List<PrivilegeType>> privilegeCache = new HashMap<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getSysPrivilegesSQL(users))) {
- while (resultSet.next()) {
- collectSysPrivileges(privilegeCache, resultSet);
- }
- }
- fillSysPrivileges(privilegeCache, userPrivilegeMap);
- }
-
- private void fillSysPrivileges(final Map<ShardingSphereUser, List<PrivilegeType>> privilegeCache, final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap) {
- for (Entry<ShardingSphereUser, List<PrivilegeType>> entry : privilegeCache.entrySet()) {
- userPrivilegeMap.get(entry.getKey()).getAdministrativePrivileges().getPrivileges().addAll(entry.getValue());
- }
- }
-
- private void collectSysPrivileges(final Map<ShardingSphereUser, List<PrivilegeType>> privilegeCache, final ResultSet resultSet) throws SQLException {
- String privilegeType = resultSet.getString("PRIVILEGE");
- String grantee = resultSet.getString("GRANTEE");
- privilegeCache
- .computeIfAbsent(new ShardingSphereUser(grantee, "", ""), k -> new ArrayList<>())
- .add(getPrivilegeType(privilegeType));
- }
-
- private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Grantee grantee = new Grantee(resultSet.getString("rolname"), "");
- return userPrivilegeMap.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
- }
-
- private String getSysPrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(SYS_PRIVILEGE_SQL, userList);
- }
-
- private String getTablePrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(TABLE_PRIVILEGE_SQL, userList);
- }
-
- private PrivilegeType getPrivilegeType(final String privilege) {
- switch (privilege) {
- case "SELECT":
- return PrivilegeType.SELECT;
- case "INSERT":
- return PrivilegeType.INSERT;
- case "UPDATE":
- return PrivilegeType.UPDATE;
- case "DELETE":
- return PrivilegeType.DELETE;
- case "REFERENCES":
- return PrivilegeType.REFERENCES;
- case "INDEX":
- return PrivilegeType.INDEX;
- case "EXECUTE":
- return PrivilegeType.EXECUTE;
- case "CREATE PROCEDURE":
- return PrivilegeType.CREATE_PROC;
- case "CREATE ROLE":
- return PrivilegeType.CREATE_ROLE;
- case "CREATE SEQUENCE":
- return PrivilegeType.CREATE_SEQUENCE;
- case "CREATE TABLESPACE":
- return PrivilegeType.CREATE_TABLESPACE;
- case "CREATE USER":
- return PrivilegeType.CREATE_USER;
- case "CREATE VIEW":
- return PrivilegeType.CREATE_VIEW;
- case "SYSDBA":
- return PrivilegeType.SUPER;
- // TODO other privilege
- default:
- throw new UnsupportedOperationException(privilege);
- }
- }
-
- @Override
- public String getType() {
- return "Oracle";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandler.java
deleted file mode 100644
index 781a597a407..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandler.java
+++ /dev/null
@@ -1,237 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * PostgreSQL privilege handler.
- */
-public final class PostgreSQLPrivilegeHandler implements StoragePrivilegeHandler {
-
- private static final String CREATE_USER_SQL = "CREATE USER %s WITH PASSWORD '%s'";
-
- private static final String GRANT_ALL_SQL = "ALTER USER %s WITH SUPERUSER";
-
- private static final String ROLES_SQL = "SELECT * FROM pg_roles WHERE rolname IN (%s)";
-
- private static final String TABLE_PRIVILEGE_SQL = "SELECT grantor, grantee, table_catalog, table_name, privilege_type, is_grantable FROM information_schema.table_privileges WHERE grantee IN (%s)";
-
- @Override
- public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Collection<Grantee> grantees = new LinkedList<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getRolePrivilegesSQL(users))) {
- while (resultSet.next()) {
- grantees.add(new Grantee(resultSet.getString("rolname"), ""));
- }
- }
- return users.stream().filter(each -> !grantees.contains(each.getGrantee())).collect(Collectors.toList());
- }
-
- @Override
- public void create(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- for (ShardingSphereUser each : users) {
- statement.execute(getCreateUsersSQL(each));
- }
- }
- }
-
- private String getCreateUsersSQL(final ShardingSphereUser user) {
- return String.format(CREATE_USER_SQL, user.getGrantee().getUsername(), user.getPassword());
- }
-
- @Override
- public void grantAll(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- for (ShardingSphereUser each : users) {
- statement.execute(getGrantAllSQL(each));
- }
- }
- }
-
- private String getGrantAllSQL(final ShardingSphereUser user) {
- return String.format(GRANT_ALL_SQL, user.getGrantee().getUsername());
- }
-
- @Override
- public Map<ShardingSphereUser, NativePrivileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>();
- users.forEach(each -> result.put(each, new NativePrivileges()));
- fillTablePrivileges(result, dataSource, users);
- fillRolePrivileges(result, dataSource, users);
- return result;
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache = new HashMap<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
- while (resultSet.next()) {
- collectPrivileges(privilegeCache, resultSet);
- }
- }
- fillTablePrivileges(privilegeCache, userPrivilegeMap);
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache,
- final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap) {
- for (Entry<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> entry : privilegeCache.entrySet()) {
- for (String db : entry.getValue().keySet()) {
- for (String tableName : entry.getValue().get(db).keySet()) {
- TablePrivileges tablePrivileges = new TablePrivileges(tableName, entry.getValue().get(db).get(tableName));
- NativePrivileges privileges = userPrivilegeMap.get(entry.getKey());
- if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
- privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
- }
- privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
- }
- }
- }
- }
-
- private void collectPrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final ResultSet resultSet) throws SQLException {
- String db = resultSet.getString("table_catalog");
- String tableName = resultSet.getString("table_name");
- String privilegeType = resultSet.getString("privilege_type");
- boolean hasPrivilege = Boolean.TRUE.toString().equalsIgnoreCase(resultSet.getString("is_grantable"));
- String grantee = resultSet.getString("grantee");
- if (hasPrivilege) {
- privilegeCache
- .computeIfAbsent(new ShardingSphereUser(grantee, "", ""), k -> new HashMap<>())
- .computeIfAbsent(db, k -> new HashMap<>())
- .computeIfAbsent(tableName, k -> new ArrayList<>())
- .add(getPrivilegeType(privilegeType));
- }
- }
-
- private void fillRolePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getRolePrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillRolePrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillRolePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadRolePrivileges(resultSet));
- }
- }
-
- private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Grantee grantee = new Grantee(resultSet.getString("rolname"), "");
- return userPrivilegeMap.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
- }
-
- private Collection<PrivilegeType> loadRolePrivileges(final ResultSet resultSet) throws SQLException {
- Collection<PrivilegeType> result = new LinkedList<>();
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolsuper"), PrivilegeType.SUPER, result);
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolcreaterole"), PrivilegeType.CREATE_ROLE, result);
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolcreatedb"), PrivilegeType.CREATE_DATABASE, result);
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolreplication"), PrivilegeType.REPL_CLIENT, result);
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolinherit"), PrivilegeType.INHERIT, result);
- addToPrivilegeTypesIfPresent(resultSet.getBoolean("rolcanlogin"), PrivilegeType.CAN_LOGIN, result);
- return result;
- }
-
- private String getTablePrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(TABLE_PRIVILEGE_SQL, userList);
- }
-
- private String getRolePrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(ROLES_SQL, userList);
- }
-
- private PrivilegeType getPrivilegeType(final String privilege) {
- switch (privilege) {
- case "SELECT":
- return PrivilegeType.SELECT;
- case "INSERT":
- return PrivilegeType.INSERT;
- case "UPDATE":
- return PrivilegeType.UPDATE;
- case "DELETE":
- return PrivilegeType.DELETE;
- case "TRUNCATE":
- return PrivilegeType.TRUNCATE;
- case "REFERENCES":
- return PrivilegeType.REFERENCES;
- case "TRIGGER":
- return PrivilegeType.TRIGGER;
- case "CREATE":
- return PrivilegeType.CREATE;
- case "EXECUTE":
- return PrivilegeType.EXECUTE;
- case "USAGE":
- return PrivilegeType.USAGE;
- case "CONNECT":
- return PrivilegeType.CONNECT;
- case "TEMPORARY":
- return PrivilegeType.TEMPORARY;
- default:
- throw new UnsupportedOperationException(privilege);
- }
- }
-
- private void addToPrivilegeTypesIfPresent(final boolean hasPrivilege, final PrivilegeType privilegeType, final Collection<PrivilegeType> target) {
- if (hasPrivilege) {
- target.add(privilegeType);
- }
- }
-
- @Override
- public String getType() {
- return "PostgreSQL";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
deleted file mode 100644
index 31dda14b1d3..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
+++ /dev/null
@@ -1,360 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * SQLServer privilege handler.
- */
-public final class SQLServerPrivilegeHandler implements StoragePrivilegeHandler {
-
- private static final String QUESTION_MARK = "?";
-
- private static final String LINE_BREAK = "\n";
-
- private static final String GO_SQL = "GO";
-
- private static final String CREATE_LOGIN_USER_SQL = "CREATE LOGIN %s WITH PASSWORD = '%s';";
-
- private static final String CREATE_DATABASE_USER_SQL = "CREATE USER %s FOR LOGIN %s;";
-
- private static final String GRANT_ALL_SQL = "GRANT CONTROL ON DATABASE::%s TO %s";
-
- private static final String GLOBAL_PRIVILEGE_SQL =
- "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, pe.permission_name AS PRIVILEGE_TYPE"
- + "FROM sys.server_principals AS pr JOIN sys.server_permissions AS pe"
- + "ON pe.grantee_principal_id = pr.principal_id WHERE pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name";
-
- private static final String SCHEMA_PRIVILEGE_SQL =
- "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, pe.permission_name AS PRIVILEGE_TYPE, o.name AS DB"
- + "FROM sys.database_principals AS pr JOIN sys.database_permissions AS pe"
- + "ON pe.grantee_principal_id = pr.principal_id JOIN sys.objects AS o"
- + "ON pe.major_id = o.object_id WHERE pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name, o.name";
-
- private static final String TABLE_PRIVILEGE_SQL =
- "SELECT GRANTOR, GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE_TYPE, IS_GRANTABLE from INFORMATION_SCHEMA.TABLE_PRIVILEGES WHERE GRANTEE IN (%s)";
-
- @Override
- public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Collection<Grantee> grantees = new LinkedList<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
- while (resultSet.next()) {
- grantees.add(new Grantee(resultSet.getString("GRANTEE"), ""));
- }
- }
- return users.stream().filter(each -> !grantees.contains(each.getGrantee())).collect(Collectors.toList());
- }
-
- @Override
- public void create(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- for (ShardingSphereUser each : users) {
- statement.execute(getCreateUsersSQL(each));
- }
- }
- }
-
- private String getCreateUsersSQL(final ShardingSphereUser user) {
- StringBuilder result = new StringBuilder();
- result.append(String.format(CREATE_LOGIN_USER_SQL, user.getGrantee().getUsername(), user.getPassword())).append(LINE_BREAK);
- result.append(GO_SQL).append(LINE_BREAK);
- result.append(String.format(CREATE_DATABASE_USER_SQL, user.getGrantee().getUsername(), user.getGrantee().getUsername())).append(LINE_BREAK);
- result.append(GO_SQL);
- return result.toString();
- }
-
- @Override
- public void grantAll(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
- String databaseName = getDatabaseName(connection.getMetaData().getURL());
- for (ShardingSphereUser each : users) {
- statement.execute(getGrantAllSQL(databaseName, each));
- }
- }
- }
-
- private String getDatabaseName(final String url) {
- if (url.contains(QUESTION_MARK)) {
- return url.substring(url.indexOf("DatabaseName=") + 1, url.indexOf("?"));
- }
- return url.substring(url.indexOf("DatabaseName=") + 1);
- }
-
- private String getGrantAllSQL(final String databaseName, final ShardingSphereUser user) {
- return String.format(GRANT_ALL_SQL, databaseName, user.getGrantee().getUsername());
- }
-
- @Override
- public Map<ShardingSphereUser, NativePrivileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, NativePrivileges> result = new LinkedHashMap<>();
- users.forEach(each -> result.put(each, new NativePrivileges()));
- fillGlobalPrivileges(result, dataSource, users);
- fillSchemaPrivileges(result, dataSource, users);
- fillTablePrivileges(result, dataSource, users);
- return result;
- }
-
- private void fillGlobalPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap,
- final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillGlobalPrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillGlobalPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadPrivileges(resultSet));
- }
- }
-
- private void fillSchemaPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getSchemaPrivilegesSQL(users))) {
- while (resultSet.next()) {
- fillSchemaPrivileges(userPrivilegeMap, resultSet);
- }
- }
- }
-
- private void fillSchemaPrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
- if (user.isPresent()) {
- String db = resultSet.getString("DB");
- SchemaPrivileges schemaPrivileges = new SchemaPrivileges(db);
- schemaPrivileges.getGlobalPrivileges().addAll(loadPrivileges(resultSet));
- userPrivilegeMap.get(user.get()).getDatabasePrivileges().getSpecificPrivileges().put(db, schemaPrivileges);
- }
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
- Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache = new HashMap<>();
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
- while (resultSet.next()) {
- collectPrivileges(privilegeCache, resultSet);
- }
- }
- fillTablePrivileges(privilegeCache, userPrivilegeMap);
- }
-
- private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap) {
- for (Entry<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> entry : privilegeCache.entrySet()) {
- for (String db : entry.getValue().keySet()) {
- for (String tableName : entry.getValue().get(db).keySet()) {
- TablePrivileges tablePrivileges = new TablePrivileges(tableName, entry.getValue().get(db).get(tableName));
- NativePrivileges privileges = userPrivilegeMap.get(entry.getKey());
- if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
- privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
- }
- privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
- }
- }
- }
- }
-
- private void collectPrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final ResultSet resultSet) throws SQLException {
- String db = resultSet.getString("TABLE_CATALOG");
- String tableName = resultSet.getString("TABLE_NAME");
- String privilegeType = resultSet.getString("PRIVILEGE_TYPE");
- boolean hasPrivilege = "YES".equalsIgnoreCase(resultSet.getString("IS_GRANTABLE"));
- String grantee = resultSet.getString("GRANTEE");
- if (hasPrivilege) {
- privilegeCache
- .computeIfAbsent(new ShardingSphereUser(grantee, "", ""), k -> new HashMap<>())
- .computeIfAbsent(db, k -> new HashMap<>())
- .computeIfAbsent(tableName, k -> new ArrayList<>())
- .add(getPrivilegeType(privilegeType));
- }
- }
-
- private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, NativePrivileges> privileges, final ResultSet resultSet) throws SQLException {
- Grantee grantee = new Grantee(resultSet.getString("GRANTEE"), "");
- return privileges.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
- }
-
- private String getGlobalPrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(GLOBAL_PRIVILEGE_SQL, userList);
- }
-
- private String getSchemaPrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(SCHEMA_PRIVILEGE_SQL, userList);
- }
-
- private String getTablePrivilegesSQL(final Collection<ShardingSphereUser> users) {
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- return String.format(TABLE_PRIVILEGE_SQL, userList);
- }
-
- private PrivilegeType getPrivilegeType(final String privilege) {
- switch (privilege) {
- case "SELECT":
- return PrivilegeType.SELECT;
- case "INSERT":
- return PrivilegeType.INSERT;
- case "UPDATE":
- return PrivilegeType.UPDATE;
- case "DELETE":
- return PrivilegeType.DELETE;
- case "CREATE FUNCTION":
- return PrivilegeType.CREATE_FUNCTION;
- case "REFERENCES":
- return PrivilegeType.REFERENCES;
- case "CREATE TABLE":
- return PrivilegeType.CREATE_TABLE;
- case "CREATE DATABASE":
- return PrivilegeType.CREATE_DATABASE;
- case "EXECUTE":
- return PrivilegeType.EXECUTE;
- case "CREATE VIEW":
- return PrivilegeType.CREATE_VIEW;
- case "CREATE PROCEDURE":
- return PrivilegeType.CREATE_PROC;
- case "BACKUP DATABASE":
- return PrivilegeType.BACKUP_DATABASE;
- case "CREATE DEFAULT":
- return PrivilegeType.CREATE_DEFAULT;
- case "BACKUP LOG":
- return PrivilegeType.BACKUP_LOG;
- case "CREATE RULE":
- return PrivilegeType.CREATE_RULE;
- case "CONNECT":
- return PrivilegeType.CONNECT;
- case "ADMINISTER BULK OPERATIONS":
- return PrivilegeType.ADMINISTER_BULK_OPERATIONS;
- case "ALTER ANY AVAILABILITY GROUP":
- return PrivilegeType.ALTER_ANY_AVAILABILITY_GROUP;
- case "ALTER ANY CONNECTION":
- return PrivilegeType.ALTER_ANY_CONNECTION;
- case "ALTER ANY CREDENTIAL":
- return PrivilegeType.ALTER_ANY_CREDENTIAL;
- case "ALTER ANY DATABASE":
- return PrivilegeType.ALTER_ANY_DATABASE;
- case "ALTER ANY ENDPOINT":
- return PrivilegeType.ALTER_ANY_ENDPOINT;
- case "ALTER ANY EVENT SESSION":
- return PrivilegeType.ALTER_ANY_EVENT_SESSION;
- case "ALTER ANY EVENT NOTIFICATION":
- return PrivilegeType.ALTER_ANY_EVENT_NOTIFICATION;
- case "ALTER ANY LINKED SERVER":
- return PrivilegeType.ALTER_ANY_LINKED_SERVER;
- case "ALTER ANY LOGIN":
- return PrivilegeType.ALTER_ANY_LOGIN;
- case "ALTER ANY SERVER AUDIT":
- return PrivilegeType.ALTER_ANY_SERVER_AUDIT;
- case "ALTER ANY SERVER ROLE":
- return PrivilegeType.ALTER_ANY_SERVER_ROLE;
- case "ALTER RESOURCES":
- return PrivilegeType.ALTER_RESOURCES;
- case "ALTER SERVER STATE":
- return PrivilegeType.ALTER_SERVER_STATE;
- case "ALTER SETTINGS":
- return PrivilegeType.ALTER_SETTINGS;
- case "ALTER TRACE":
- return PrivilegeType.ALTER_TRACE;
- case "AUTHENTICATE SERVER":
- return PrivilegeType.AUTHENTICATE_SERVER;
- case "CONNECT ANY DATABASE":
- return PrivilegeType.CONNECT_ANY_DATABASE;
- case "CONNECT SQL":
- return PrivilegeType.CONNECT_SQL;
- case "CONTROL SERVER":
- return PrivilegeType.CONTROL_SERVER;
- case "CREATE ANY DATABASE":
- return PrivilegeType.CREATE_ANY_DATABASE;
- case "CREATE AVAILABILITY GROUP":
- return PrivilegeType.CREATE_AVAILABILITY_GROUP;
- case "CREATE DDL EVENT NOTIFICATION":
- return PrivilegeType.CREATE_DDL_EVENT_NOTIFICATION;
- case "CREATE ENDPOINT":
- return PrivilegeType.CREATE_ENDPOINT;
- case "CREATE SERVER ROLE":
- return PrivilegeType.CREATE_SERVER_ROLE;
- case "CREATE TRACE EVENT NOTIFICATION ":
- return PrivilegeType.CREATE_TRACE_EVENT_NOTIFICATION;
- case "EXTERNAL ACCESS ASSEMBLY":
- return PrivilegeType.EXTERNAL_ACCESS_ASSEMBLY;
- case "IMPERSONATE ANY LOGIN":
- return PrivilegeType.IMPERSONATE_ANY_LOGIN;
- case "SELECT ALL USER SECURABLES":
- return PrivilegeType.SELECT_ALL_USER_SECURABLES;
- case "SHUTDOWN":
- return PrivilegeType.SHUTDOWN;
- case "UNSAFE ASSEMBLY":
- return PrivilegeType.UNSAFE_ASSEMBLY;
- case "VIEW ANY DATABASE":
- return PrivilegeType.VIEW_ANY_DATABASE;
- case "VIEW ANY DEFINITION":
- return PrivilegeType.VIEW_ANY_DEFINITION;
- case "VIEW SERVER STATE ":
- return PrivilegeType.VIEW_SERVER_STATE;
- default:
- throw new UnsupportedOperationException(privilege);
- }
- }
-
- private Collection<PrivilegeType> loadPrivileges(final ResultSet resultSet) throws SQLException {
- Collection<PrivilegeType> result = new LinkedList<>();
- if ("GRANT".equals(resultSet.getString("STATE"))) {
- result.add(getPrivilegeType(resultSet.getString("PRIVILEGE_TYPE")));
- }
- return result;
- }
-
- @Override
- public String getType() {
- return "SQLServer";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/NativePrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/NativePrivileges.java
deleted file mode 100644
index 2f4bebd760a..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/NativePrivileges.java
+++ /dev/null
@@ -1,85 +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.authority.provider.natived.model.privilege;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.admin.AdministrativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.DatabasePrivileges;
-import org.apache.shardingsphere.authority.model.AccessSubject;
-import org.apache.shardingsphere.authority.provider.natived.model.subject.DatabaseAccessSubject;
-import org.apache.shardingsphere.authority.provider.natived.model.subject.TableAccessSubject;
-
-import java.util.Collection;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-/**
- * Native privileges.
- */
-@Getter
-@EqualsAndHashCode
-public final class NativePrivileges implements ShardingSpherePrivileges {
-
- private final AdministrativePrivileges administrativePrivileges = new AdministrativePrivileges();
-
- private final DatabasePrivileges databasePrivileges = new DatabasePrivileges();
-
- @Override
- public void setSuperPrivilege() {
- administrativePrivileges.getPrivileges().add(PrivilegeType.SUPER);
- }
-
- @Override
- public boolean hasPrivileges(final String database) {
- return administrativePrivileges.getPrivileges().contains(PrivilegeType.SUPER)
- || !databasePrivileges.getGlobalPrivileges().isEmpty() || databasePrivileges.getSpecificPrivileges().containsKey(database);
- }
-
- @Override
- public boolean hasPrivileges(final Collection<PrivilegeType> privileges) {
- return administrativePrivileges.hasPrivileges(filterPrivileges(privileges));
- }
-
- @Override
- public boolean hasPrivileges(final AccessSubject accessSubject, final Collection<PrivilegeType> privileges) {
- if (accessSubject instanceof DatabaseAccessSubject) {
- return hasPrivileges(((DatabaseAccessSubject) accessSubject).getDatabase(), filterPrivileges(privileges));
- }
- if (accessSubject instanceof TableAccessSubject) {
- return hasPrivileges(((TableAccessSubject) accessSubject).getSchema(), ((TableAccessSubject) accessSubject).getTable(), filterPrivileges(privileges));
- }
- throw new UnsupportedOperationException(accessSubject.getClass().getCanonicalName());
- }
-
- private boolean hasPrivileges(final String schema, final Collection<PrivilegeType> privileges) {
- return administrativePrivileges.hasPrivileges(privileges) || databasePrivileges.hasPrivileges(schema, privileges);
- }
-
- private boolean hasPrivileges(final String schema, final String table, final Collection<PrivilegeType> privileges) {
- return administrativePrivileges.hasPrivileges(privileges) || databasePrivileges.hasPrivileges(schema, table, privileges);
- }
-
- private Collection<PrivilegeType> filterPrivileges(final Collection<PrivilegeType> privileges) {
- return privileges.stream()
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/admin/AdministrativePrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/admin/AdministrativePrivileges.java
deleted file mode 100644
index daa990c8044..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/admin/AdministrativePrivileges.java
+++ /dev/null
@@ -1,45 +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.authority.provider.natived.model.privilege.admin;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-
-import java.util.Collection;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Administrative privileges.
- */
-@Getter
-@EqualsAndHashCode
-public final class AdministrativePrivileges {
-
- private final Collection<PrivilegeType> privileges = new CopyOnWriteArraySet<>();
-
- /**
- * Has privileges.
- *
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final Collection<PrivilegeType> privileges) {
- return this.privileges.contains(PrivilegeType.SUPER) || this.privileges.containsAll(privileges);
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivileges.java
deleted file mode 100644
index be898e974cb..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivileges.java
+++ /dev/null
@@ -1,79 +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.authority.provider.natived.model.privilege.database;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-/**
- * Database privileges.
- */
-@Getter
-@EqualsAndHashCode
-public final class DatabasePrivileges {
-
- private final Collection<PrivilegeType> globalPrivileges = new CopyOnWriteArraySet<>();
-
- private final Map<String, SchemaPrivileges> specificPrivileges = new ConcurrentHashMap<>();
-
- /**
- * Has privileges.
- *
- * @param schema schema
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final String schema, final Collection<PrivilegeType> privileges) {
- return hasGlobalPrivileges(privileges) || hasSpecificPrivileges(schema, privileges);
- }
-
- /**
- * Has privileges.
- *
- * @param schema schema
- * @param table table
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final String schema, final String table, final Collection<PrivilegeType> privileges) {
- return hasGlobalPrivileges(privileges) || hasSpecificPrivileges(schema, table, privileges);
- }
-
- private boolean hasGlobalPrivileges(final Collection<PrivilegeType> privileges) {
- return globalPrivileges.containsAll(privileges);
- }
-
- private boolean hasSpecificPrivileges(final String schema, final Collection<PrivilegeType> privileges) {
- return specificPrivileges.containsKey(schema) && specificPrivileges.get(schema).hasPrivileges(getSpecificPrivileges(privileges));
- }
-
- private boolean hasSpecificPrivileges(final String schema, final String table, final Collection<PrivilegeType> privileges) {
- return specificPrivileges.containsKey(schema) && specificPrivileges.get(schema).hasPrivileges(table, getSpecificPrivileges(privileges));
- }
-
- private Collection<PrivilegeType> getSpecificPrivileges(final Collection<PrivilegeType> privileges) {
- return privileges.stream().filter(each -> !globalPrivileges.contains(each)).collect(Collectors.toList());
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/SchemaPrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/SchemaPrivileges.java
deleted file mode 100644
index 6150c3f3f82..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/SchemaPrivileges.java
+++ /dev/null
@@ -1,77 +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.authority.provider.natived.model.privilege.database;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-/**
- * Schema privileges.
- */
-@RequiredArgsConstructor
-@Getter
-@EqualsAndHashCode
-public final class SchemaPrivileges {
-
- private final String name;
-
- private final Collection<PrivilegeType> globalPrivileges = new CopyOnWriteArraySet<>();
-
- private final Map<String, TablePrivileges> specificPrivileges = new ConcurrentHashMap<>();
-
- /**
- * Has privileges.
- *
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final Collection<PrivilegeType> privileges) {
- return hasGlobalPrivileges(privileges);
- }
-
- /**
- * Has privileges.
- *
- * @param table table
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final String table, final Collection<PrivilegeType> privileges) {
- return hasGlobalPrivileges(privileges) || hasSpecificPrivileges(table, privileges);
- }
-
- private boolean hasGlobalPrivileges(final Collection<PrivilegeType> privileges) {
- return globalPrivileges.containsAll(privileges);
- }
-
- private boolean hasSpecificPrivileges(final String table, final Collection<PrivilegeType> privileges) {
- return specificPrivileges.containsKey(table) && specificPrivileges.get(table).hasPrivileges(getSpecificPrivileges(privileges));
- }
-
- private Collection<PrivilegeType> getSpecificPrivileges(final Collection<PrivilegeType> privileges) {
- return privileges.stream().filter(each -> !globalPrivileges.contains(each)).collect(Collectors.toList());
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/TablePrivileges.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/TablePrivileges.java
deleted file mode 100644
index 569a5a941b3..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/TablePrivileges.java
+++ /dev/null
@@ -1,48 +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.authority.provider.natived.model.privilege.database;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-
-import java.util.Collection;
-
-/**
- * Table privileges.
- */
-@RequiredArgsConstructor
-@EqualsAndHashCode
-@Getter
-public final class TablePrivileges {
-
- private final String tableName;
-
- private final Collection<PrivilegeType> privileges;
-
- /**
- * Has privileges.
- *
- * @param privileges privileges
- * @return has privileges or not
- */
- public boolean hasPrivileges(final Collection<PrivilegeType> privileges) {
- return this.privileges.containsAll(privileges);
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/TableAccessSubject.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/TableAccessSubject.java
deleted file mode 100644
index b82cdb652e6..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/provider/natived/model/subject/TableAccessSubject.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.authority.provider.natived.model.subject;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.authority.model.AccessSubject;
-
-/**
- * Table access subject.
- */
-@RequiredArgsConstructor
-@Getter
-public final class TableAccessSubject implements AccessSubject {
-
- private final String schema;
-
- private final String table;
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler
deleted file mode 100644
index 35e4b4aa851..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler
+++ /dev/null
@@ -1,21 +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.
-#
-
-org.apache.shardingsphere.authority.provider.natived.builder.dialect.MySQLPrivilegeHandler
-org.apache.shardingsphere.authority.provider.natived.builder.dialect.PostgreSQLPrivilegeHandler
-org.apache.shardingsphere.authority.provider.natived.builder.dialect.OraclePrivilegeHandler
-org.apache.shardingsphere.authority.provider.natived.builder.dialect.SQLServerPrivilegeHandler
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm
index 09ac0f321e2..4c763f63866 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityProviderAlgorithm
@@ -15,6 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.provider.natived.NativeAuthorityProviderAlgorithm
org.apache.shardingsphere.authority.provider.simple.AllPermittedPrivilegesProviderAlgorithm
org.apache.shardingsphere.authority.provider.database.DatabasePermittedPrivilegesProviderAlgorithm
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
index 5ffc8e4c01c..a45eb9a7f45 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
@@ -34,21 +34,14 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.Map;
import java.util.Properties;
-import java.util.stream.Collectors;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class AuthorityCheckerTest {
@@ -68,27 +61,13 @@ public final class AuthorityCheckerTest {
assertTrue(sqlChecker.check("db0", new Grantee("root", "localhost"), rule));
}
- @SuppressWarnings("unchecked")
- @Test
- public void assertCheckSchemaByNative() throws SQLException {
- Collection<ShardingSphereUser> users = new LinkedList<>();
- ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- users.add(root);
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
- AuthorityRule rule = new AuthorityRule(ruleConfig, createDatabases(users));
- SQLChecker<AuthorityRule> sqlChecker = SQLCheckerFactory.getInstance(Collections.singleton(rule)).get(rule);
- assertTrue(sqlChecker.check("db0", new Grantee("root", "localhost"), rule));
- assertFalse(sqlChecker.check("db1", new Grantee("root", "localhost"), rule));
- assertFalse(sqlChecker.check("db0", new Grantee("other", "localhost"), rule));
- }
-
@SuppressWarnings("unchecked")
@Test
public void assertCheckUser() {
Collection<ShardingSphereUser> users = new LinkedList<>();
ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
users.add(root);
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRule(ruleConfig, Collections.emptyMap());
SQLChecker<AuthorityRule> sqlChecker = SQLCheckerFactory.getInstance(Collections.singleton(rule)).get(rule);
assertTrue(sqlChecker.check(new Grantee("root", "localhost"), rule));
@@ -102,7 +81,7 @@ public final class AuthorityCheckerTest {
Collection<ShardingSphereUser> users = new LinkedList<>();
ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
users.add(root);
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRule(ruleConfig, Collections.emptyMap());
SQLChecker<AuthorityRule> sqlChecker = SQLCheckerFactory.getInstance(Collections.singleton(rule)).get(rule);
SelectStatement selectStatement = mock(SelectStatement.class);
@@ -112,60 +91,4 @@ public final class AuthorityCheckerTest {
assertTrue(sqlChecker.check(insertStatement, Collections.emptyList(), new Grantee("root", "localhost"), "db0", Collections.emptyMap(), rule).isPassed());
assertTrue(sqlChecker.check(createTableStatement, Collections.emptyList(), new Grantee("root", "localhost"), "db0", Collections.emptyMap(), rule).isPassed());
}
-
- private Map<String, ShardingSphereDatabase> createDatabases(final Collection<ShardingSphereUser> users) throws SQLException {
- when(database.getName()).thenReturn("db0");
- DataSource dataSource = mockDataSourceForPrivileges(users);
- when(database.getResource().getAllInstanceDataSources()).thenReturn(Collections.singletonList(dataSource));
- when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return Collections.singletonMap("db0", database);
- }
-
- private DataSource mockDataSourceForPrivileges(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
- ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String globalPrivilegeSQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
- String schemaPrivilegeSQL = "SELECT * FROM mysql.db WHERE (user, host) in (%s)";
- String tablePrivilegeSQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
- String useHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSQL, useHostTuples))).thenReturn(globalPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSQL, useHostTuples))).thenReturn(schemaPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSQL, useHostTuples))).thenReturn(tablePrivilegeResultSet);
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
- return result;
- }
-
- private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("user")).thenReturn("root");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("db0");
- when(result.getObject("Select_priv")).thenReturn(true);
- when(result.getObject("Insert_priv")).thenReturn(true);
- when(result.getObject("Update_priv")).thenReturn(true);
- when(result.getObject("Delete_priv")).thenReturn(true);
- when(result.getString("user")).thenReturn("root");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("db0");
- when(result.getString("Table_name")).thenReturn("sys_config");
- when(result.getArray("Table_priv").getArray()).thenReturn(new String[]{"Select"});
- when(result.getString("user")).thenReturn("root");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/fixture/FixtureStoragePrivilegeHandler.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/fixture/FixtureStoragePrivilegeHandler.java
deleted file mode 100644
index 71f5926088d..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/fixture/FixtureStoragePrivilegeHandler.java
+++ /dev/null
@@ -1,53 +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.authority.provider.fixture;
-
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Map;
-
-public final class FixtureStoragePrivilegeHandler implements StoragePrivilegeHandler {
-
- @Override
- public Collection<ShardingSphereUser> diff(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- return null;
- }
-
- @Override
- public void create(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- }
-
- @Override
- public void grantAll(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- }
-
- @Override
- public Map<ShardingSphereUser, NativePrivileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- return null;
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java
deleted file mode 100644
index 3ab273a2452..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithmTest.java
+++ /dev/null
@@ -1,167 +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.authority.provider.natived;
-
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class NativeAuthorityProviderAlgorithmTest {
-
- @Test
- public void assertFindPrivileges() throws SQLException {
- NativeAuthorityProviderAlgorithm algorithm = new NativeAuthorityProviderAlgorithm();
- Collection<ShardingSphereUser> users = new LinkedList<>();
- ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- users.add(root);
- ShardingSphereDatabase database = mockDatabase(users);
- AuthorityRegistry authorityRegistry = algorithm.buildAuthorityRegistry(Collections.singletonMap("db0", database), users);
- Optional<ShardingSpherePrivileges> privileges = authorityRegistry.findPrivileges(new Grantee("root", "localhost"));
- assertTrue(privileges.isPresent());
- assertPrivilege(privileges.get());
- }
-
- private void assertPrivilege(final ShardingSpherePrivileges privileges) {
- Collection<PrivilegeType> expected = new LinkedList<>();
- expected.add(PrivilegeType.SUPER);
- expected.add(PrivilegeType.SELECT);
- expected.add(PrivilegeType.INSERT);
- expected.add(PrivilegeType.UPDATE);
- expected.add(PrivilegeType.RELOAD);
- expected.add(PrivilegeType.SHUTDOWN);
- assertTrue(privileges.hasPrivileges(expected));
- }
-
- private ShardingSphereDatabase mockDatabase(final Collection<ShardingSphereUser> users) throws SQLException {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DataSource dataSource = mockDataSourceForPrivileges(users);
- when(result.getResource().getAllInstanceDataSources()).thenReturn(Collections.singletonList(dataSource));
- when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return result;
- }
-
- private DataSource mockDataSourceForPrivileges(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
- ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String globalPrivilegeSQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
- String schemaPrivilegeSQL = "SELECT * FROM mysql.db WHERE (user, host) in (%s)";
- String tablePrivilegeSQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
- String useHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSQL, useHostTuples))).thenReturn(globalPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSQL, useHostTuples))).thenReturn(schemaPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSQL, useHostTuples))).thenReturn(tablePrivilegeResultSet);
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
- return result;
- }
-
- private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false, true, true, false);
- when(result.getObject("Super_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Reload_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Shutdown_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Process_priv")).thenReturn(false, false, false, false);
- when(result.getObject("File_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Show_db_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Repl_slave_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Repl_client_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_user_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_tablespace_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Select_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Insert_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Update_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Delete_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Create_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Alter_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Drop_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Grant_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Index_priv")).thenReturn(false, false, false, false);
- when(result.getObject("References_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Execute_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_view_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Show_view_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_routine_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Event_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Trigger_priv")).thenReturn(false, false, false, false);
- when(result.getString("user")).thenReturn("root", "mysql.sys", "root", "mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getObject("Select_priv")).thenReturn(false);
- when(result.getObject("Insert_priv")).thenReturn(false);
- when(result.getObject("Update_priv")).thenReturn(false);
- when(result.getObject("Delete_priv")).thenReturn(false);
- when(result.getObject("Create_priv")).thenReturn(false);
- when(result.getObject("Alter_priv")).thenReturn(false);
- when(result.getObject("Drop_priv")).thenReturn(false);
- when(result.getObject("Grant_priv")).thenReturn(false);
- when(result.getObject("Index_priv")).thenReturn(false);
- when(result.getObject("References_priv")).thenReturn(false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false);
- when(result.getObject("Execute_priv")).thenReturn(false);
- when(result.getObject("Create_view_priv")).thenReturn(false);
- when(result.getObject("Show_view_priv")).thenReturn(false);
- when(result.getObject("Create_routine_priv")).thenReturn(false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false);
- when(result.getObject("Event_priv")).thenReturn(false);
- when(result.getObject("Trigger_priv")).thenReturn(true);
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getString("Table_name")).thenReturn("sys_config");
- when(result.getArray("Table_priv").getArray()).thenReturn(new String[]{"Select"});
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java
deleted file mode 100644
index efb55c5394a..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeBuilderTest.java
+++ /dev/null
@@ -1,172 +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.authority.provider.natived.builder;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class StoragePrivilegeBuilderTest {
-
- @Test
- public void assertBuildInCache() {
- Collection<ShardingSphereDatabase> databases = new LinkedList<>();
- Collection<ShardingSphereUser> users = new LinkedList<>();
- ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- users.add(root);
- Map<ShardingSphereUser, NativePrivileges> result = StoragePrivilegeBuilder.build(databases, users);
- assertThat(result.size(), is(1));
- assertTrue(result.get(root).hasPrivileges(Collections.singletonList(PrivilegeType.SUPER)));
- }
-
- @Test
- public void assertBuildPrivilegesInStorage() throws SQLException {
- Collection<ShardingSphereUser> users = new LinkedList<>();
- ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- users.add(root);
- ShardingSphereDatabase database = mockDatabase(users);
- Map<ShardingSphereUser, NativePrivileges> result = StoragePrivilegeBuilder.build(Collections.singletonList(database), users);
- assertThat(result.size(), is(1));
- Collection<PrivilegeType> expected = new LinkedList<>();
- expected.add(PrivilegeType.SUPER);
- expected.add(PrivilegeType.SELECT);
- expected.add(PrivilegeType.INSERT);
- expected.add(PrivilegeType.UPDATE);
- expected.add(PrivilegeType.RELOAD);
- expected.add(PrivilegeType.SHUTDOWN);
- assertTrue(result.get(root).hasPrivileges(expected));
- }
-
- private ShardingSphereDatabase mockDatabase(final Collection<ShardingSphereUser> users) throws SQLException {
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- DataSource dataSource = mockDataSourceForPrivileges(users);
- when(result.getResource().getAllInstanceDataSources()).thenReturn(Collections.singleton(dataSource));
- when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return result;
- }
-
- private DataSource mockDataSourceForPrivileges(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
- ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String globalPrivilegeSQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
- String schemaPrivilegeSQL = "SELECT * FROM mysql.db WHERE (user, host) in (%s)";
- String tablePrivilegeSQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
- String useHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSQL, useHostTuples))).thenReturn(globalPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSQL, useHostTuples))).thenReturn(schemaPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSQL, useHostTuples))).thenReturn(tablePrivilegeResultSet);
- when(result.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
- return result;
- }
-
- private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false, true, true, false);
- when(result.getObject("Super_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Reload_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Shutdown_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Process_priv")).thenReturn(false, false, false, false);
- when(result.getObject("File_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Show_db_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Repl_slave_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Repl_client_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_user_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_tablespace_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Select_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Insert_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Update_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Delete_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Create_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Alter_priv")).thenReturn(true, false, true, false);
- when(result.getObject("Drop_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Grant_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Index_priv")).thenReturn(false, false, false, false);
- when(result.getObject("References_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Execute_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_view_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Show_view_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Create_routine_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Event_priv")).thenReturn(false, false, false, false);
- when(result.getObject("Trigger_priv")).thenReturn(false, false, false, false);
- when(result.getString("user")).thenReturn("root", "mysql.sys", "root", "mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getObject("Select_priv")).thenReturn(false);
- when(result.getObject("Insert_priv")).thenReturn(false);
- when(result.getObject("Update_priv")).thenReturn(false);
- when(result.getObject("Delete_priv")).thenReturn(false);
- when(result.getObject("Create_priv")).thenReturn(false);
- when(result.getObject("Alter_priv")).thenReturn(false);
- when(result.getObject("Drop_priv")).thenReturn(false);
- when(result.getObject("Grant_priv")).thenReturn(false);
- when(result.getObject("Index_priv")).thenReturn(false);
- when(result.getObject("References_priv")).thenReturn(false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false);
- when(result.getObject("Execute_priv")).thenReturn(false);
- when(result.getObject("Create_view_priv")).thenReturn(false);
- when(result.getObject("Show_view_priv")).thenReturn(false);
- when(result.getObject("Create_routine_priv")).thenReturn(false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false);
- when(result.getObject("Event_priv")).thenReturn(false);
- when(result.getObject("Trigger_priv")).thenReturn(true);
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getString("Table_name")).thenReturn("sys_config");
- when(result.getArray("Table_priv").getArray()).thenReturn(new String[]{"Select"});
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactoryTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactoryTest.java
deleted file mode 100644
index 51b0dcaafea..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeHandlerFactoryTest.java
+++ /dev/null
@@ -1,37 +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.authority.provider.natived.builder;
-
-import org.apache.shardingsphere.authority.provider.fixture.FixtureStoragePrivilegeHandler;
-import org.junit.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class StoragePrivilegeHandlerFactoryTest {
-
- @Test
- public void assertFindInstance() {
- Optional<StoragePrivilegeHandler> actual = StoragePrivilegeHandlerFactory.findInstance("FIXTURE");
- assertTrue(actual.isPresent());
- assertThat(actual.get(), instanceOf(FixtureStoragePrivilegeHandler.class));
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMergerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMergerTest.java
deleted file mode 100644
index 85ba39114fa..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/StoragePrivilegeMergerTest.java
+++ /dev/null
@@ -1,79 +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.authority.provider.natived.builder;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.TablePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Collections;
-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;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class StoragePrivilegeMergerTest {
-
- @Test
- public void assertPrivilegeMergeResult() {
- ShardingSphereUser user = new ShardingSphereUser("test", "test", "%");
- Map<ShardingSphereUser, Collection<NativePrivileges>> userPrivilegeMap = Collections.singletonMap(user, Collections.singleton(buildPrivileges()));
- Map<ShardingSphereUser, NativePrivileges> actual = StoragePrivilegeMerger.merge(userPrivilegeMap, "schema", Collections.singleton(buildRule()));
- assertThat(actual.size(), is(1));
- assertTrue(actual.get(user).getAdministrativePrivileges().getPrivileges().isEmpty());
- assertTrue(actual.get(user).getDatabasePrivileges().getGlobalPrivileges().isEmpty());
- assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
- assertTrue(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("schema").getGlobalPrivileges().isEmpty());
- assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("schema").getSpecificPrivileges().size(), is(1));
- assertThat("TableName assert error.", actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("schema").getSpecificPrivileges().get("tbl").getTableName(), is("tbl"));
- assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("schema").getSpecificPrivileges().get("tbl").getPrivileges().size(), is(1));
- assertTrue(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("schema").getSpecificPrivileges().get("tbl").getPrivileges().contains(PrivilegeType.SELECT));
- }
-
- private NativePrivileges buildPrivileges() {
- Collection<PrivilegeType> tablePrivileges = Collections.singleton(PrivilegeType.SELECT);
- SchemaPrivileges schema0Privilege = new SchemaPrivileges("schema_0");
- schema0Privilege.getSpecificPrivileges().put("tbl_0", new TablePrivileges("tbl_0", tablePrivileges));
- schema0Privilege.getSpecificPrivileges().put("tbl_1", new TablePrivileges("tbl_1", tablePrivileges));
- SchemaPrivileges schema1Privilege = new SchemaPrivileges("schema_1");
- schema1Privilege.getSpecificPrivileges().put("tbl_2", new TablePrivileges("tbl_2", tablePrivileges));
- schema1Privilege.getSpecificPrivileges().put("tbl_3", new TablePrivileges("tbl_3", tablePrivileges));
- NativePrivileges result = new NativePrivileges();
- result.getDatabasePrivileges().getSpecificPrivileges().put("schema_0", schema0Privilege);
- result.getDatabasePrivileges().getSpecificPrivileges().put("schema_1", schema1Privilege);
- return result;
- }
-
- private DataNodeContainedRule buildRule() {
- DataNodeContainedRule result = mock(DataNodeContainedRule.class);
- when(result.findLogicTableByActualTable("tbl_0")).thenReturn(Optional.of("tbl"));
- when(result.findLogicTableByActualTable("tbl_1")).thenReturn(Optional.of("tbl"));
- when(result.findLogicTableByActualTable("tbl_2")).thenReturn(Optional.of("tbl"));
- when(result.findLogicTableByActualTable("tbl_3")).thenReturn(Optional.of("tbl"));
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandlerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandlerTest.java
deleted file mode 100644
index 9fa04fbe941..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/MySQLPrivilegeHandlerTest.java
+++ /dev/null
@@ -1,241 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandlerFactory;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public final class MySQLPrivilegeHandlerTest {
-
- @Test
- public void assertDiff() throws SQLException {
- Collection<ShardingSphereUser> newUsers = createUsers();
- newUsers.add(new ShardingSphereUser("root", "", "127.0.0.2"));
- DataSource dataSource = mockDataSourceForUsers(newUsers);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("MySQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertDiffUsers(storagePrivilegeHandler.get().diff(newUsers, dataSource));
- }
-
- @Test
- public void assertCreate() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("MySQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().create(users, dataSource);
- assertCreateUsers(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertGrantAll() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("MySQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().grantAll(users, dataSource);
- assertGrantUsersAll(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertLoad() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForPrivileges(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("MySQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertPrivileges(storagePrivilegeHandler.get().load(users, dataSource));
- }
-
- private Collection<ShardingSphereUser> createUsers() {
- Collection<ShardingSphereUser> result = new LinkedList<>();
- result.add(new ShardingSphereUser("root", "", "localhost"));
- result.add(new ShardingSphereUser("mysql.sys", "", "localhost"));
- return result;
- }
-
- private DataSource mockDataSourceForUsers(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet usersResultSet = mockUsersResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- Statement statement = mock(Statement.class);
- Connection connection = mock(Connection.class);
- String diffUsersSQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
- String useHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- when(statement.executeQuery(String.format(diffUsersSQL, useHostTuples))).thenReturn(usersResultSet);
- when(connection.createStatement()).thenReturn(statement);
- when(result.getConnection()).thenReturn(connection);
- return result;
- }
-
- private DataSource mockDataSourceForPrivileges(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
- ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String globalPrivilegeSQL = "SELECT * FROM mysql.user WHERE (user, host) in (%s)";
- String schemaPrivilegeSQL = "SELECT * FROM mysql.db WHERE (user, host) in (%s)";
- String tablePrivilegeSQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
- String useHostTuples = users.stream().map(each -> String.format("('%s', '%s')", each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSQL, useHostTuples))).thenReturn(globalPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSQL, useHostTuples))).thenReturn(schemaPrivilegeResultSet);
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSQL, useHostTuples))).thenReturn(tablePrivilegeResultSet);
- return result;
- }
-
- private ResultSet mockUsersResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false);
- when(result.getString("user")).thenReturn("root", "mysql.sys");
- when(result.getString("host")).thenReturn("localhost", "localhost");
- return result;
- }
-
- private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false);
- when(result.getObject("Super_priv")).thenReturn(true, false);
- when(result.getObject("Reload_priv")).thenReturn(true, false);
- when(result.getObject("Shutdown_priv")).thenReturn(true, false);
- when(result.getObject("Process_priv")).thenReturn(false, false);
- when(result.getObject("File_priv")).thenReturn(false, false);
- when(result.getObject("Show_db_priv")).thenReturn(false, false);
- when(result.getObject("Repl_slave_priv")).thenReturn(false, false);
- when(result.getObject("Repl_client_priv")).thenReturn(false, false);
- when(result.getObject("Create_user_priv")).thenReturn(false, false);
- when(result.getObject("Create_tablespace_priv")).thenReturn(false, false);
- when(result.getObject("Select_priv")).thenReturn(true, false);
- when(result.getObject("Insert_priv")).thenReturn(true, false);
- when(result.getObject("Update_priv")).thenReturn(true, false);
- when(result.getObject("Delete_priv")).thenReturn(true, false);
- when(result.getObject("Create_priv")).thenReturn(true, false);
- when(result.getObject("Alter_priv")).thenReturn(true, false);
- when(result.getObject("Drop_priv")).thenReturn(false, false);
- when(result.getObject("Grant_priv")).thenReturn(false, false);
- when(result.getObject("Index_priv")).thenReturn(false, false);
- when(result.getObject("References_priv")).thenReturn(false, false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false, false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false, false);
- when(result.getObject("Execute_priv")).thenReturn(false, false);
- when(result.getObject("Create_view_priv")).thenReturn(false, false);
- when(result.getObject("Show_view_priv")).thenReturn(false, false);
- when(result.getObject("Create_routine_priv")).thenReturn(false, false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false, false);
- when(result.getObject("Event_priv")).thenReturn(false, false);
- when(result.getObject("Trigger_priv")).thenReturn(false, false);
- when(result.getString("user")).thenReturn("root", "mysql.sys");
- when(result.getString("host")).thenReturn("localhost", "localhost");
- return result;
- }
-
- private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getObject("Select_priv")).thenReturn(false);
- when(result.getObject("Insert_priv")).thenReturn(false);
- when(result.getObject("Update_priv")).thenReturn(false);
- when(result.getObject("Delete_priv")).thenReturn(false);
- when(result.getObject("Create_priv")).thenReturn(false);
- when(result.getObject("Alter_priv")).thenReturn(false);
- when(result.getObject("Drop_priv")).thenReturn(false);
- when(result.getObject("Grant_priv")).thenReturn(false);
- when(result.getObject("Index_priv")).thenReturn(false);
- when(result.getObject("References_priv")).thenReturn(false);
- when(result.getObject("Create_tmp_table_priv")).thenReturn(false);
- when(result.getObject("Lock_tables_priv")).thenReturn(false);
- when(result.getObject("Execute_priv")).thenReturn(false);
- when(result.getObject("Create_view_priv")).thenReturn(false);
- when(result.getObject("Show_view_priv")).thenReturn(false);
- when(result.getObject("Create_routine_priv")).thenReturn(false);
- when(result.getObject("Alter_routine_priv")).thenReturn(false);
- when(result.getObject("Event_priv")).thenReturn(false);
- when(result.getObject("Trigger_priv")).thenReturn(true);
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("Db")).thenReturn("sys");
- when(result.getString("Table_name")).thenReturn("sys_config");
- when(result.getArray("Table_priv").getArray()).thenReturn(new String[]{"Select"});
- when(result.getString("user")).thenReturn("mysql.sys");
- when(result.getString("host")).thenReturn("localhost");
- return result;
- }
-
- private void assertDiffUsers(final Collection<ShardingSphereUser> users) {
- assertThat(users.size(), is(1));
- assertThat(users.iterator().next().getGrantee().getUsername(), is("root"));
- assertThat(users.iterator().next().getGrantee().getHostname(), is("127.0.0.2"));
- }
-
- private void assertCreateUsers(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- String createUsers = users.stream().map(each -> String.format("'%s'@'%s' IDENTIFIED BY '%s'",
- each.getGrantee().getUsername(), each.getGrantee().getHostname(), each.getPassword())).collect(Collectors.joining(", "));
- verify(statement).execute(String.format("CREATE USER %s", createUsers));
- }
-
- private void assertGrantUsersAll(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- String grantUsers = users.stream().map(each -> String.format("'%s'@'%s'",
- each.getGrantee().getUsername(), each.getGrantee().getHostname())).collect(Collectors.joining(", "));
- verify(statement).execute(String.format("GRANT ALL ON *.* TO %s", grantUsers));
- }
-
- private void assertPrivileges(final Map<ShardingSphereUser, NativePrivileges> actual) {
- assertThat(actual.size(), is(2));
- ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- assertThat(actual.get(root).getAdministrativePrivileges().getPrivileges().size(), is(3));
- Collection<PrivilegeType> expectedAdminPrivileges = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.SUPER, PrivilegeType.RELOAD, PrivilegeType.SHUTDOWN));
- assertThat(actual.get(root).getAdministrativePrivileges().getPrivileges(), is(expectedAdminPrivileges));
- Collection<PrivilegeType> expectedDatabasePrivileges = new CopyOnWriteArraySet<>(
- Arrays.asList(PrivilegeType.SELECT, PrivilegeType.INSERT, PrivilegeType.UPDATE, PrivilegeType.DELETE, PrivilegeType.CREATE, PrivilegeType.ALTER));
- assertThat(actual.get(root).getDatabasePrivileges().getGlobalPrivileges().size(), is(6));
- assertThat(actual.get(root).getDatabasePrivileges().getGlobalPrivileges(), is(expectedDatabasePrivileges));
- ShardingSphereUser sys = new ShardingSphereUser("mysql.sys", "", "localhost");
- assertTrue(actual.get(sys).getAdministrativePrivileges().getPrivileges().isEmpty());
- assertTrue(actual.get(sys).getDatabasePrivileges().getGlobalPrivileges().isEmpty());
- assertThat(actual.get(sys).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
deleted file mode 100644
index e814b57ba48..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
+++ /dev/null
@@ -1,176 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandlerFactory;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public final class OraclePrivilegeHandlerTest {
-
- @Test
- public void assertDiff() throws SQLException {
- Collection<ShardingSphereUser> newUsers = createUsers();
- newUsers.add(new ShardingSphereUser("user", "", ""));
- DataSource dataSource = mockDataSourceForUsers(newUsers);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("Oracle");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertDiffUsers(storagePrivilegeHandler.get().diff(newUsers, dataSource));
- }
-
- @Test
- public void assertCreate() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("Oracle");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().create(users, dataSource);
- assertCreateUsers(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertGrantAll() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("Oracle");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().grantAll(users, dataSource);
- assertGrantUsersAll(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertLoad() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSource(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("Oracle");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertPrivileges(storagePrivilegeHandler.get().load(users, dataSource));
- }
-
- private void assertCreateUsers(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- for (ShardingSphereUser each : users) {
- verify(statement).execute(String.format("CREATE USER %s IDENTIFIED BY %s", each.getGrantee().getUsername(), each.getPassword()));
- }
- }
-
- private void assertDiffUsers(final Collection<ShardingSphereUser> users) {
- assertThat(users.size(), is(1));
- assertThat(users.iterator().next().getGrantee().getUsername(), is("user"));
- }
-
- private void assertGrantUsersAll(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- for (ShardingSphereUser each : users) {
- verify(statement).execute(String.format("GRANT ALL PRIVILEGES TO %s", each.getGrantee().getUsername()));
- }
- }
-
- private void assertPrivileges(final Map<ShardingSphereUser, NativePrivileges> actual) {
- assertThat(actual.size(), is(1));
- ShardingSphereUser user = new ShardingSphereUser("admin", "", "");
- assertTrue(actual.get(user).getDatabasePrivileges().getGlobalPrivileges().isEmpty());
- assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
- Collection<PrivilegeType> expectedSpecificPrivilege = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.INSERT, PrivilegeType.SELECT, PrivilegeType.UPDATE));
- SchemaPrivileges schemaPrivileges = actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("sys");
- assertTrue(schemaPrivileges.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege));
- assertThat(actual.get(user).getAdministrativePrivileges().getPrivileges().size(), is(3));
- Collection<PrivilegeType> expectedAdminPrivileges = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.SUPER, PrivilegeType.CREATE_ROLE, PrivilegeType.CREATE_TABLESPACE));
- assertThat(actual.get(user).getAdministrativePrivileges().getPrivileges(), is(expectedAdminPrivileges));
- }
-
- private Collection<ShardingSphereUser> createUsers() {
- Collection<ShardingSphereUser> result = new LinkedList<>();
- result.add(new ShardingSphereUser("admin", "", ""));
- return result;
- }
-
- private DataSource mockDataSource(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet sysPrivilegeResultSet = mockSysPrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String sysPrivilegeSQL = "SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE IN (%s)";
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(sysPrivilegeSQL, userList))).thenReturn(sysPrivilegeResultSet);
- ResultSet tabPrivilegeResultSet = mockTabPrivilegeResultSet();
- String tabPrivilegeSQL = "SELECT GRANTEE, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE, GRANTABLE, INHERITED FROM ALL_TAB_PRIVS WHERE GRANTEE IN (%s)";
- when(result.getConnection().createStatement().executeQuery(String.format(tabPrivilegeSQL, userList))).thenReturn(tabPrivilegeResultSet);
- return result;
- }
-
- private DataSource mockDataSourceForUsers(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet usersResultSet = mockUsersResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- Statement statement = mock(Statement.class);
- Connection connection = mock(Connection.class);
- String diffUsersSQL = "SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE IN (%s)";
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(statement.executeQuery(String.format(diffUsersSQL, userList))).thenReturn(usersResultSet);
- when(connection.createStatement()).thenReturn(statement);
- when(result.getConnection()).thenReturn(connection);
- return result;
- }
-
- private ResultSet mockSysPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, true, true, false);
- when(result.getString("GRANTEE")).thenReturn("admin");
- when(result.getString("PRIVILEGE")).thenReturn("SYSDBA", "CREATE ROLE", "CREATE TABLESPACE");
- return result;
- }
-
- private ResultSet mockTabPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, true, true, true, false);
- when(result.getString("TABLE_SCHEMA")).thenReturn("sys");
- when(result.getString("TABLE_NAME")).thenReturn("t_order");
- when(result.getString("PRIVILEGE")).thenReturn("SELECT", "INSERT", "DELETE", "UPDATE");
- when(result.getString("GRANTABLE")).thenReturn("YES", "YES", "FALSE", "YES");
- when(result.getString("GRANTEE")).thenReturn("admin");
- return result;
- }
-
- private ResultSet mockUsersResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, false);
- when(result.getString("GRANTEE")).thenReturn("admin");
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
deleted file mode 100644
index eb492fb2b21..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
+++ /dev/null
@@ -1,182 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandlerFactory;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public final class PostgreSQLPrivilegeHandlerTest {
-
- @Test
- public void assertDiff() throws SQLException {
- Collection<ShardingSphereUser> newUsers = createUsers();
- newUsers.add(new ShardingSphereUser("postgres2", "", ""));
- DataSource dataSource = mockDataSourceForUsers(newUsers);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("PostgreSQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertDiffUsers(storagePrivilegeHandler.get().diff(newUsers, dataSource));
- }
-
- @Test
- public void assertCreate() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("PostgreSQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().create(users, dataSource);
- assertCreateUsers(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertGrantAll() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("PostgreSQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().grantAll(users, dataSource);
- assertGrantUsersAll(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertLoad() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSource(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("PostgreSQL");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertPrivileges(storagePrivilegeHandler.get().load(users, dataSource));
- }
-
- private void assertPrivileges(final Map<ShardingSphereUser, NativePrivileges> actual) {
- assertThat(actual.size(), is(1));
- ShardingSphereUser user = new ShardingSphereUser("postgres", "", "");
- assertTrue(actual.get(user).getDatabasePrivileges().getGlobalPrivileges().isEmpty());
- assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
- Collection<PrivilegeType> expectedSpecificPrivilege = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.INSERT, PrivilegeType.SELECT, PrivilegeType.UPDATE, PrivilegeType.DELETE));
- SchemaPrivileges schemaPrivileges = actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("db0");
- assertTrue(schemaPrivileges.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege));
- assertThat(actual.get(user).getAdministrativePrivileges().getPrivileges().size(), is(4));
- Collection<PrivilegeType> expectedAdminPrivileges = new CopyOnWriteArraySet<>(
- Arrays.asList(PrivilegeType.SUPER, PrivilegeType.CREATE_ROLE, PrivilegeType.CREATE_DATABASE, PrivilegeType.CAN_LOGIN));
- assertThat(actual.get(user).getAdministrativePrivileges().getPrivileges(), is(expectedAdminPrivileges));
- }
-
- private void assertDiffUsers(final Collection<ShardingSphereUser> users) {
- assertThat(users.size(), is(1));
- assertThat(users.iterator().next().getGrantee().getUsername(), is("postgres2"));
- }
-
- private void assertCreateUsers(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- for (ShardingSphereUser each : users) {
- verify(statement).execute(String.format("CREATE USER %s WITH PASSWORD '%s'", each.getGrantee().getUsername(), each.getPassword()));
- }
- }
-
- private void assertGrantUsersAll(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- for (ShardingSphereUser each : users) {
- verify(statement).execute(String.format("ALTER USER %s WITH SUPERUSER", each.getGrantee().getUsername()));
- }
- }
-
- private Collection<ShardingSphereUser> createUsers() {
- Collection<ShardingSphereUser> result = new LinkedList<>();
- result.add(new ShardingSphereUser("postgres", "", ""));
- return result;
- }
-
- private DataSource mockDataSourceForUsers(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet usersResultSet = mockUsersResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- Statement statement = mock(Statement.class);
- Connection connection = mock(Connection.class);
- String diffUsersSQL = "SELECT * FROM pg_roles WHERE rolname IN (%s)";
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(statement.executeQuery(String.format(diffUsersSQL, userList))).thenReturn(usersResultSet);
- when(connection.createStatement()).thenReturn(statement);
- when(result.getConnection()).thenReturn(connection);
- return result;
- }
-
- private DataSource mockDataSource(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String tablePrivilegeSql = "SELECT grantor, grantee, table_catalog, table_name, privilege_type, is_grantable FROM information_schema.table_privileges WHERE grantee IN (%s)";
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSql, userList))).thenReturn(tablePrivilegeResultSet);
- ResultSet rolePrivilegeResultSet = mockRolePrivilegeResultSet();
- String rolePrivilegeSql = "SELECT * FROM pg_roles WHERE rolname IN (%s)";
- when(result.getConnection().createStatement().executeQuery(String.format(rolePrivilegeSql, userList))).thenReturn(rolePrivilegeResultSet);
- return result;
- }
-
- private ResultSet mockUsersResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false);
- when(result.getString("rolname")).thenReturn("postgres1", "postgres");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, true, true, true, true, true, true, false);
- when(result.getString("table_catalog")).thenReturn("db0");
- when(result.getString("table_name")).thenReturn("t_order");
- when(result.getString("privilege_type")).thenReturn("INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER");
- when(result.getString("is_grantable")).thenReturn("TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE");
- when(result.getString("grantee")).thenReturn("postgres");
- return result;
- }
-
- private ResultSet mockRolePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("rolname")).thenReturn("postgres");
- when(result.getBoolean("rolsuper")).thenReturn(true);
- when(result.getBoolean("rolcreaterole")).thenReturn(true);
- when(result.getBoolean("rolcreatedb")).thenReturn(true);
- when(result.getBoolean("rolreplication")).thenReturn(false);
- when(result.getBoolean("rolinherit")).thenReturn(false);
- when(result.getBoolean("rolcanlogin")).thenReturn(true);
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandlerTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandlerTest.java
deleted file mode 100644
index 9c1517b063a..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandlerTest.java
+++ /dev/null
@@ -1,215 +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.authority.provider.natived.builder.dialect;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
-import org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandlerFactory;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public final class SQLServerPrivilegeHandlerTest {
-
- @Test
- public void assertDiff() throws SQLException {
- Collection<ShardingSphereUser> newUsers = createUsers();
- newUsers.add(new ShardingSphereUser("testUser2", "", ""));
- DataSource dataSource = mockDataSourceForUsers(newUsers);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("SQLServer");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertDiffUsers(storagePrivilegeHandler.get().diff(newUsers, dataSource));
- }
-
- @Test
- public void assertCreate() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("SQLServer");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().create(users, dataSource);
- assertCreateUsers(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertGrantAll() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSourceForUsers(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("SQLServer");
- assertTrue(storagePrivilegeHandler.isPresent());
- storagePrivilegeHandler.get().grantAll(users, dataSource);
- assertGrantUsersAll(users, dataSource.getConnection().createStatement());
- }
-
- @Test
- public void assertLoad() throws SQLException {
- Collection<ShardingSphereUser> users = createUsers();
- DataSource dataSource = mockDataSource(users);
- Optional<StoragePrivilegeHandler> storagePrivilegeHandler = StoragePrivilegeHandlerFactory.findInstance("SQLServer");
- assertTrue(storagePrivilegeHandler.isPresent());
- assertPrivileges(storagePrivilegeHandler.get().load(users, dataSource));
- }
-
- private void assertPrivileges(final Map<ShardingSphereUser, NativePrivileges> actual) {
- assertThat(actual.size(), is(2));
- ShardingSphereUser dbo = new ShardingSphereUser("dbo", "", "");
- assertThat(actual.get(dbo).getAdministrativePrivileges().getPrivileges().size(), is(2));
- Collection<PrivilegeType> expectedAdminPrivileges = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.CONNECT, PrivilegeType.SHUTDOWN));
- assertThat(actual.get(dbo).getAdministrativePrivileges().getPrivileges(), is(expectedAdminPrivileges));
- Collection<PrivilegeType> expectedSpecificPrivilege = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.INSERT, PrivilegeType.SELECT, PrivilegeType.UPDATE, PrivilegeType.DELETE));
- SchemaPrivileges schemaPrivileges = actual.get(dbo).getDatabasePrivileges().getSpecificPrivileges().get("db0");
- assertTrue(schemaPrivileges.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege));
- ShardingSphereUser testUser = new ShardingSphereUser("testUser", "", "");
- assertTrue(actual.get(testUser).getAdministrativePrivileges().getPrivileges().isEmpty());
- assertTrue(actual.get(testUser).getDatabasePrivileges().getGlobalPrivileges().isEmpty());
- assertTrue(actual.get(testUser).getDatabasePrivileges().getSpecificPrivileges().isEmpty());
- }
-
- private Collection<ShardingSphereUser> createUsers() {
- Collection<ShardingSphereUser> result = new LinkedList<>();
- result.add(new ShardingSphereUser("dbo", "password", ""));
- result.add(new ShardingSphereUser("testUser", "password", ""));
- return result;
- }
-
- private DataSource mockDataSource(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- String globalPrivilegeSql = "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, pe.permission_name AS PRIVILEGE_TYPE"
- + "FROM sys.server_principals AS pr JOIN sys.server_permissions AS pe"
- + "ON pe.grantee_principal_id = pr.principal_id WHERE pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name";
- when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSql, userList))).thenReturn(globalPrivilegeResultSet);
- ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
- String schemaPrivilegeSql = "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, pe.permission_name AS PRIVILEGE_TYPE, o.name AS DB"
- + "FROM sys.database_principals AS pr JOIN sys.database_permissions AS pe"
- + "ON pe.grantee_principal_id = pr.principal_id JOIN sys.objects AS o"
- + "ON pe.major_id = o.object_id WHERE pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name, o.name";
- when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSql, userList))).thenReturn(schemaPrivilegeResultSet);
- ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
- String tablePrivilegeSql = "SELECT GRANTOR, GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE_TYPE, IS_GRANTABLE from INFORMATION_SCHEMA.TABLE_PRIVILEGES WHERE GRANTEE IN (%s)";
- when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSql, userList))).thenReturn(tablePrivilegeResultSet);
- return result;
- }
-
- private DataSource mockDataSourceForUsers(final Collection<ShardingSphereUser> users) throws SQLException {
- ResultSet usersResultSet = mockUsersResultSet();
- DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
- Statement statement = mock(Statement.class);
- Connection connection = mock(Connection.class);
- DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
- String diffUsersSQL = "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, pe.permission_name AS PRIVILEGE_TYPE"
- + "FROM sys.server_principals AS pr JOIN sys.server_permissions AS pe"
- + "ON pe.grantee_principal_id = pr.principal_id WHERE pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name";
- String userList = users.stream().map(each -> String.format("'%s'", each.getGrantee().getUsername())).collect(Collectors.joining(", "));
- when(statement.executeQuery(String.format(diffUsersSQL, userList))).thenReturn(usersResultSet);
- when(connection.createStatement()).thenReturn(statement);
- when(result.getConnection()).thenReturn(connection);
- when(statement.getConnection()).thenReturn(connection);
- when(connection.getMetaData()).thenReturn(databaseMetaData);
- when(databaseMetaData.getURL()).thenReturn("jdbc:sqlserver://127.0.0.1;DatabaseName=ds_0");
- return result;
- }
-
- private ResultSet mockUsersResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class);
- when(result.next()).thenReturn(true, true, false);
- when(result.getString("GRANTEE")).thenReturn("dbo", "testUser");
- return result;
- }
-
- private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, true, false);
- when(result.getString("STATE")).thenReturn("GRANT", "GRANT");
- when(result.getString("GRANTEE")).thenReturn("dbo", "dbo");
- when(result.getString("PRIVILEGE_TYPE")).thenReturn("CONNECT", "SHUTDOWN");
- return result;
- }
-
- private ResultSet mockTablePrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, true, true, true, true, true, true, false);
- when(result.getString("TABLE_CATALOG")).thenReturn("db0");
- when(result.getString("TABLE_NAME")).thenReturn("t_order");
- when(result.getString("PRIVILEGE_TYPE")).thenReturn("INSERT", "SELECT", "UPDATE", "DELETE", "REFERENCES");
- when(result.getString("IS_GRANTABLE")).thenReturn("YES", "YES", "YES", "YES", "YES", "YES", "YES");
- when(result.getString("GRANTEE")).thenReturn("dbo");
- return result;
- }
-
- private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
- ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
- when(result.next()).thenReturn(true, false);
- when(result.getString("STATE")).thenReturn("GRANT");
- when(result.getString("GRANTEE")).thenReturn("dbo");
- when(result.getString("PRIVILEGE_TYPE")).thenReturn("CONNECT");
- when(result.getString("DB")).thenReturn("t_order");
- return result;
- }
-
- private void assertDiffUsers(final Collection<ShardingSphereUser> users) {
- assertThat(users.size(), is(1));
- assertThat(users.iterator().next().getGrantee().getUsername(), is("testUser2"));
- }
-
- private void assertCreateUsers(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- for (ShardingSphereUser each : users) {
- StringBuilder sql = new StringBuilder();
- sql.append(String.format("CREATE LOGIN %s WITH PASSWORD = '%s';", each.getGrantee().getUsername(), each.getPassword())).append("\n");
- sql.append("GO").append("\n");
- sql.append(String.format("CREATE USER %s FOR LOGIN %s;\n", each.getGrantee().getUsername(), each.getGrantee().getUsername()));
- sql.append("GO");
- verify(statement).execute(sql.toString());
- }
- }
-
- private void assertGrantUsersAll(final Collection<ShardingSphereUser> users, final Statement statement) throws SQLException {
- String databaseName = getDatabaseName(statement.getConnection().getMetaData().getURL());
- for (ShardingSphereUser each : users) {
- verify(statement).execute(String.format("GRANT CONTROL ON DATABASE::%s TO %s", databaseName, each.getGrantee().getUsername()));
- }
- }
-
- private String getDatabaseName(final String url) {
- return url.contains("?") ? url.substring(url.indexOf("DatabaseName=") + 1, url.indexOf("?")) : url.substring(url.indexOf("DatabaseName=") + 1);
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivilegesTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivilegesTest.java
deleted file mode 100644
index 79bcd7b6638..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/natived/model/privilege/database/DatabasePrivilegesTest.java
+++ /dev/null
@@ -1,101 +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.authority.provider.natived.model.privilege.database;
-
-import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class DatabasePrivilegesTest {
-
- private static DatabasePrivileges privileges = new DatabasePrivileges();
-
- @Before
- public void setUp() {
- privileges = buildPrivilege();
- }
-
- @Test
- public void assertGetGlobalPrivileges() {
- assertThat(privileges.getGlobalPrivileges(), instanceOf(Collection.class));
- assertTrue(privileges.getGlobalPrivileges().isEmpty());
- privileges.getGlobalPrivileges().add(PrivilegeType.SELECT);
- assertTrue(privileges.getGlobalPrivileges().contains(PrivilegeType.SELECT));
- assertFalse(privileges.getGlobalPrivileges().contains(PrivilegeType.DELETE));
- privileges.getGlobalPrivileges().add(PrivilegeType.DELETE);
- assertTrue(privileges.getGlobalPrivileges().contains(PrivilegeType.DELETE));
- }
-
- @Test
- public void assertGetSpecificPrivileges() {
- assertThat(privileges.getSpecificPrivileges(), instanceOf(Map.class));
- assertThat(privileges.getSpecificPrivileges().get("schema1"), instanceOf(SchemaPrivileges.class));
- assertThat(privileges.getSpecificPrivileges().get("schema1").getSpecificPrivileges().get("table1"), instanceOf(TablePrivileges.class));
- assertTrue(privileges.getSpecificPrivileges().get("schema1").getSpecificPrivileges().get("table1").getPrivileges().contains(PrivilegeType.SELECT));
- assertFalse(privileges.getSpecificPrivileges().get("schema1").getSpecificPrivileges().get("table1").getPrivileges().contains(PrivilegeType.DELETE));
- assertTrue(privileges.getSpecificPrivileges().get("schema2").getSpecificPrivileges().get("table3").getPrivileges().contains(PrivilegeType.DELETE));
- assertFalse(privileges.getSpecificPrivileges().get("schema2").getSpecificPrivileges().get("table3").getPrivileges().contains(PrivilegeType.UPDATE));
- }
-
- @Test
- public void assertHasPrivileges() {
- assertTrue(privileges.hasPrivileges("schema1", "table1", Collections.singletonList(PrivilegeType.SELECT)));
- assertFalse(privileges.hasPrivileges("schema1", "table3", Collections.singletonList(PrivilegeType.SELECT)));
- assertTrue(privileges.hasPrivileges("schema2", "table3", Collections.singletonList(PrivilegeType.SELECT)));
- assertFalse(privileges.hasPrivileges("schema1", "table1", Collections.singletonList(PrivilegeType.DELETE)));
- assertFalse(privileges.hasPrivileges("schema1", "table2", Collections.singletonList(PrivilegeType.DELETE)));
- assertTrue(privileges.hasPrivileges("schema2", "table3", Collections.singletonList(PrivilegeType.DELETE)));
- privileges.getGlobalPrivileges().add(PrivilegeType.DELETE);
- assertTrue(privileges.hasPrivileges("schema1", "table1", Collections.singletonList(PrivilegeType.DELETE)));
- assertTrue(privileges.hasPrivileges("schema1", Collections.singletonList(PrivilegeType.DELETE)));
- assertTrue(privileges.hasPrivileges("schema2", Collections.singletonList(PrivilegeType.DELETE)));
- assertFalse(privileges.hasPrivileges("schema1", Collections.singletonList(PrivilegeType.UPDATE)));
- assertFalse(privileges.hasPrivileges("schema2", Collections.singletonList(PrivilegeType.UPDATE)));
- privileges.getGlobalPrivileges().add(PrivilegeType.UPDATE);
- assertTrue(privileges.hasPrivileges("schema1", Collections.singletonList(PrivilegeType.UPDATE)));
- assertTrue(privileges.hasPrivileges("schema2", Collections.singletonList(PrivilegeType.UPDATE)));
- }
-
- private DatabasePrivileges buildPrivilege() {
- Collection<PrivilegeType> tablePrivileges1 = new LinkedList<>();
- Collection<PrivilegeType> tablePrivileges2 = new LinkedList<>();
- tablePrivileges1.add(PrivilegeType.SELECT);
- tablePrivileges2.add(PrivilegeType.SELECT);
- tablePrivileges2.add(PrivilegeType.DELETE);
- SchemaPrivileges schema1Privilege = new SchemaPrivileges("schema1");
- schema1Privilege.getSpecificPrivileges().put("table1", new TablePrivileges("table1", tablePrivileges1));
- schema1Privilege.getSpecificPrivileges().put("table2", new TablePrivileges("table2", tablePrivileges1));
- SchemaPrivileges schema2Privilege = new SchemaPrivileges("schema2");
- schema2Privilege.getSpecificPrivileges().put("table3", new TablePrivileges("table3", tablePrivileges2));
- schema2Privilege.getSpecificPrivileges().put("table4", new TablePrivileges("table4", tablePrivileges2));
- DatabasePrivileges result = new DatabasePrivileges();
- result.getSpecificPrivileges().put("schema1", schema1Privilege);
- result.getSpecificPrivileges().put("schema2", schema2Privilege);
- return result;
- }
-}
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesProviderAlgorithmTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesProviderAlgorithmTest.java
index d7aab9749f1..152aad11b89 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesProviderAlgorithmTest.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesProviderAlgorithmTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.authority.provider.simple.model.privilege;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.provider.natived.model.subject.DatabaseAccessSubject;
+import org.apache.shardingsphere.authority.provider.database.model.subject.DatabaseAccessSubject;
import org.junit.Test;
import java.util.Collections;
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler
deleted file mode 100644
index 08a6d4cbeec..00000000000
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.authority.provider.fixture.FixtureStoragePrivilegeHandler
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 71455884608..fceeda1fc89 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -261,7 +261,7 @@ public final class ClusterContextManagerCoordinatorTest {
}
private Collection<RuleConfiguration> getChangedGlobalRuleConfigurations() {
- RuleConfiguration authorityRuleConfig = new AuthorityRuleConfiguration(getShardingSphereUsers(), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ RuleConfiguration authorityRuleConfig = new AuthorityRuleConfiguration(getShardingSphereUsers(), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
return Collections.singleton(authorityRuleConfig);
}
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 e412270bb69..b0b976a6281 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
@@ -188,7 +188,7 @@ public final class MySQLFrontendEngineTest extends ProxyContextRestorer {
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
return new ShardingSphereRuleMetaData(Collections.singletonList(rule));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
index a310029a7fa..306cd509965 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java
@@ -152,7 +152,7 @@ public final class MySQLAuthenticationHandlerTest extends ProxyContextRestorer {
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user, final boolean isNeedSuper) throws NoSuchFieldException, IllegalAccessException {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
if (!isNeedSuper) {
Field authorityRegistryField = AuthorityRule.class.getDeclaredField("authorityRegistry");
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
index 9d20a8375a1..9b3fc4f97a3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
@@ -173,7 +173,7 @@ public final class OpenGaussAuthenticationEngineTest extends ProxyContextRestore
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
return new ShardingSphereRuleMetaData(Collections.singletonList(rule));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
index bb39a47f0f6..6256ade5ed8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java
@@ -146,7 +146,7 @@ public final class OpenGaussAuthenticationHandlerTest extends ProxyContextRestor
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
return new ShardingSphereRuleMetaData(Collections.singleton(rule));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
index c67ebcbe097..e8e33ddab80 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
@@ -183,7 +183,7 @@ public final class PostgreSQLAuthenticationEngineTest extends ProxyContextRestor
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
return new ShardingSphereRuleMetaData(Collections.singletonList(rule));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
index d4c23267704..747cc851446 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java
@@ -159,7 +159,7 @@ public final class PostgreSQLAuthenticationHandlerTest extends ProxyContextResto
}
private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) {
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("NATIVE", new Properties()));
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(Collections.singletonList(user), new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap());
return new ShardingSphereRuleMetaData(Collections.singleton(rule));
}