You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/04/06 09:13:21 UTC
[shardingsphere] branch master updated: Rename
ShardingSpherePrivilege to Privileges (#9950)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1275f91 Rename ShardingSpherePrivilege to Privileges (#9950)
1275f91 is described below
commit 1275f91c30bb3c73e982d2bb3d61b28c0920d67f
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Apr 6 17:12:52 2021 +0800
Rename ShardingSpherePrivilege to Privileges (#9950)
---
...hardingSpherePrivilege.java => Privileges.java} | 26 ++++----
...rivilege.java => AdministrativePrivileges.java} | 4 +-
...abasePrivilege.java => DatabasePrivileges.java} | 6 +-
...{SchemaPrivilege.java => SchemaPrivileges.java} | 6 +-
.../{TablePrivilege.java => TablePrivileges.java} | 4 +-
.../authority/spi/PrivilegeLoadAlgorithm.java | 6 +-
.../authority/checker/AuthorityChecker.java | 8 +--
.../authority/engine/Authentication.java | 10 +--
.../engine/impl/DefaultAuthentication.java | 8 +--
.../loader/StoragePrivilegeLoadAlgorithm.java | 6 +-
.../authority/loader/builder/PrivilegeBuilder.java | 50 +++++++-------
.../authority/loader/builder/PrivilegeMerger.java | 20 +++---
.../loader/builder/loader/PrivilegeLoader.java | 4 +-
.../loader/dialect/MySQLPrivilegeLoader.java | 77 +++++++++++-----------
.../loader/dialect/PostgreSQLPrivilegeLoader.java | 61 ++++++++---------
.../loader/dialect/MySQLPrivilegeLoaderTest.java | 20 +++---
.../dialect/PostgreSQLPrivilegeLoaderTest.java | 20 +++---
.../authority/GovernanceAuthorityContext.java | 20 +++---
.../core/facade/GovernanceFacadeTest.java | 4 +-
.../core/registry/RegistryCenterTest.java | 4 +-
.../mysql/executor/ShowDatabasesExecutorTest.java | 4 +-
.../impl/GovernanceBootstrapInitializerTest.java | 8 +--
.../impl/StandardBootstrapInitializerTest.java | 8 +--
.../swapper/YamlProxyConfigurationSwapperTest.java | 8 +--
.../mysql/auth/MySQLAuthenticationHandlerTest.java | 8 +--
.../auth/PostgreSQLAuthenticationEngineTest.java | 6 +-
26 files changed, 203 insertions(+), 203 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/ShardingSpherePrivilege.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/Privileges.java
similarity index 69%
rename from shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/ShardingSpherePrivilege.java
rename to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/Privileges.java
index b7ef7d7..1e17b13 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/ShardingSpherePrivilege.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/Privileges.java
@@ -19,27 +19,27 @@ package org.apache.shardingsphere.authority.model;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import org.apache.shardingsphere.authority.model.admin.AdministrativePrivilege;
-import org.apache.shardingsphere.authority.model.database.DatabasePrivilege;
+import org.apache.shardingsphere.authority.model.admin.AdministrativePrivileges;
+import org.apache.shardingsphere.authority.model.database.DatabasePrivileges;
import java.util.Collection;
/**
- * ShardingSphere privilege.
+ * Privileges.
*/
@Getter
@EqualsAndHashCode
-public final class ShardingSpherePrivilege {
+public final class Privileges {
- private final AdministrativePrivilege administrativePrivilege = new AdministrativePrivilege();
+ private final AdministrativePrivileges administrativePrivileges = new AdministrativePrivileges();
- private final DatabasePrivilege databasePrivilege = new DatabasePrivilege();
+ private final DatabasePrivileges databasePrivileges = new DatabasePrivileges();
/**
* Set super privilege.
*/
public void setSuperPrivilege() {
- administrativePrivilege.getPrivileges().add(PrivilegeType.SUPER);
+ administrativePrivileges.getPrivileges().add(PrivilegeType.SUPER);
}
/**
@@ -48,7 +48,7 @@ public final class ShardingSpherePrivilege {
* @return is empty or not
*/
public boolean isEmpty() {
- return administrativePrivilege.getPrivileges().isEmpty() && databasePrivilege.getGlobalPrivileges().isEmpty() && databasePrivilege.getSpecificPrivileges().isEmpty();
+ return administrativePrivileges.getPrivileges().isEmpty() && databasePrivileges.getGlobalPrivileges().isEmpty() && databasePrivileges.getSpecificPrivileges().isEmpty();
}
/**
@@ -58,7 +58,7 @@ public final class ShardingSpherePrivilege {
* @return has privileges or not
*/
public boolean hasPrivileges(final Collection<PrivilegeType> privileges) {
- return administrativePrivilege.hasPrivileges(privileges);
+ return administrativePrivileges.hasPrivileges(privileges);
}
/**
@@ -69,7 +69,7 @@ public final class ShardingSpherePrivilege {
* @return has privileges or not
*/
public boolean hasPrivileges(final String schema, final Collection<PrivilegeType> privileges) {
- return hasPrivileges(privileges) || databasePrivilege.hasPrivileges(schema, privileges);
+ return hasPrivileges(privileges) || databasePrivileges.hasPrivileges(schema, privileges);
}
/**
@@ -79,8 +79,8 @@ public final class ShardingSpherePrivilege {
* @return has or not
*/
public boolean hasPrivileges(final String schema) {
- return administrativePrivilege.getPrivileges().contains(PrivilegeType.SUPER) || !databasePrivilege.getGlobalPrivileges().isEmpty()
- || databasePrivilege.getSpecificPrivileges().containsKey(schema);
+ return administrativePrivileges.getPrivileges().contains(PrivilegeType.SUPER) || !databasePrivileges.getGlobalPrivileges().isEmpty()
+ || databasePrivileges.getSpecificPrivileges().containsKey(schema);
}
/**
@@ -92,6 +92,6 @@ public final class ShardingSpherePrivilege {
* @return has privileges or not
*/
public boolean hasPrivileges(final String schema, final String table, final Collection<PrivilegeType> privileges) {
- return hasPrivileges(privileges) || databasePrivilege.hasPrivileges(schema, table, privileges);
+ return hasPrivileges(privileges) || databasePrivileges.hasPrivileges(schema, table, privileges);
}
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivilege.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivileges.java
similarity index 95%
rename from shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivilege.java
rename to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivileges.java
index 181a20f..20a0300 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivilege.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/admin/AdministrativePrivileges.java
@@ -25,11 +25,11 @@ import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;
/**
- * Administrative privilege.
+ * Administrative privileges.
*/
@Getter
@EqualsAndHashCode
-public final class AdministrativePrivilege {
+public final class AdministrativePrivileges {
private final Collection<PrivilegeType> privileges = new CopyOnWriteArraySet<>();
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivilege.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivileges.java
similarity index 94%
rename from shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivilege.java
rename to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivileges.java
index 4cd9bb1..127cb9c 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivilege.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/DatabasePrivileges.java
@@ -28,15 +28,15 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
/**
- * Database privilege.
+ * Database privileges.
*/
@Getter
@EqualsAndHashCode
-public final class DatabasePrivilege {
+public final class DatabasePrivileges {
private final Collection<PrivilegeType> globalPrivileges = new CopyOnWriteArraySet<>();
- private final Map<String, SchemaPrivilege> specificPrivileges = new ConcurrentHashMap<>();
+ private final Map<String, SchemaPrivileges> specificPrivileges = new ConcurrentHashMap<>();
/**
* Has privileges.
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivilege.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivileges.java
similarity index 94%
rename from shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivilege.java
rename to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivileges.java
index cd2385c..8e82a6e 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivilege.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/SchemaPrivileges.java
@@ -29,18 +29,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
/**
- * Schema privilege.
+ * Schema privileges.
*/
@RequiredArgsConstructor
@Getter
@EqualsAndHashCode
-public final class SchemaPrivilege {
+public final class SchemaPrivileges {
private final String name;
private final Collection<PrivilegeType> globalPrivileges = new CopyOnWriteArraySet<>();
- private final Map<String, TablePrivilege> specificPrivileges = new ConcurrentHashMap<>();
+ private final Map<String, TablePrivileges> specificPrivileges = new ConcurrentHashMap<>();
/**
* Has privileges.
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivilege.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivileges.java
similarity index 96%
rename from shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivilege.java
rename to shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivileges.java
index 2b331f1..8f896c4 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivilege.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/model/database/TablePrivileges.java
@@ -24,11 +24,11 @@ import org.apache.shardingsphere.authority.model.PrivilegeType;
import java.util.Collection;
/**
- * Table privilege.
+ * Table privileges.
*/
@RequiredArgsConstructor
@EqualsAndHashCode
-public final class TablePrivilege {
+public final class TablePrivileges {
private final String tableName;
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
index bcea440..906620a 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.authority.spi;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -42,6 +42,6 @@ public interface PrivilegeLoadAlgorithm extends ShardingSphereAlgorithm {
* @param users users
* @return user and privileges map
*/
- Map<ShardingSphereUser, ShardingSpherePrivilege> load(String schemaName, DatabaseType databaseType,
- Collection<DataSource> dataSources, Collection<ShardingSphereRule> rules, Collection<ShardingSphereUser> users);
+ Map<ShardingSphereUser, Privileges> load(String schemaName, DatabaseType databaseType,
+ Collection<DataSource> dataSources, Collection<ShardingSphereRule> rules, Collection<ShardingSphereUser> users);
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
index 340e281..88f63b9 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.check.SQLChecker;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.authority.engine.AuthenticationContext;
import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
@@ -43,7 +43,7 @@ public final class AuthorityChecker implements SQLChecker<AuthorityRule> {
if (null == grantee) {
return true;
}
- return AuthenticationContext.getInstance().getAuthentication().findPrivilege(grantee).map(optional -> optional.hasPrivileges(schemaName)).orElse(false);
+ return AuthenticationContext.getInstance().getAuthentication().findPrivileges(grantee).map(optional -> optional.hasPrivileges(schemaName)).orElse(false);
}
@Override
@@ -51,9 +51,9 @@ public final class AuthorityChecker implements SQLChecker<AuthorityRule> {
if (null == grantee) {
return new SQLCheckResult(true, "");
}
- Optional<ShardingSpherePrivilege> privilege = AuthenticationContext.getInstance().getAuthentication().findPrivilege(grantee);
+ Optional<Privileges> privileges = AuthenticationContext.getInstance().getAuthentication().findPrivileges(grantee);
// TODO add error msg
- return privilege.map(optional -> new SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))), "")).orElseGet(() -> new SQLCheckResult(false, ""));
+ return privileges.map(optional -> new SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))), "")).orElseGet(() -> new SQLCheckResult(false, ""));
}
private PrivilegeType getPrivilege(final SQLStatement sqlStatement) {
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/Authentication.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/Authentication.java
index 7ead0cb..1d95df0 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/Authentication.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/Authentication.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.authority.engine;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -35,14 +35,14 @@ public interface Authentication {
*
* @param loadedPrivileges loaded privileges
*/
- void init(Map<ShardingSphereUser, ShardingSpherePrivilege> loadedPrivileges);
+ void init(Map<ShardingSphereUser, Privileges> loadedPrivileges);
/**
* Get authentication.
*
* @return Authentication
*/
- Map<ShardingSphereUser, ShardingSpherePrivilege> getAuthentication();
+ Map<ShardingSphereUser, Privileges> getAuthentication();
/**
* Get all users.
@@ -60,10 +60,10 @@ public interface Authentication {
Optional<ShardingSphereUser> findUser(Grantee grantee);
/**
- * Find Privilege.
+ * Find Privileges.
*
* @param grantee grantee
* @return found user
*/
- Optional<ShardingSpherePrivilege> findPrivilege(Grantee grantee);
+ Optional<Privileges> findPrivileges(Grantee grantee);
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthentication.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthentication.java
index 452000d..1f5d78a 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthentication.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthentication.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.authority.engine.impl;
import lombok.Getter;
import org.apache.shardingsphere.authority.engine.Authentication;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -34,10 +34,10 @@ import java.util.concurrent.ConcurrentHashMap;
@Getter
public final class DefaultAuthentication implements Authentication {
- private final Map<ShardingSphereUser, ShardingSpherePrivilege> authentication = new ConcurrentHashMap<>();
+ private final Map<ShardingSphereUser, Privileges> authentication = new ConcurrentHashMap<>();
@Override
- public void init(final Map<ShardingSphereUser, ShardingSpherePrivilege> loadedPrivileges) {
+ public void init(final Map<ShardingSphereUser, Privileges> loadedPrivileges) {
authentication.putAll(loadedPrivileges);
}
@@ -52,7 +52,7 @@ public final class DefaultAuthentication implements Authentication {
}
@Override
- public Optional<ShardingSpherePrivilege> findPrivilege(final Grantee grantee) {
+ public Optional<Privileges> findPrivileges(final Grantee grantee) {
return findUser(grantee).map(authentication::get);
}
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
index 188f566..5c0b88b 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.authority.loader.builder.PrivilegeBuilder;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoaderEngine;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -37,8 +37,8 @@ import java.util.Optional;
public final class StoragePrivilegeLoadAlgorithm implements PrivilegeLoadAlgorithm {
@Override
- public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final String schemaName, final DatabaseType databaseType, final Collection<DataSource> dataSources,
- final Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser> users) {
+ public Map<ShardingSphereUser, Privileges> load(final String schemaName, final DatabaseType databaseType, final Collection<DataSource> dataSources,
+ final Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser> users) {
Optional<PrivilegeLoader> loader = PrivilegeLoaderEngine.findPrivilegeLoader(databaseType);
return loader.map(
optional -> PrivilegeBuilder.build(schemaName, groupDataSourcesByInstance(dataSources), rules, users, optional)).orElseGet(() -> PrivilegeBuilder.buildDefaultPrivileges(users));
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
index d9dbd0b..b270ae0 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -61,8 +61,8 @@ public final class PrivilegeBuilder {
* @param users users
* @return privileges
*/
- public static Map<ShardingSphereUser, ShardingSpherePrivilege> build(final DatabaseType databaseType,
- final Collection<ShardingSphereMetaData> metaDataList, final Collection<ShardingSphereUser> users) {
+ public static Map<ShardingSphereUser, Privileges> build(final DatabaseType databaseType,
+ final Collection<ShardingSphereMetaData> metaDataList, final Collection<ShardingSphereUser> users) {
if (metaDataList.isEmpty()) {
return buildDefaultPrivileges(users);
}
@@ -70,16 +70,16 @@ public final class PrivilegeBuilder {
return loader.map(optional -> build(metaDataList, users, optional)).orElseGet(() -> buildDefaultPrivileges(users));
}
- private static Map<ShardingSphereUser, ShardingSpherePrivilege> build(final Collection<ShardingSphereMetaData> metaDataList,
- final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
+ private static Map<ShardingSphereUser, Privileges> build(final Collection<ShardingSphereMetaData> metaDataList,
+ final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ Map<ShardingSphereUser, Privileges> result = new LinkedHashMap<>();
for (ShardingSphereMetaData each : metaDataList) {
result.putAll(build(each, users, loader));
}
return result;
}
- private static Map<ShardingSphereUser, ShardingSpherePrivilege> build(final ShardingSphereMetaData metaData, final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ private static Map<ShardingSphereUser, Privileges> build(final ShardingSphereMetaData metaData, final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
return build(metaData.getName(), metaData.getResource().getAllInstanceDataSources(), metaData.getRuleMetaData().getRules(), users, loader);
}
@@ -93,18 +93,18 @@ public final class PrivilegeBuilder {
* @param loader privilege loader
* @return privileges
*/
- public static Map<ShardingSphereUser, ShardingSpherePrivilege> build(final String schemaName, final Collection<DataSource> dataSources,
- final Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
- Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> result = load(dataSources, users, loader);
+ public static Map<ShardingSphereUser, Privileges> build(final String schemaName, final Collection<DataSource> dataSources,
+ final Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ Map<ShardingSphereUser, Collection<Privileges>> result = load(dataSources, users, loader);
checkPrivileges(result);
return PrivilegeMerger.merge(result, schemaName, rules);
}
- private static Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> load(final Collection<DataSource> dataSources,
- final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
- Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> result = new LinkedHashMap<>(users.size(), 1);
+ private static Map<ShardingSphereUser, Collection<Privileges>> load(final Collection<DataSource> dataSources,
+ final Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ Map<ShardingSphereUser, Collection<Privileges>> result = new LinkedHashMap<>(users.size(), 1);
ExecutorService executorService = Executors.newFixedThreadPool(Math.min(CPU_CORES * 2, dataSources.isEmpty() ? 1 : dataSources.size()));
- Collection<Future<Map<ShardingSphereUser, ShardingSpherePrivilege>>> futures = new HashSet<>(dataSources.size(), 1);
+ Collection<Future<Map<ShardingSphereUser, Privileges>>> futures = new HashSet<>(dataSources.size(), 1);
for (DataSource each : dataSources) {
futures.add(executorService.submit(() -> loader.load(users, each)));
}
@@ -125,17 +125,17 @@ public final class PrivilegeBuilder {
* @param users users
* @return privileges
*/
- public static Map<ShardingSphereUser, ShardingSpherePrivilege> buildDefaultPrivileges(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>(users.size(), 1);
- ShardingSpherePrivilege privilege = new ShardingSpherePrivilege();
- privilege.setSuperPrivilege();
- users.forEach(each -> result.put(each, privilege));
+ public static Map<ShardingSphereUser, Privileges> buildDefaultPrivileges(final Collection<ShardingSphereUser> users) {
+ Map<ShardingSphereUser, Privileges> result = new LinkedHashMap<>(users.size(), 1);
+ Privileges privileges = new Privileges();
+ privileges.setSuperPrivilege();
+ users.forEach(each -> result.put(each, privileges));
return result;
}
- private static void fillPrivileges(final Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> userPrivilegeMap,
- final Future<Map<ShardingSphereUser, ShardingSpherePrivilege>> future) throws InterruptedException, ExecutionException, TimeoutException {
- for (Entry<ShardingSphereUser, ShardingSpherePrivilege> entry : future.get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS).entrySet()) {
+ private static void fillPrivileges(final Map<ShardingSphereUser, Collection<Privileges>> userPrivilegeMap,
+ final Future<Map<ShardingSphereUser, Privileges>> future) throws InterruptedException, ExecutionException, TimeoutException {
+ for (Entry<ShardingSphereUser, Privileges> entry : future.get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS).entrySet()) {
if (!userPrivilegeMap.containsKey(entry.getKey())) {
userPrivilegeMap.put(entry.getKey(), new LinkedHashSet<>());
}
@@ -143,9 +143,9 @@ public final class PrivilegeBuilder {
}
}
- private static void checkPrivileges(final Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> userPrivilegeMap) {
- for (Entry<ShardingSphereUser, Collection<ShardingSpherePrivilege>> entry : userPrivilegeMap.entrySet()) {
- for (ShardingSpherePrivilege each : entry.getValue()) {
+ private static void checkPrivileges(final Map<ShardingSphereUser, Collection<Privileges>> userPrivilegeMap) {
+ for (Entry<ShardingSphereUser, Collection<Privileges>> entry : userPrivilegeMap.entrySet()) {
+ for (Privileges each : entry.getValue()) {
if (each.isEmpty()) {
throw new ShardingSphereException(String.format("There is no enough privileges for %s on all database instances.", entry.getKey().getGrantee().toString().replaceAll("%", "%%")));
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
index 5ee2971..ef0380c 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.authority.loader.builder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -44,23 +44,23 @@ public final class PrivilegeMerger {
* @param rules ShardingSphere rules
* @return privileges
*/
- public static Map<ShardingSphereUser, ShardingSpherePrivilege> merge(final Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> authentication,
- final String schemaName, final Collection<ShardingSphereRule> rules) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new HashMap<>(authentication.size(), 1);
- for (Entry<ShardingSphereUser, Collection<ShardingSpherePrivilege>> entry : authentication.entrySet()) {
+ public static Map<ShardingSphereUser, Privileges> merge(final Map<ShardingSphereUser, Collection<Privileges>> authentication,
+ final String schemaName, final Collection<ShardingSphereRule> rules) {
+ Map<ShardingSphereUser, Privileges> result = new HashMap<>(authentication.size(), 1);
+ for (Entry<ShardingSphereUser, Collection<Privileges>> entry : authentication.entrySet()) {
result.put(entry.getKey(), merge(entry.getKey(), entry.getValue()));
}
return result;
}
- private static ShardingSpherePrivilege merge(final ShardingSphereUser user, final Collection<ShardingSpherePrivilege> privileges) {
+ private static Privileges merge(final ShardingSphereUser user, final Collection<Privileges> privileges) {
if (privileges.isEmpty()) {
- return new ShardingSpherePrivilege();
+ return new Privileges();
}
- Iterator<ShardingSpherePrivilege> iterator = privileges.iterator();
- ShardingSpherePrivilege result = iterator.next();
+ Iterator<Privileges> iterator = privileges.iterator();
+ Privileges result = iterator.next();
while (iterator.hasNext()) {
- ShardingSpherePrivilege each = iterator.next();
+ Privileges each = iterator.next();
if (!result.equals(each)) {
throw new ShardingSphereException("Different physical instances have different permissions for user %s@%s", user.getGrantee().getUsername(), user.getGrantee().getHostname());
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
index 1cfc6cb..12c746c 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.authority.loader.builder.loader;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import javax.sql.DataSource;
@@ -38,7 +38,7 @@ public interface PrivilegeLoader {
* @return ShardingSphere privilege
* @throws SQLException SQL exception
*/
- Map<ShardingSphereUser, ShardingSpherePrivilege> load(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
+ Map<ShardingSphereUser, Privileges> load(Collection<ShardingSphereUser> users, DataSource dataSource) throws SQLException;
/**
* Get database type.
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
index 44eb27f..5b82252 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
-import org.apache.shardingsphere.authority.model.database.SchemaPrivilege;
-import org.apache.shardingsphere.authority.model.database.TablePrivilege;
+import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
+import org.apache.shardingsphere.authority.model.database.TablePrivileges;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -50,99 +50,98 @@ public final class MySQLPrivilegeLoader implements PrivilegeLoader {
private static final String TABLE_PRIVILEGE_SQL = "SELECT Db, Table_name, Table_priv FROM mysql.tables_priv WHERE (user, host) in (%s)";
@Override
- public Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
- users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));
- fillGlobalPrivilege(result, dataSource, users);
- fillSchemaPrivilege(result, dataSource, users);
- fillTablePrivilege(result, dataSource, users);
+ public Map<ShardingSphereUser, Privileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
+ Map<ShardingSphereUser, Privileges> result = new LinkedHashMap<>();
+ users.forEach(user -> result.put(user, new Privileges()));
+ fillGlobalPrivileges(result, dataSource, users);
+ fillSchemaPrivileges(result, dataSource, users);
+ fillTablePrivileges(result, dataSource, users);
return result;
}
- private void fillGlobalPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
+ private void fillGlobalPrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
Statement statement = connection.createStatement();
- try (ResultSet resultSet = statement.executeQuery(getGlobalPrivilegeSQL(users))) {
+ try (ResultSet resultSet = statement.executeQuery(getGlobalPrivilegesSQL(users))) {
while (resultSet.next()) {
- fillGlobalPrivilege(privileges, resultSet);
+ fillGlobalPrivileges(userPrivilegeMap, resultSet);
}
}
}
}
- private void fillGlobalPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
+ private void fillGlobalPrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
+ Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
if (user.isPresent()) {
- privileges.get(user.get()).getAdministrativePrivilege().getPrivileges().addAll(loadAdministrativePrivileges(resultSet));
- privileges.get(user.get()).getDatabasePrivilege().getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
+ userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadAdministrativePrivileges(resultSet));
+ userPrivilegeMap.get(user.get()).getDatabasePrivileges().getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
}
}
- private void fillSchemaPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
+ private void fillSchemaPrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
Statement statement = connection.createStatement();
- try (ResultSet resultSet = statement.executeQuery(getSchemaPrivilegeSQL(users))) {
+ try (ResultSet resultSet = statement.executeQuery(getSchemaPrivilegesSQL(users))) {
while (resultSet.next()) {
- fillSchemaPrivilege(privileges, resultSet);
+ fillSchemaPrivileges(userPrivilegeMap, resultSet);
}
}
}
}
- private void fillSchemaPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
+ private void fillSchemaPrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
+ Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
if (user.isPresent()) {
String db = resultSet.getString("Db");
- SchemaPrivilege schemaPrivilege = new SchemaPrivilege(db);
- schemaPrivilege.getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
- privileges.get(user.get()).getDatabasePrivilege().getSpecificPrivileges().put(db, schemaPrivilege);
+ SchemaPrivileges schemaPrivileges = new SchemaPrivileges(db);
+ schemaPrivileges.getGlobalPrivileges().addAll(loadDatabaseGlobalPrivileges(resultSet));
+ userPrivilegeMap.get(user.get()).getDatabasePrivileges().getSpecificPrivileges().put(db, schemaPrivileges);
}
}
- private void fillTablePrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
+ private void fillTablePrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
Statement statement = connection.createStatement();
- try (ResultSet resultSet = statement.executeQuery(getTablePrivilegeSQL(users))) {
+ try (ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
while (resultSet.next()) {
- fillTablePrivilege(privileges, resultSet);
+ fillTablePrivileges(userPrivilegeMap, resultSet);
}
}
}
}
- private void fillTablePrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
+ private void fillTablePrivileges(final Map<ShardingSphereUser, Privileges> 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");
- String[] tablePrivileges = (String[]) resultSet.getArray("Table_priv").getArray();
- TablePrivilege tablePrivilege = new TablePrivilege(tableName, getPrivileges(tablePrivileges));
- ShardingSpherePrivilege privilege = privileges.get(user.get());
- if (!privilege.getDatabasePrivilege().getSpecificPrivileges().containsKey(db)) {
- privilege.getDatabasePrivilege().getSpecificPrivileges().put(db, new SchemaPrivilege(db));
+ TablePrivileges tablePrivileges = new TablePrivileges(tableName, getPrivileges((String[]) resultSet.getArray("Table_priv").getArray()));
+ Privileges privileges = userPrivilegeMap.get(user.get());
+ if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
+ privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
}
- privilege.getDatabasePrivilege().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivilege);
+ privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
}
}
- private String getGlobalPrivilegeSQL(final Collection<ShardingSphereUser> users) {
+ 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 getSchemaPrivilegeSQL(final Collection<ShardingSphereUser> users) {
+ 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 getTablePrivilegeSQL(final Collection<ShardingSphereUser> users) {
+ 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> getShardingSphereUser(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
+ private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, Privileges> 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();
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
index 9ff6e96..6cbf80b 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
-import org.apache.shardingsphere.authority.model.database.SchemaPrivilege;
-import org.apache.shardingsphere.authority.model.database.TablePrivilege;
+import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
+import org.apache.shardingsphere.authority.model.database.TablePrivileges;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -48,46 +48,47 @@ public final class PostgreSQLPrivilegeLoader implements PrivilegeLoader {
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)";
+ 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 Map<ShardingSphereUser, ShardingSpherePrivilege> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new LinkedHashMap<>();
- users.forEach(user -> result.put(user, new ShardingSpherePrivilege()));
- fillTablePrivilege(result, dataSource, users);
- fillRolePrivilege(result, dataSource, users);
+ public Map<ShardingSphereUser, Privileges> load(final Collection<ShardingSphereUser> users, final DataSource dataSource) throws SQLException {
+ Map<ShardingSphereUser, Privileges> result = new LinkedHashMap<>();
+ users.forEach(user -> result.put(user, new Privileges()));
+ fillTablePrivileges(result, dataSource, users);
+ fillRolePrivileges(result, dataSource, users);
return result;
}
- private void fillTablePrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
+ private void fillTablePrivileges(final Map<ShardingSphereUser, Privileges> 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();
- try (ResultSet resultSet = statement.executeQuery(getTablePrivilegeSQL(users))) {
+ try (ResultSet resultSet = statement.executeQuery(getTablePrivilegesSQL(users))) {
while (resultSet.next()) {
- collectPrivilege(privilegeCache, resultSet);
+ collectPrivileges(privilegeCache, resultSet);
}
}
}
- fillTablePrivilege(privilegeCache, privileges);
+ fillTablePrivileges(privilegeCache, userPrivilegeMap);
}
- private void fillTablePrivilege(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges) {
+ private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final Map<ShardingSphereUser, Privileges> 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()) {
- TablePrivilege tablePrivilege = new TablePrivilege(tableName, entry.getValue().get(db).get(tableName));
- ShardingSpherePrivilege privilege = privileges.get(entry.getKey());
- if (!privilege.getDatabasePrivilege().getSpecificPrivileges().containsKey(db)) {
- privilege.getDatabasePrivilege().getSpecificPrivileges().put(db, new SchemaPrivilege(db));
+ TablePrivileges tablePrivileges = new TablePrivileges(tableName, entry.getValue().get(db).get(tableName));
+ Privileges privileges = userPrivilegeMap.get(entry.getKey());
+ if (!privileges.getDatabasePrivileges().getSpecificPrivileges().containsKey(db)) {
+ privileges.getDatabasePrivileges().getSpecificPrivileges().put(db, new SchemaPrivileges(db));
}
- privilege.getDatabasePrivilege().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivilege);
+ privileges.getDatabasePrivileges().getSpecificPrivileges().get(db).getSpecificPrivileges().put(tableName, tablePrivileges);
}
}
}
}
- private void collectPrivilege(final Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> privilegeCache, final ResultSet resultSet) throws SQLException {
+ 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");
@@ -102,27 +103,27 @@ public final class PostgreSQLPrivilegeLoader implements PrivilegeLoader {
}
}
- private void fillRolePrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
+ private void fillRolePrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final DataSource dataSource, final Collection<ShardingSphereUser> users) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
Statement statement = connection.createStatement();
- try (ResultSet resultSet = statement.executeQuery(getRolePrivilegeSQL(users))) {
+ try (ResultSet resultSet = statement.executeQuery(getRolePrivilegesSQL(users))) {
while (resultSet.next()) {
- fillRolePrivilege(privileges, resultSet);
+ fillRolePrivileges(userPrivilegeMap, resultSet);
}
}
}
}
- private void fillRolePrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
- Optional<ShardingSphereUser> user = getShardingSphereUser(privileges, resultSet);
+ private void fillRolePrivileges(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
+ Optional<ShardingSphereUser> user = findShardingSphereUser(userPrivilegeMap, resultSet);
if (user.isPresent()) {
- privileges.get(user.get()).getAdministrativePrivilege().getPrivileges().addAll(loadRolePrivileges(resultSet));
+ userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadRolePrivileges(resultSet));
}
}
- private Optional<ShardingSphereUser> getShardingSphereUser(final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges, final ResultSet resultSet) throws SQLException {
+ private Optional<ShardingSphereUser> findShardingSphereUser(final Map<ShardingSphereUser, Privileges> userPrivilegeMap, final ResultSet resultSet) throws SQLException {
Grantee grantee = new Grantee(resultSet.getString("rolname"), "");
- return privileges.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
+ return userPrivilegeMap.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst();
}
private Collection<PrivilegeType> loadRolePrivileges(final ResultSet resultSet) throws SQLException {
@@ -136,12 +137,12 @@ public final class PostgreSQLPrivilegeLoader implements PrivilegeLoader {
return result;
}
- private String getTablePrivilegeSQL(final Collection<ShardingSphereUser> users) {
+ 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 getRolePrivilegeSQL(final Collection<ShardingSphereUser> users) {
+ 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);
}
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
index 1af2ac7..c757259 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -52,7 +52,7 @@ public final class MySQLPrivilegeLoaderTest {
public void assertLoad() throws SQLException {
Collection<ShardingSphereUser> users = createUsers();
DataSource dataSource = mockDataSource(users);
- assertPrivilege(getPrivilegeLoader().load(users, dataSource));
+ assertPrivileges(getPrivilegeLoader().load(users, dataSource));
}
private Collection<ShardingSphereUser> createUsers() {
@@ -153,20 +153,20 @@ public final class MySQLPrivilegeLoaderTest {
return result;
}
- private void assertPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> actual) {
+ private void assertPrivileges(final Map<ShardingSphereUser, Privileges> actual) {
assertThat(actual.size(), is(2));
ShardingSphereUser root = new ShardingSphereUser("root", "", "localhost");
- assertThat(actual.get(root).getAdministrativePrivilege().getPrivileges().size(), is(3));
+ assertThat(actual.get(root).getAdministrativePrivileges().getPrivileges().size(), is(3));
Collection<PrivilegeType> expectedAdministrativePrivileges = new CopyOnWriteArraySet<>(Arrays.asList(PrivilegeType.SUPER, PrivilegeType.RELOAD, PrivilegeType.SHUTDOWN));
- assertThat(actual.get(root).getAdministrativePrivilege().getPrivileges(), is(expectedAdministrativePrivileges));
+ assertThat(actual.get(root).getAdministrativePrivileges().getPrivileges(), is(expectedAdministrativePrivileges));
Collection<PrivilegeType> expectedDatabasePrivileges = new CopyOnWriteArraySet<>(
Arrays.asList(PrivilegeType.SELECT, PrivilegeType.INSERT, PrivilegeType.UPDATE, PrivilegeType.DELETE, PrivilegeType.CREATE, PrivilegeType.ALTER));
- assertThat(actual.get(root).getDatabasePrivilege().getGlobalPrivileges().size(), is(6));
- assertThat(actual.get(root).getDatabasePrivilege().getGlobalPrivileges(), is(expectedDatabasePrivileges));
+ assertThat(actual.get(root).getDatabasePrivileges().getGlobalPrivileges().size(), is(6));
+ assertThat(actual.get(root).getDatabasePrivileges().getGlobalPrivileges(), is(expectedDatabasePrivileges));
ShardingSphereUser sys = new ShardingSphereUser("mysql.sys", "", "localhost");
- assertThat(actual.get(sys).getAdministrativePrivilege().getPrivileges().size(), is(0));
- assertThat(actual.get(sys).getDatabasePrivilege().getGlobalPrivileges().size(), is(0));
- assertThat(actual.get(sys).getDatabasePrivilege().getSpecificPrivileges().size(), is(1));
+ assertThat(actual.get(sys).getAdministrativePrivileges().getPrivileges().size(), is(0));
+ assertThat(actual.get(sys).getDatabasePrivileges().getGlobalPrivileges().size(), is(0));
+ assertThat(actual.get(sys).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
}
private PrivilegeLoader getPrivilegeLoader() {
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
index 473dc1d..5b5ded9 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
import org.apache.shardingsphere.authority.model.PrivilegeType;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
-import org.apache.shardingsphere.authority.model.database.SchemaPrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
+import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -57,22 +57,22 @@ public final class PostgreSQLPrivilegeLoaderTest {
public void assertLoad() throws SQLException {
Collection<ShardingSphereUser> users = createUsers();
DataSource dataSource = mockDataSource(users);
- assertPrivilege(getPrivilegeLoader().load(users, dataSource));
+ assertPrivileges(getPrivilegeLoader().load(users, dataSource));
}
- private void assertPrivilege(final Map<ShardingSphereUser, ShardingSpherePrivilege> actual) {
+ private void assertPrivileges(final Map<ShardingSphereUser, Privileges> actual) {
assertThat(actual.size(), is(1));
ShardingSphereUser user = new ShardingSphereUser("postgres", "", "");
- assertThat(actual.get(user).getDatabasePrivilege().getGlobalPrivileges().size(), is(0));
- assertThat(actual.get(user).getDatabasePrivilege().getSpecificPrivileges().size(), is(1));
+ assertThat(actual.get(user).getDatabasePrivileges().getGlobalPrivileges().size(), is(0));
+ assertThat(actual.get(user).getDatabasePrivileges().getSpecificPrivileges().size(), is(1));
Collection<PrivilegeType> expectedSpecificPrivilege = new CopyOnWriteArraySet(Arrays.asList(PrivilegeType.INSERT, PrivilegeType.SELECT, PrivilegeType.UPDATE,
PrivilegeType.DELETE));
- SchemaPrivilege schemaPrivilege = actual.get(user).getDatabasePrivilege().getSpecificPrivileges().get("db0");
- assertThat(schemaPrivilege.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege), is(true));
- assertThat(actual.get(user).getAdministrativePrivilege().getPrivileges().size(), is(4));
+ SchemaPrivileges schemaPrivileges = actual.get(user).getDatabasePrivileges().getSpecificPrivileges().get("db0");
+ assertThat(schemaPrivileges.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege), is(true));
+ assertThat(actual.get(user).getAdministrativePrivileges().getPrivileges().size(), is(4));
Collection<PrivilegeType> expectedAdministrativePrivilege = new CopyOnWriteArraySet(Arrays.asList(PrivilegeType.SUPER, PrivilegeType.CREATE_ROLE,
PrivilegeType.CREATE_DATABASE, PrivilegeType.CAN_LOGIN));
- assertEquals(actual.get(user).getAdministrativePrivilege().getPrivileges(), expectedAdministrativePrivilege);
+ assertEquals(actual.get(user).getAdministrativePrivileges().getPrivileges(), expectedAdministrativePrivilege);
}
private Collection<ShardingSphereUser> createUsers() {
diff --git a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
index 54a4f80..d2361e3 100644
--- a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
+++ b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.authority.loader.builder.PrivilegeBuilder;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoaderEngine;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import java.util.Collection;
@@ -73,9 +73,9 @@ public final class GovernanceAuthorityContext implements MetaDataAwareEventSubsc
private Authentication createAuthentication(final Collection<ShardingSphereUser> users) {
Authentication result = new DefaultAuthentication();
Collection<ShardingSphereUser> newUsers = getNewUsers(users);
- Map<ShardingSphereUser, ShardingSpherePrivilege> modifiedUsers = getModifiedUsers(users);
+ Map<ShardingSphereUser, Privileges> modifiedUsers = getModifiedUsers(users);
for (ShardingSphereUser each : newUsers) {
- modifiedUsers.put(each, new ShardingSpherePrivilege());
+ modifiedUsers.put(each, new Privileges());
}
result.init(modifiedUsers);
return result;
@@ -85,12 +85,12 @@ public final class GovernanceAuthorityContext implements MetaDataAwareEventSubsc
return users.stream().filter(each -> !AuthenticationContext.getInstance().getAuthentication().findUser(each.getGrantee()).isPresent()).collect(Collectors.toList());
}
- private Map<ShardingSphereUser, ShardingSpherePrivilege> getModifiedUsers(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new HashMap<>(users.size(), 1);
+ private Map<ShardingSphereUser, Privileges> getModifiedUsers(final Collection<ShardingSphereUser> users) {
+ Map<ShardingSphereUser, Privileges> result = new HashMap<>(users.size(), 1);
for (ShardingSphereUser each : users) {
Optional<ShardingSphereUser> user = AuthenticationContext.getInstance().getAuthentication().findUser(each.getGrantee());
if (user.isPresent()) {
- Optional<ShardingSpherePrivilege> privilege = AuthenticationContext.getInstance().getAuthentication().findPrivilege(user.get().getGrantee());
+ Optional<Privileges> privilege = AuthenticationContext.getInstance().getAuthentication().findPrivileges(user.get().getGrantee());
privilege.ifPresent(optional -> result.put(user.get(), optional));
}
}
@@ -102,15 +102,15 @@ public final class GovernanceAuthorityContext implements MetaDataAwareEventSubsc
DatabaseType databaseType = metaDataContexts.getMetaDataMap().values().iterator().next().getResource().getDatabaseType();
Optional<PrivilegeLoader> loader = PrivilegeLoaderEngine.findPrivilegeLoader(databaseType);
if (loader.isPresent()) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> privileges = PrivilegeBuilder.build(databaseType, metaDataContexts.getMetaDataMap().values(), users);
+ Map<ShardingSphereUser, Privileges> privileges = PrivilegeBuilder.build(databaseType, metaDataContexts.getMetaDataMap().values(), users);
authentication.getAuthentication().putAll(getPrivilegesWithPassword(authentication, privileges));
}
AuthenticationContext.getInstance().init(authentication);
}
- private Map<ShardingSphereUser, ShardingSpherePrivilege> getPrivilegesWithPassword(final Authentication authentication, final Map<ShardingSphereUser, ShardingSpherePrivilege> privileges) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> result = new HashMap<>(privileges.size(), 1);
- for (Map.Entry<ShardingSphereUser, ShardingSpherePrivilege> entry : privileges.entrySet()) {
+ private Map<ShardingSphereUser, Privileges> getPrivilegesWithPassword(final Authentication authentication, final Map<ShardingSphereUser, Privileges> privileges) {
+ Map<ShardingSphereUser, Privileges> result = new HashMap<>(privileges.size(), 1);
+ for (Map.Entry<ShardingSphereUser, Privileges> entry : privileges.entrySet()) {
if (privileges.containsKey(entry.getKey())) {
Optional<ShardingSphereUser> user = authentication.findUser(entry.getKey().getGrantee());
Preconditions.checkState(user.isPresent());
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
index 5ea2bb8..8920a75 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/facade/GovernanceFacadeTest.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.governance.repository.api.config.GovernanceCent
import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import org.junit.Before;
@@ -72,7 +72,7 @@ public final class GovernanceFacadeTest {
Map<String, Collection<RuleConfiguration>> ruleConfigurationMap = Collections.singletonMap("sharding_db", Collections.singletonList(mock(RuleConfiguration.class)));
ShardingSphereUser user = new ShardingSphereUser("root", "root", "");
DefaultAuthentication authentication = new DefaultAuthentication();
- authentication.getAuthentication().put(user, new ShardingSpherePrivilege());
+ authentication.getAuthentication().put(user, new Privileges());
Properties props = new Properties();
governanceFacade.onlineInstance(
Collections.singletonMap("sharding_db", dataSourceConfigMap), ruleConfigurationMap, authentication.getAllUsers(), props);
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index ba1f6e7..44b0419 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKe
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
import org.apache.shardingsphere.infra.metadata.user.yaml.swapper.UsersYamlSwapper;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
@@ -376,7 +376,7 @@ public final class RegistryCenterTest {
new UsersYamlSwapper().swapToObject(YamlEngine.unmarshal(readYAML(AUTHENTICATION_YAML), YamlUsersConfiguration.class));
DefaultAuthentication result = new DefaultAuthentication();
for (ShardingSphereUser each : users) {
- result.getAuthentication().put(each, new ShardingSpherePrivilege());
+ result.getAuthentication().put(each, new Privileges());
}
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
index 8c98415..7a8f3c9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutorTest.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.authority.engine.Authentication;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
import org.apache.shardingsphere.authority.engine.AuthenticationContext;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
@@ -69,7 +69,7 @@ public final class ShowDatabasesExecutorTest {
private void initAuthentication() {
Authentication authentication = new DefaultAuthentication();
- authentication.getAuthentication().put(new ShardingSphereUser("root", "root", ""), new ShardingSpherePrivilege());
+ authentication.getAuthentication().put(new ShardingSphereUser("root", "root", ""), new Privileges());
AuthenticationContext.getInstance().init(authentication);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
index f06eeef..3c9e1ba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
import org.apache.shardingsphere.authority.engine.Authentication;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
@@ -197,10 +197,10 @@ public final class GovernanceBootstrapInitializerTest extends AbstractBootstrapI
assertThat(props.getProperty("algorithm-expression"), is(expectedAlgorithmExpr));
}
- private Map<ShardingSphereUser, ShardingSpherePrivilege> getPrivileges(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> privileges = new HashMap<>(users.size(), 1);
+ private Map<ShardingSphereUser, Privileges> getPrivileges(final Collection<ShardingSphereUser> users) {
+ Map<ShardingSphereUser, Privileges> privileges = new HashMap<>(users.size(), 1);
for (ShardingSphereUser each : users) {
- privileges.put(each, new ShardingSpherePrivilege());
+ privileges.put(each, new Privileges());
}
return privileges;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
index 8746c29..a02a67a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializerTest.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.authority.engine.Authentication;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -152,10 +152,10 @@ public final class StandardBootstrapInitializerTest extends AbstractBootstrapIni
assertThat(((FixtureRuleConfiguration) actual).getName(), is("testRule"));
}
- private Map<ShardingSphereUser, ShardingSpherePrivilege> getPrivileges(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> privileges = new HashMap<>(users.size(), 1);
+ private Map<ShardingSphereUser, Privileges> getPrivileges(final Collection<ShardingSphereUser> users) {
+ Map<ShardingSphereUser, Privileges> privileges = new HashMap<>(users.size(), 1);
for (ShardingSphereUser each : users) {
- privileges.put(each, new ShardingSpherePrivilege());
+ privileges.put(each, new Privileges());
}
return privileges;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
index 626960a..459346f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfiguration;
import org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUsersConfiguration;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
@@ -113,10 +113,10 @@ public final class YamlProxyConfigurationSwapperTest {
assertNotNull(authentication);
}
- private Map<ShardingSphereUser, ShardingSpherePrivilege> getPrivileges(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivilege> privileges = new HashMap<>(users.size(), 1);
+ private Map<ShardingSphereUser, Privileges> getPrivileges(final Collection<ShardingSphereUser> users) {
+ Map<ShardingSphereUser, Privileges> privileges = new HashMap<>(users.size(), 1);
for (ShardingSphereUser each : users) {
- privileges.put(each, new ShardingSpherePrivilege());
+ privileges.put(each, new Privileges());
}
return privileges;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
index c1a28f2..45448f3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
@@ -123,9 +123,9 @@ public final class MySQLAuthenticationHandlerTest {
private void setAuthentication(final ShardingSphereUser user) {
DefaultAuthentication authentication = new DefaultAuthentication();
- ShardingSpherePrivilege privilege = new ShardingSpherePrivilege();
- privilege.setSuperPrivilege();
- authentication.getAuthentication().put(user, privilege);
+ Privileges privileges = new Privileges();
+ privileges.setSuperPrivilege();
+ authentication.getAuthentication().put(user, privileges);
initProxyContext(user);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
index a5c4f9c..a9f4c04 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.bin
import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLAuthenticationMD5PasswordPacket;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
import org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivilege;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResult;
@@ -123,8 +123,8 @@ public final class PostgreSQLAuthenticationEngineTest {
payload.writeInt4(4 + md5Digest.length() + 1);
payload.writeStringNul(md5Digest);
StandardMetaDataContexts standardMetaDataContexts = new StandardMetaDataContexts();
- ShardingSpherePrivilege privilege = new ShardingSpherePrivilege();
- privilege.setSuperPrivilege();
+ Privileges privileges = new Privileges();
+ privileges.setSuperPrivilege();
standardMetaDataContexts.getUsers().getUsers().add(new ShardingSphereUser(username, password, ""));
ProxyContext.getInstance().init(standardMetaDataContexts, mock(TransactionContexts.class));
actual = engine.auth(channelHandlerContext, payload);