Add authority provider module (#29556)
* Add authority provider module
* Add authority provider module
* Add authority provider module
* Add authority provider module
* Add authority provider module
diff --git a/infra/context/pom.xml b/infra/context/pom.xml
index 8efcd29..3599d6a 100644
--- a/infra/context/pom.xml
+++ b/infra/context/pom.xml
@@ -54,6 +54,16 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-simple</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-database</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-single-api</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
index bb7d9a1..6cb66c9 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/checker/AuthorityCheckerTest.java
@@ -39,14 +39,14 @@
@Test
void assertCheckIsAuthorizedDatabase() {
Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), null);
+ AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("FIXTURE", new Properties()), null);
assertTrue(new AuthorityChecker(new AuthorityRule(ruleConfig), new Grantee("root", "localhost")).isAuthorized("db0"));
}
@Test
void assertCheckPrivileges() {
Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
- AuthorityRule rule = new AuthorityRule(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), null));
+ AuthorityRule rule = new AuthorityRule(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("FIXTURE", new Properties()), null));
AuthorityChecker authorityChecker = new AuthorityChecker(rule, new Grantee("root", "localhost"));
authorityChecker.checkPrivileges(null, mock(SelectStatement.class));
authorityChecker.checkPrivileges(null, mock(InsertStatement.class));
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
similarity index 68%
copy from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
copy to kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
index 4714cbf..7bd3e1e 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
@@ -15,33 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.provider.simple;
+package org.apache.shardingsphere.authority.fixture;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.registry.AllPermittedAuthorityRegistry;
import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import java.util.Collection;
-import java.util.Collections;
+import java.util.Optional;
-/**
- * All permitted authority registry provider.
- */
-public final class AllPermittedAuthorityRegistryProvider implements AuthorityRegistryProvider {
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class AuthorityRegistryProviderFixture implements AuthorityRegistryProvider {
@Override
public AuthorityRegistry build(final Collection<ShardingSphereUser> users) {
- return new AllPermittedAuthorityRegistry();
+ AuthorityRegistry result = mock(AuthorityRegistry.class);
+ when(result.findPrivileges(any())).thenReturn(Optional.of(new ShardingSpherePrivilegesFixture()));
+ return result;
}
@Override
public String getType() {
- return "ALL_PERMITTED";
- }
-
- @Override
- public Collection<Object> getTypeAliases() {
- return Collections.singleton("ALL_PRIVILEGES_PERMITTED");
+ return "FIXTURE";
}
}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
similarity index 87%
copy from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java
copy to kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
index 78f8d4b..6b41d83 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.provider.simple.model.privilege;
+package org.apache.shardingsphere.authority.fixture;
import org.apache.shardingsphere.authority.model.AccessSubject;
import org.apache.shardingsphere.authority.model.PrivilegeType;
@@ -23,10 +23,7 @@
import java.util.Collection;
-/**
- * All permitted privileges.
- */
-public final class AllPermittedPrivileges implements ShardingSpherePrivileges {
+public final class ShardingSpherePrivilegesFixture implements ShardingSpherePrivileges {
@Override
public boolean hasPrivileges(final String database) {
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
index ad8d707..0d22b20 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
@@ -58,6 +58,6 @@
Collection<ShardingSphereUser> users = new LinkedList<>();
users.add(new ShardingSphereUser("root", "root", "localhost"));
users.add(new ShardingSphereUser("admin", "123456", "localhost"));
- return new AuthorityRule(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), null));
+ return new AuthorityRule(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("FIXTURE", new Properties()), null));
}
}
diff --git a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider b/kernel/authority/core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
similarity index 80%
copy from kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
copy to kernel/authority/core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
index b25b1f2..121e823 100644
--- a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
+++ b/kernel/authority/core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.provider.simple.AllPermittedAuthorityRegistryProvider
-org.apache.shardingsphere.authority.provider.database.DatabasePermittedAuthorityRegistryProvider
+org.apache.shardingsphere.authority.fixture.AuthorityRegistryProviderFixture
diff --git a/kernel/authority/pom.xml b/kernel/authority/pom.xml
index fba5674..e24287e 100644
--- a/kernel/authority/pom.xml
+++ b/kernel/authority/pom.xml
@@ -30,6 +30,7 @@
<modules>
<module>api</module>
<module>core</module>
+ <module>provider</module>
<module>distsql</module>
</modules>
</project>
diff --git a/kernel/authority/provider/database/pom.xml b/kernel/authority/provider/database/pom.xml
new file mode 100644
index 0000000..312c37c
--- /dev/null
+++ b/kernel/authority/provider/database/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-provider</artifactId>
+ <version>5.4.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-authority-database</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
similarity index 97%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
rename to kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
index cbc1aa7..010545f 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
+++ b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProvider.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.provider.database.model.privilege.DatabasePermittedPrivileges;
-import org.apache.shardingsphere.authority.registry.UserPrivilegeMapAuthorityRegistry;
+import org.apache.shardingsphere.authority.provider.database.registry.UserPrivilegeMapAuthorityRegistry;
import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
similarity index 100%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
rename to kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/model/privilege/DatabasePermittedPrivileges.java
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
similarity index 100%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
rename to kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/model/subject/DatabaseAccessSubject.java
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/UserPrivilegeMapAuthorityRegistry.java b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/registry/UserPrivilegeMapAuthorityRegistry.java
similarity index 95%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/UserPrivilegeMapAuthorityRegistry.java
rename to kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/registry/UserPrivilegeMapAuthorityRegistry.java
index 979a00e..55db290 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/UserPrivilegeMapAuthorityRegistry.java
+++ b/kernel/authority/provider/database/src/main/java/org/apache/shardingsphere/authority/provider/database/registry/UserPrivilegeMapAuthorityRegistry.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.registry;
+package org.apache.shardingsphere.authority.provider.database.registry;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
diff --git a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider b/kernel/authority/provider/database/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
similarity index 90%
rename from kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
rename to kernel/authority/provider/database/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
index b25b1f2..1ac13ed 100644
--- a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
+++ b/kernel/authority/provider/database/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.provider.simple.AllPermittedAuthorityRegistryProvider
org.apache.shardingsphere.authority.provider.database.DatabasePermittedAuthorityRegistryProvider
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java b/kernel/authority/provider/database/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java
similarity index 92%
rename from kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java
rename to kernel/authority/provider/database/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java
index 13a1ff9..c306d81 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java
+++ b/kernel/authority/provider/database/src/test/java/org/apache/shardingsphere/authority/provider/database/DatabasePermittedAuthorityRegistryProviderTest.java
@@ -25,6 +25,7 @@
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
@@ -43,7 +44,7 @@
AuthorityRegistry actual = provider.build(Collections.singletonList(new ShardingSphereUser("user1", "", "127.0.0.2")));
Optional<ShardingSpherePrivileges> privileges = actual.findPrivileges(new Grantee("user1", "127.0.0.2"));
assertTrue(privileges.isPresent());
- assertTrue(privileges.get().hasPrivileges("test"));
- assertTrue(privileges.get().hasPrivileges("db_dal_admin"));
+ Assertions.assertTrue(privileges.get().hasPrivileges("test"));
+ Assertions.assertTrue(privileges.get().hasPrivileges("db_dal_admin"));
}
}
diff --git a/kernel/authority/provider/pom.xml b/kernel/authority/provider/pom.xml
new file mode 100644
index 0000000..6f33a42
--- /dev/null
+++ b/kernel/authority/provider/pom.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority</artifactId>
+ <version>5.4.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-authority-provider</artifactId>
+ <packaging>pom</packaging>
+ <name>${project.artifactId}</name>
+
+ <modules>
+ <module>simple</module>
+ <module>database</module>
+ </modules>
+</project>
diff --git a/kernel/authority/provider/simple/pom.xml b/kernel/authority/provider/simple/pom.xml
new file mode 100644
index 0000000..a1fc218
--- /dev/null
+++ b/kernel/authority/provider/simple/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-provider</artifactId>
+ <version>5.4.2-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-authority-simple</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-authority-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
similarity index 94%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
rename to kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
index 4714cbf..87906df 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
+++ b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/AllPermittedAuthorityRegistryProvider.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.authority.provider.simple;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.registry.AllPermittedAuthorityRegistry;
+import org.apache.shardingsphere.authority.provider.simple.registry.AllPermittedAuthorityRegistry;
import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivileges.java
similarity index 94%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java
rename to kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivileges.java
index 78f8d4b..eb7915b 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivileges.java
+++ b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivileges.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.provider.simple.model.privilege;
+package org.apache.shardingsphere.authority.provider.simple.privilege;
import org.apache.shardingsphere.authority.model.AccessSubject;
import org.apache.shardingsphere.authority.model.PrivilegeType;
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/AllPermittedAuthorityRegistry.java b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/registry/AllPermittedAuthorityRegistry.java
similarity index 89%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/AllPermittedAuthorityRegistry.java
rename to kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/registry/AllPermittedAuthorityRegistry.java
index 07e2019..544985a 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/registry/AllPermittedAuthorityRegistry.java
+++ b/kernel/authority/provider/simple/src/main/java/org/apache/shardingsphere/authority/provider/simple/registry/AllPermittedAuthorityRegistry.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.registry;
+package org.apache.shardingsphere.authority.provider.simple.registry;
import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.provider.simple.model.privilege.AllPermittedPrivileges;
+import org.apache.shardingsphere.authority.provider.simple.privilege.AllPermittedPrivileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import java.util.Optional;
diff --git a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider b/kernel/authority/provider/simple/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
similarity index 89%
copy from kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
copy to kernel/authority/provider/simple/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
index b25b1f2..f0cd5e4 100644
--- a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
+++ b/kernel/authority/provider/simple/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
@@ -16,4 +16,3 @@
#
org.apache.shardingsphere.authority.provider.simple.AllPermittedAuthorityRegistryProvider
-org.apache.shardingsphere.authority.provider.database.DatabasePermittedAuthorityRegistryProvider
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesTest.java b/kernel/authority/provider/simple/src/test/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivilegesTest.java
similarity index 81%
rename from kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesTest.java
rename to kernel/authority/provider/simple/src/test/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivilegesTest.java
index d506369..552cc65 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/simple/model/privilege/AllPermittedPrivilegesTest.java
+++ b/kernel/authority/provider/simple/src/test/java/org/apache/shardingsphere/authority/provider/simple/privilege/AllPermittedPrivilegesTest.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.provider.simple.model.privilege;
+package org.apache.shardingsphere.authority.provider.simple.privilege;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.provider.database.model.subject.DatabaseAccessSubject;
import org.junit.jupiter.api.Test;
import java.util.Collections;
@@ -32,6 +31,5 @@
ShardingSpherePrivileges actual = new AllPermittedPrivileges();
assertTrue(actual.hasPrivileges("testSchema"));
assertTrue(actual.hasPrivileges(Collections.emptyList()));
- assertTrue(actual.hasPrivileges(new DatabaseAccessSubject("testSchema"), Collections.emptyList()));
}
}
diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java
index 2267879..1cc8d31 100644
--- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java
+++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowDatabasesExecutorTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
-import org.apache.shardingsphere.authority.provider.simple.model.privilege.AllPermittedPrivileges;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -57,6 +57,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -190,7 +192,16 @@
private AuthorityRule mockAuthorityRule() {
AuthorityRule result = mock(AuthorityRule.class);
- when(result.findPrivileges(new Grantee("root", ""))).thenReturn(Optional.of(new AllPermittedPrivileges()));
+ ShardingSpherePrivileges privileges = mockPrivileges();
+ when(result.findPrivileges(new Grantee("root", ""))).thenReturn(Optional.of(privileges));
+ return result;
+ }
+
+ private ShardingSpherePrivileges mockPrivileges() {
+ ShardingSpherePrivileges result = mock(ShardingSpherePrivileges.class);
+ when(result.hasPrivileges(anyString())).thenReturn(true);
+ when(result.hasPrivileges(anyCollection())).thenReturn(true);
+ when(result.hasPrivileges(anyCollection())).thenReturn(true);
return result;
}
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
index 8d46506..328ad0b 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java
@@ -23,7 +23,7 @@
import io.netty.channel.ChannelPipeline;
import io.netty.util.Attribute;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.authority.provider.simple.model.privilege.AllPermittedPrivileges;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
@@ -81,6 +81,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doReturn;
@@ -170,7 +172,8 @@
AuthorityRule rule = mock(AuthorityRule.class);
ShardingSphereUser user = new ShardingSphereUser("root", "", "127.0.0.1");
when(rule.findUser(user.getGrantee())).thenReturn(Optional.of(user));
- when(rule.findPrivileges(user.getGrantee())).thenReturn(Optional.of(new AllPermittedPrivileges()));
+ ShardingSpherePrivileges privileges = mockPrivileges();
+ when(rule.findPrivileges(user.getGrantee())).thenReturn(Optional.of(privileges));
when(rule.getAuthenticatorType(any())).thenReturn("");
ContextManager contextManager = mockContextManager(rule);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
@@ -183,6 +186,14 @@
Plugins.getMemberAccessor().set(MySQLAuthenticationEngine.class.getDeclaredField("currentAuthResult"), authenticationEngine, AuthenticationResultBuilder.continued("root", "", "foo_db"));
}
+ private ShardingSpherePrivileges mockPrivileges() {
+ ShardingSpherePrivileges result = mock(ShardingSpherePrivileges.class);
+ when(result.hasPrivileges(anyString())).thenReturn(true);
+ when(result.hasPrivileges(anyCollection())).thenReturn(true);
+ when(result.hasPrivileges(anyCollection())).thenReturn(true);
+ return result;
+ }
+
@Test
void assertAuthenticateFailedWithAbsentUser() {
setConnectionPhase(MySQLConnectionPhase.AUTH_PHASE_FAST_PATH);