This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 54ba7d6 Use AuthorityCheckAlgorithm to make init and findPrivileges
pluggable (#10015)
54ba7d6 is described below
commit 54ba7d6a1bfc70d090638749684202d7a7363144
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Apr 9 23:48:51 2021 +0800
Use AuthorityCheckAlgorithm to make init and findPrivileges pluggable
(#10015)
* Refactor ShardingSphereAuthority to AuthorityCheckAlgorithm
* Remove PrivilegeLoadAlgorithm
* Remove AuthorityEngine
* Move StorageAuthorityCheckAlgorithm
* Refactor AuthorityContext
* Move storage loader package
---
.../api/config/AuthorityRuleConfiguration.java | 2 +-
.../authority/spi/AuthorityCheckAlgorithm.java} | 14 ++--
.../authority/spi/PrivilegeLoadAlgorithm.java | 41 -----------
.../authority/{engine => }/AuthorityContext.java | 13 ++--
.../storage/StorageAuthorityCheckAlgorithm.java} | 20 ++++--
.../loader/StoragePrivilegeLoadEngine.java} | 23 +++----
.../storage/loader}/StoragePrivilegeLoader.java | 4 +-
.../loader}/impl/StoragePrivilegeBuilder.java | 3 +-
.../loader}/impl/StoragePrivilegeMerger.java | 2 +-
.../loader}/impl/dialect/MySQLPrivilegeLoader.java | 4 +-
.../impl/dialect/OraclePrivilegeLoader.java | 6 +-
.../impl/dialect/PostgreSQLPrivilegeLoader.java | 4 +-
.../authority/checker/AuthorityChecker.java | 6 +-
.../authority/engine/AuthorityEngine.java | 46 -------------
.../authority/rule/AuthorityRule.java | 17 ++---
.../config/YamlAuthorityRuleConfiguration.java | 2 +-
.../AuthorityRuleConfigurationYamlSwapper.java | 4 +-
...lgorithm.storage.loader.StoragePrivilegeLoader} | 6 +-
...ngsphere.authority.spi.AuthorityCheckAlgorithm} | 2 +-
.../impl/dialect/MySQLPrivilegeLoaderTest.java | 4 +-
.../impl/dialect/OraclePrivilegeLoaderTest.java | 4 +-
.../dialect/PostgreSQLPrivilegeLoaderTest.java | 4 +-
.../authority/merge/PrivilegeMergeTest.java | 2 +-
.../authority/GovernanceAuthorityContext.java | 80 ++++------------------
.../metadata/GovernanceMetaDataContextsTest.java | 4 +-
.../mysql/executor/ShowDatabasesExecutorTest.java | 22 +++---
.../src/main/resources/conf/server.yaml | 11 ++-
.../proxy/config/ProxyConfigurationLoader.java | 4 +-
.../mysql/auth/MySQLAuthenticationHandlerTest.java | 15 ++--
29 files changed, 115 insertions(+), 254 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
index 5a53460..d19a2ae 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/api/config/AuthorityRuleConfiguration.java
@@ -29,5 +29,5 @@ import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmC
@Getter
public final class AuthorityRuleConfiguration implements RuleConfiguration {
- private final ShardingSphereAlgorithmConfiguration privilegeLoader;
+ private final ShardingSphereAlgorithmConfiguration checker;
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityCheckAlgorithm.java
similarity index 72%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityCheckAlgorithm.java
index ccb8945..93e0eb6 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/ShardingSphereAuthority.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityCheckAlgorithm.java
@@ -15,26 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.engine;
+package org.apache.shardingsphere.authority.spi;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import java.util.Collection;
import java.util.Map;
import java.util.Optional;
/**
- * ShardingSphere authority.
+ * Authority check algorithm.
*/
-public interface ShardingSphereAuthority {
+public interface AuthorityCheckAlgorithm extends ShardingSphereAlgorithm {
/**
* Initialize authority.
*
- * @param loadedUserPrivilegeMap loaded map of users and privileges
+ * @param mataDataMap mata data map
+ * @param users users
*/
- void init(Map<ShardingSphereUser, ShardingSpherePrivileges>
loadedUserPrivilegeMap);
+ void init(Map<String, ShardingSphereMetaData> mataDataMap,
Collection<ShardingSphereUser> users);
/**
* Find Privileges.
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
deleted file mode 100644
index 59f72b5..0000000
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeLoadAlgorithm.java
+++ /dev/null
@@ -1,41 +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.spi;
-
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Privilege load algorithm.
- */
-public interface PrivilegeLoadAlgorithm extends ShardingSphereAlgorithm {
-
- /**
- * Load privileges.
- *
- * @param mataDataMap mata data map
- * @param users users
- * @return user and privileges map
- */
- Map<ShardingSphereUser, ShardingSpherePrivileges> load(Map<String,
ShardingSphereMetaData> mataDataMap, Collection<ShardingSphereUser> users);
-}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityContext.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/AuthorityContext.java
similarity index 78%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityContext.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/AuthorityContext.java
index 7dc0540..fb4a9bf 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityContext.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/AuthorityContext.java
@@ -15,11 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.engine;
+package org.apache.shardingsphere.authority;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm;
/**
* Authority context.
@@ -30,7 +31,7 @@ public final class AuthorityContext {
private static final AuthorityContext INSTANCE = new AuthorityContext();
- private volatile ShardingSphereAuthority authority;
+ private volatile AuthorityCheckAlgorithm checker;
/**
* Get instance.
@@ -42,11 +43,11 @@ public final class AuthorityContext {
}
/**
- * Initial authority.
+ * Initial authority checker.
*
- * @param authority authority
+ * @param checker authority checker
*/
- public synchronized void init(final ShardingSphereAuthority authority) {
- this.authority = AuthorityEngine.findSPIAuthority().orElse(authority);
+ public synchronized void init(final AuthorityCheckAlgorithm checker) {
+ this.checker = checker;
}
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/StorageAuthorityCheckAlgorithm.java
similarity index 66%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/StorageAuthorityCheckAlgorithm.java
index 503fcd6..5f72ce3 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/impl/DefaultAuthority.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/StorageAuthorityCheckAlgorithm.java
@@ -15,31 +15,39 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.engine.impl;
+package org.apache.shardingsphere.authority.algorithm.storage;
-import org.apache.shardingsphere.authority.engine.ShardingSphereAuthority;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoadEngine;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Default authority.
+ * Storage authority check algorithm.
*/
-public final class DefaultAuthority implements ShardingSphereAuthority {
+public final class StorageAuthorityCheckAlgorithm implements
AuthorityCheckAlgorithm {
private final Map<ShardingSphereUser, ShardingSpherePrivileges>
userPrivilegeMap = new ConcurrentHashMap<>();
@Override
- public void init(final Map<ShardingSphereUser, ShardingSpherePrivileges>
loadedUserPrivilegeMap) {
- userPrivilegeMap.putAll(loadedUserPrivilegeMap);
+ public void init(final Map<String, ShardingSphereMetaData> mataDataMap,
final Collection<ShardingSphereUser> users) {
+ userPrivilegeMap.putAll(new
StoragePrivilegeLoadEngine().load(mataDataMap, users));
}
@Override
public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee
grantee) {
return userPrivilegeMap.keySet().stream().filter(each ->
each.getGrantee().equals(grantee)).findFirst().map(userPrivilegeMap::get);
}
+
+ @Override
+ public String getType() {
+ return "STORAGE";
+ }
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoadEngine.java
similarity index 74%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoadEngine.java
index 65600c0..f9c8c5e 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoadEngine.java
@@ -15,12 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage;
+package org.apache.shardingsphere.authority.algorithm.storage.loader;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeBuilder;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.StoragePrivilegeBuilder;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -30,21 +28,22 @@ import java.util.LinkedList;
import java.util.Map;
/**
- * Storage privilege load algorithm.
+ * Storage privilege load engine.
*/
-public final class StoragePrivilegeLoadAlgorithm implements
PrivilegeLoadAlgorithm {
+public final class StoragePrivilegeLoadEngine {
static {
ShardingSphereServiceLoader.register(StoragePrivilegeLoader.class);
}
- @Override
+ /**
+ * Load privileges.
+ *
+ * @param mataDataMap mata data map
+ * @param users users
+ * @return user and privileges map
+ */
public Map<ShardingSphereUser, ShardingSpherePrivileges> load(final
Map<String, ShardingSphereMetaData> mataDataMap, final
Collection<ShardingSphereUser> users) {
return StoragePrivilegeBuilder.build(new
LinkedList<>(mataDataMap.values()), users);
}
-
- @Override
- public String getType() {
- return "STORAGE";
- }
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoader.java
similarity index 93%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoader.java
index 9ab640d..5112abb 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/StoragePrivilegeLoader.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl;
+package org.apache.shardingsphere.authority.algorithm.storage.loader;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -36,7 +36,7 @@ public interface StoragePrivilegeLoader extends TypedSPI {
*
* @param users users
* @param dataSource data source
- * @return ShardingSphere privilege
+ * @return ShardingSphere privileges
* @throws SQLException SQL exception
*/
Map<ShardingSphereUser, ShardingSpherePrivileges>
load(Collection<ShardingSphereUser> users, DataSource dataSource) throws
SQLException;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeBuilder.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeBuilder.java
index 2eaa7241..9bd8fa0 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeBuilder.java
@@ -15,11 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl;
+package org.apache.shardingsphere.authority.algorithm.storage.loader.impl;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeMerger.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeMerger.java
index 3ca8976..5ef1b97 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/StoragePrivilegeMerger.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl;
+package org.apache.shardingsphere.authority.algorithm.storage.loader.impl;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoader.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoader.java
index 9a7741a..1b2f2dc 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoader.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
import org.apache.shardingsphere.authority.model.database.TablePrivileges;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoader.java
similarity index 97%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoader.java
index b9dd567..1869a74 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoader.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
@@ -92,7 +92,7 @@ public final class OraclePrivilegeLoader implements
StoragePrivilegeLoader {
String db = resultSet.getString("TABLE_SCHEMA");
String tableName = resultSet.getString("TABLE_NAME");
String privilegeType = resultSet.getString("PRIVILEGE");
- boolean hasPrivilege =
resultSet.getString("GRANTABLE").equalsIgnoreCase("YES");
+ boolean hasPrivilege =
"YES".equalsIgnoreCase(resultSet.getString("GRANTABLE"));
String grantee = resultSet.getString("GRANTEE");
if (hasPrivilege) {
privilegeCache
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoader.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoader.java
index 1e40c85..d1332d6 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoader.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
import org.apache.shardingsphere.authority.model.database.TablePrivileges;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
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 292abba..30cd691 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
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.check.SQLCheckResult;
import org.apache.shardingsphere.infra.check.SQLChecker;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.authority.engine.AuthorityContext;
+import org.apache.shardingsphere.authority.AuthorityContext;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -43,7 +43,7 @@ public final class AuthorityChecker implements
SQLChecker<AuthorityRule> {
if (null == grantee) {
return true;
}
- return
AuthorityContext.getInstance().getAuthority().findPrivileges(grantee).map(optional
-> optional.hasPrivileges(schemaName)).orElse(false);
+ return
AuthorityContext.getInstance().getChecker().findPrivileges(grantee).map(optional
-> optional.hasPrivileges(schemaName)).orElse(false);
}
@Override
@@ -51,7 +51,7 @@ public final class AuthorityChecker implements
SQLChecker<AuthorityRule> {
if (null == grantee) {
return new SQLCheckResult(true, "");
}
- Optional<ShardingSpherePrivileges> privileges =
AuthorityContext.getInstance().getAuthority().findPrivileges(grantee);
+ Optional<ShardingSpherePrivileges> privileges =
AuthorityContext.getInstance().getChecker().findPrivileges(grantee);
// TODO add error msg
return privileges.map(optional -> new
SQLCheckResult(optional.hasPrivileges(Collections.singletonList(getPrivilege(sqlStatement))),
"")).orElseGet(() -> new SQLCheckResult(false, ""));
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityEngine.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityEngine.java
deleted file mode 100644
index eb18fbf..0000000
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/engine/AuthorityEngine.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.engine;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Authority engine.
-*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AuthorityEngine {
-
- static {
- ShardingSphereServiceLoader.register(ShardingSphereAuthority.class);
- }
-
- /**
- * Find SPI authority.
- *
- * @return authority
- */
- public static Optional<ShardingSphereAuthority> findSPIAuthority() {
- Collection<ShardingSphereAuthority> authorities =
ShardingSphereServiceLoader.newServiceInstances(ShardingSphereAuthority.class);
- return authorities.isEmpty() ? Optional.empty() :
Optional.of(authorities.iterator().next());
- }
-}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index 7386bb2..ce4efa4 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -18,10 +18,8 @@
package org.apache.shardingsphere.authority.rule;
import
org.apache.shardingsphere.authority.api.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.engine.AuthorityContext;
-import org.apache.shardingsphere.authority.engine.ShardingSphereAuthority;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm;
+import org.apache.shardingsphere.authority.AuthorityContext;
+import org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -35,15 +33,14 @@ import java.util.Map;
* Authority rule.
*/
public final class AuthorityRule implements GlobalRule {
-
+
static {
- ShardingSphereServiceLoader.register(PrivilegeLoadAlgorithm.class);
+ ShardingSphereServiceLoader.register(AuthorityCheckAlgorithm.class);
}
public AuthorityRule(final AuthorityRuleConfiguration config, final
Map<String, ShardingSphereMetaData> mataDataMap, final
Collection<ShardingSphereUser> users) {
- PrivilegeLoadAlgorithm privilegeLoader =
ShardingSphereAlgorithmFactory.createAlgorithm(config.getPrivilegeLoader(),
PrivilegeLoadAlgorithm.class);
- ShardingSphereAuthority authority = null ==
AuthorityContext.getInstance().getAuthority() ? new DefaultAuthority() :
AuthorityContext.getInstance().getAuthority();
- authority.init(privilegeLoader.load(mataDataMap, users));
- AuthorityContext.getInstance().init(authority);
+ AuthorityCheckAlgorithm checker =
ShardingSphereAlgorithmFactory.createAlgorithm(config.getChecker(),
AuthorityCheckAlgorithm.class);
+ checker.init(mataDataMap, users);
+ AuthorityContext.getInstance().init(checker);
}
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
index 97113e2..5dba67c 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/config/YamlAuthorityRuleConfiguration.java
@@ -30,7 +30,7 @@ import
org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereA
@Setter
public final class YamlAuthorityRuleConfiguration implements
YamlRuleConfiguration {
- private YamlShardingSphereAlgorithmConfiguration privilegeLoader;
+ private YamlShardingSphereAlgorithmConfiguration checker;
@Override
public Class<AuthorityRuleConfiguration> getRuleConfigurationType() {
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
index eef268e..ce056e4 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationYamlSwapper.java
@@ -33,13 +33,13 @@ public final class AuthorityRuleConfigurationYamlSwapper
implements YamlRuleConf
@Override
public YamlAuthorityRuleConfiguration swapToYamlConfiguration(final
AuthorityRuleConfiguration data) {
YamlAuthorityRuleConfiguration result = new
YamlAuthorityRuleConfiguration();
-
result.setPrivilegeLoader(algorithmSwapper.swapToYamlConfiguration(data.getPrivilegeLoader()));
+
result.setChecker(algorithmSwapper.swapToYamlConfiguration(data.getChecker()));
return result;
}
@Override
public AuthorityRuleConfiguration swapToObject(final
YamlAuthorityRuleConfiguration yamlConfig) {
- return new
AuthorityRuleConfiguration(algorithmSwapper.swapToObject(yamlConfig.getPrivilegeLoader()));
+ return new
AuthorityRuleConfiguration(algorithmSwapper.swapToObject(yamlConfig.getChecker()));
}
@Override
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader
similarity index 72%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader
index d9e44b4..f1249e3 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader
@@ -15,6 +15,6 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.loader.storage.impl.dialect.MySQLPrivilegeLoader
-org.apache.shardingsphere.authority.loader.storage.impl.dialect.PostgreSQLPrivilegeLoader
-org.apache.shardingsphere.authority.loader.storage.impl.dialect.OraclePrivilegeLoader
+org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect.MySQLPrivilegeLoader
+org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect.PostgreSQLPrivilegeLoader
+org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect.OraclePrivilegeLoader
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm
similarity index 90%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm
index d6166f0..9c320a8 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.loader.storage.StoragePrivilegeLoadAlgorithm
+org.apache.shardingsphere.authority.algorithm.storage.StorageAuthorityCheckAlgorithm
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoaderTest.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoaderTest.java
index 0f696c9..f1a8417 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/MySQLPrivilegeLoaderTest.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoaderTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoaderTest.java
similarity index 97%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoaderTest.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoaderTest.java
index dc99de2..4e89921 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/OraclePrivilegeLoaderTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/OraclePrivilegeLoaderTest.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
similarity index 97%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
index 71de82f..f7e71c9 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/algorithm/storage/loader/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+package
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.dialect;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.StoragePrivilegeLoader;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/merge/PrivilegeMergeTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/merge/PrivilegeMergeTest.java
index 4260bad..c68062e 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/merge/PrivilegeMergeTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/merge/PrivilegeMergeTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.authority.merge;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeMerger;
+import
org.apache.shardingsphere.authority.algorithm.storage.loader.impl.StoragePrivilegeMerger;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
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 d4a0e99..a39c33a 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
@@ -17,29 +17,18 @@
package org.apache.shardingsphere.governance.context.authority;
-import com.google.common.base.Preconditions;
import com.google.common.eventbus.Subscribe;
import lombok.Setter;
-import org.apache.shardingsphere.authority.engine.ShardingSphereAuthority;
-import org.apache.shardingsphere.authority.engine.AuthorityContext;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeBuilder;
-import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import org.apache.shardingsphere.authority.AuthorityContext;
+import
org.apache.shardingsphere.authority.algorithm.storage.StorageAuthorityCheckAlgorithm;
+import org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm;
import
org.apache.shardingsphere.governance.core.event.model.auth.PrivilegeChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.auth.UserRuleChangedEvent;
import
org.apache.shardingsphere.infra.context.metadata.MetaDataAwareEventSubscriber;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.stream.Collectors;
/**
* Governance authority context.
@@ -54,11 +43,10 @@ public final class GovernanceAuthorityContext implements
MetaDataAwareEventSubsc
*
* @param event user changed event
*/
+ // TODO consider about merge UserRuleChangedEvent and PrivilegeChangedEvent
@Subscribe
public synchronized void renew(final UserRuleChangedEvent event) {
- ShardingSphereAuthority authority = createAuthority(event.getUsers());
- AuthorityContext.getInstance().init(authority);
- reloadPrivilege(event.getUsers());
+ reloadAuthority(event.getUsers());
}
/**
@@ -68,57 +56,13 @@ public final class GovernanceAuthorityContext implements
MetaDataAwareEventSubsc
*/
@Subscribe
public synchronized void renew(final PrivilegeChangedEvent event) {
- reloadPrivilege(event.getUsers());
+ reloadAuthority(event.getUsers());
}
-
- private ShardingSphereAuthority createAuthority(final
Collection<ShardingSphereUser> users) {
- ShardingSphereAuthority result = new DefaultAuthority();
- Collection<ShardingSphereUser> newUsers = getNewUsers(users);
- Map<ShardingSphereUser, ShardingSpherePrivileges> modifiedUsers =
getModifiedUsers(users);
- for (ShardingSphereUser each : newUsers) {
- modifiedUsers.put(each, new ShardingSpherePrivileges());
- }
- result.init(modifiedUsers);
- return result;
- }
-
- private Collection<ShardingSphereUser> getNewUsers(final
Collection<ShardingSphereUser> users) {
- return users.stream().filter(each ->
!metaDataContexts.getUsers().findUser(each.getGrantee()).isPresent()).collect(Collectors.toList());
- }
-
- private Map<ShardingSphereUser, ShardingSpherePrivileges>
getModifiedUsers(final Collection<ShardingSphereUser> users) {
- Map<ShardingSphereUser, ShardingSpherePrivileges> result = new
HashMap<>(users.size(), 1);
- for (ShardingSphereUser each : users) {
- Optional<ShardingSphereUser> user =
metaDataContexts.getUsers().findUser(each.getGrantee());
- if (user.isPresent()) {
- Optional<ShardingSpherePrivileges> privileges =
AuthorityContext.getInstance().getAuthority().findPrivileges(user.get().getGrantee());
- privileges.ifPresent(optional -> result.put(user.get(),
optional));
- }
- }
- return result;
- }
-
- private void reloadPrivilege(final Collection<ShardingSphereUser> users) {
- ShardingSphereAuthority authority =
AuthorityContext.getInstance().getAuthority();
- DatabaseType databaseType =
metaDataContexts.getMetaDataMap().values().iterator().next().getResource().getDatabaseType();
- Optional<StoragePrivilegeLoader> loader =
TypedSPIRegistry.findRegisteredService(StoragePrivilegeLoader.class,
databaseType.getName(), new Properties());
- // TODO :Authority, Loader is created here and still created in
StoragePrivilegeBuilder
- if (loader.isPresent()) {
- Map<ShardingSphereUser, ShardingSpherePrivileges> privileges =
StoragePrivilegeBuilder.build(metaDataContexts.getMetaDataMap().values(),
users);
- authority.init(getPrivilegesWithPassword(privileges));
- }
- AuthorityContext.getInstance().init(authority);
- }
-
- private Map<ShardingSphereUser, ShardingSpherePrivileges>
getPrivilegesWithPassword(final Map<ShardingSphereUser,
ShardingSpherePrivileges> privileges) {
- Map<ShardingSphereUser, ShardingSpherePrivileges> result = new
HashMap<>(privileges.size(), 1);
- for (Map.Entry<ShardingSphereUser, ShardingSpherePrivileges> entry :
privileges.entrySet()) {
- if (privileges.containsKey(entry.getKey())) {
- Optional<ShardingSphereUser> user =
metaDataContexts.getUsers().findUser(entry.getKey().getGrantee());
- Preconditions.checkState(user.isPresent());
- result.put(user.get(), entry.getValue());
- }
- }
- return result;
+
+ private void reloadAuthority(final Collection<ShardingSphereUser> users) {
+ // TODO reload AuthorityCheckAlgorithm from SPI
+ AuthorityCheckAlgorithm result = new StorageAuthorityCheckAlgorithm();
+ result.init(metaDataContexts.getMetaDataMap(), users);
+ AuthorityContext.getInstance().init(result);
}
}
diff --git
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
index ba7d2e8..47711b2 100644
---
a/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
+++
b/shardingsphere-governance/shardingsphere-governance-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.governance.context.metadata;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
+import
org.apache.shardingsphere.authority.algorithm.storage.StorageAuthorityCheckAlgorithm;
import
org.apache.shardingsphere.governance.core.event.model.auth.UserRuleChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.metadata.MetaDataDeletedEvent;
@@ -159,7 +159,7 @@ public final class GovernanceMetaDataContextsTest {
@Test
public void assertAuthorityChanged() {
- DefaultAuthority authority = new DefaultAuthority();
+ StorageAuthorityCheckAlgorithm authority = new
StorageAuthorityCheckAlgorithm();
UserRuleChangedEvent event = new
UserRuleChangedEvent(Collections.singleton(mock(ShardingSphereUser.class)));
governanceMetaDataContexts.renew(event);
assertThat(governanceMetaDataContexts.getUsers().getUsers().size(),
is(1));
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 357bcf9..4d61b6f 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
@@ -17,19 +17,18 @@
package org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor;
+import org.apache.shardingsphere.authority.AuthorityContext;
+import
org.apache.shardingsphere.authority.algorithm.storage.StorageAuthorityCheckAlgorithm;
+import org.apache.shardingsphere.authority.spi.AuthorityCheckAlgorithm;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import
org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataContexts;
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.ShardingSphereAuthority;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import org.apache.shardingsphere.authority.engine.AuthorityContext;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.Before;
@@ -40,7 +39,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@@ -63,17 +61,15 @@ public final class ShowDatabasesExecutorTest {
showDatabasesExecutor = new ShowDatabasesExecutor();
Field metaDataContexts =
ProxyContext.getInstance().getClass().getDeclaredField("metaDataContexts");
metaDataContexts.setAccessible(true);
- initAuthority();
+ initAuthorityCheckAlgorithm();
metaDataContexts.set(ProxyContext.getInstance(), new
StandardMetaDataContexts(getMetaDataMap(),
mock(ShardingSphereRuleMetaData.class),
mock(ExecutorEngine.class), new
ShardingSphereUsers(Collections.singleton(new ShardingSphereUser("root",
"root", ""))), new ConfigurationProperties(new Properties())));
}
- private void initAuthority() {
- ShardingSphereAuthority authority = new DefaultAuthority();
- Map<ShardingSphereUser, ShardingSpherePrivileges> userPrivilegeMap =
new HashMap<>(1, 1);
- userPrivilegeMap.put(new ShardingSphereUser("root", "root", ""), new
ShardingSpherePrivileges());
- authority.init(userPrivilegeMap);
- AuthorityContext.getInstance().init(authority);
+ private void initAuthorityCheckAlgorithm() {
+ AuthorityCheckAlgorithm algorithm = new
StorageAuthorityCheckAlgorithm();
+ algorithm.init(Collections.emptyMap(), Collections.emptyList());
+ AuthorityContext.getInstance().init(algorithm);
}
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index 9ddd6b6..12dc5fb 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -32,15 +32,15 @@
# maxRetries: 3
# operationTimeoutMilliseconds: 500
# overwrite: false
-
+#
#users:
# - root@%:root
# - sharding@:sharding
-
+#
#scaling:
# blockQueueSize: 10000
# workerThread: 40
-
+#
#props:
# max-connections-size-per-query: 1
# executor-size: 16 # Infinite by default.
@@ -56,3 +56,8 @@
# sql-show: false
# check-table-metadata-enabled: false
# lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock
+#
+#rules:
+# - !AUTHORITY
+# checker:
+# type: STORAGE
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
index a20a3a3..d4669c4 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.proxy.config;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.authority.engine.AuthorityEngine;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
import
org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
@@ -72,8 +71,7 @@ public final class ProxyConfigurationLoader {
private static YamlProxyServerConfiguration loadServerConfiguration(final
File yamlFile) throws IOException {
YamlProxyServerConfiguration result = YamlEngine.unmarshal(yamlFile,
YamlProxyServerConfiguration.class);
Preconditions.checkNotNull(result, "Server configuration file `%s` is
invalid.", yamlFile.getName());
- Preconditions.checkState(
- AuthorityEngine.findSPIAuthority().isPresent() ||
!result.getUsers().isEmpty() || null != result.getGovernance(), "Authority
configuration is invalid.");
+ Preconditions.checkState(!result.getUsers().isEmpty() || null !=
result.getGovernance(), "Authority configuration is invalid.");
return result;
}
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 503329e..0da3f7e 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
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.frontend.mysql.auth;
import com.google.common.primitives.Bytes;
import lombok.SneakyThrows;
+import
org.apache.shardingsphere.authority.algorithm.storage.StorageAuthorityCheckAlgorithm;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
import org.apache.shardingsphere.infra.check.SQLChecker;
@@ -28,12 +29,10 @@ import
org.apache.shardingsphere.infra.context.metadata.impl.StandardMetaDataCon
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUsers;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.Before;
@@ -122,12 +121,8 @@ public final class MySQLAuthenticationHandlerTest {
}
private void setAuthority(final ShardingSphereUser user) {
- DefaultAuthority authority = new DefaultAuthority();
- ShardingSpherePrivileges privileges = new ShardingSpherePrivileges();
- privileges.setSuperPrivilege();
- Map<ShardingSphereUser, ShardingSpherePrivileges> userPrivilegeMap =
new HashMap<>(1, 1);
- userPrivilegeMap.put(user, privileges);
- authority.init(userPrivilegeMap);
+ StorageAuthorityCheckAlgorithm algorithm = new
StorageAuthorityCheckAlgorithm();
+ algorithm.init(Collections.emptyMap(), Collections.emptyList());
initProxyContext(user);
}