This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 f09f0e62de0 Rename PrivilegeProvider (#29615)
f09f0e62de0 is described below
commit f09f0e62de0d42b5feab595fe3e0966936751a20
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 1 16:33:13 2024 +0800
Rename PrivilegeProvider (#29615)
* Remove AuthorityRegistry
* Rename PrivilegeProvider
* Refactor PrivilegeProviderFixture
---
.../config/AuthorityRuleConfiguration.java | 2 +-
.../authority/model/AuthorityRegistry.java | 43 ----------------------
...egistryProvider.java => PrivilegeProvider.java} | 14 ++++---
.../authority/rule/AuthorityRule.java | 12 +++---
.../NewYamlAuthorityRuleConfigurationSwapper.java | 4 +-
.../YamlAuthorityRuleConfigurationSwapper.java | 4 +-
...rFixture.java => PrivilegeProviderFixture.java} | 21 +++++++----
.../fixture/ShardingSpherePrivilegesFixture.java | 28 --------------
...faultAuthorityRuleConfigurationBuilderTest.java | 2 +-
.../YamlAuthorityRuleConfigurationSwapperTest.java | 4 +-
...shardingsphere.authority.spi.PrivilegeProvider} | 2 +-
.../distsql/handler/ShowAuthorityRuleExecutor.java | 2 +-
...ava => DatabasePermittedPrivilegeProvider.java} | 13 +++----
...shardingsphere.authority.spi.PrivilegeProvider} | 2 +-
...=> DatabasePermittedPrivilegeProviderTest.java} | 19 ++++------
...der.java => AllPermittedPrivilegeProvider.java} | 14 ++++---
...shardingsphere.authority.spi.PrivilegeProvider} | 2 +-
17 files changed, 61 insertions(+), 127 deletions(-)
diff --git
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/config/AuthorityRuleConfiguration.java
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/config/AuthorityRuleConfiguration.java
index 8b7224d549e..d640b5d51c3 100644
---
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/config/AuthorityRuleConfiguration.java
+++
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/config/AuthorityRuleConfiguration.java
@@ -35,7 +35,7 @@ public final class AuthorityRuleConfiguration implements
GlobalRuleConfiguration
private final Collection<ShardingSphereUser> users;
- private final AlgorithmConfiguration authorityProvider;
+ private final AlgorithmConfiguration privilegeProvider;
private final Map<String, AlgorithmConfiguration> authenticators;
diff --git
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
deleted file mode 100644
index f517a423ca6..00000000000
---
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/model/AuthorityRegistry.java
+++ /dev/null
@@ -1,43 +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.model;
-
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Authority registry.
- */
-@RequiredArgsConstructor
-public final class AuthorityRegistry {
-
- private final Map<Grantee, ShardingSpherePrivileges> granteePrivileges;
-
- /**
- * Find privileges.
- *
- * @param grantee grantee
- * @return found privileges
- */
- public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee
grantee) {
- return granteePrivileges.keySet().stream().filter(each ->
each.accept(grantee)).findFirst().map(granteePrivileges::get);
- }
-}
diff --git
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityRegistryProvider.java
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeProvider.java
similarity index 74%
rename from
kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityRegistryProvider.java
rename to
kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeProvider.java
index 2e1e916814f..c4ff64ce9e5 100644
---
a/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityRegistryProvider.java
+++
b/kernel/authority/api/src/main/java/org/apache/shardingsphere/authority/spi/PrivilegeProvider.java
@@ -17,24 +17,26 @@
package org.apache.shardingsphere.authority.spi;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import java.util.Collection;
+import java.util.Map;
/**
- * Authority registry provider.
+ * Privilege provider.
*/
@SingletonSPI
-public interface AuthorityRegistryProvider extends TypedSPI {
+public interface PrivilegeProvider extends TypedSPI {
/**
- * Build authority registry.
+ * Build grantee and privileges map.
*
* @param users users
- * @return built authority registry
+ * @return grantee and privileges map
*/
- AuthorityRegistry build(Collection<ShardingSphereUser> users);
+ Map<Grantee, ShardingSpherePrivileges>
build(Collection<ShardingSphereUser> users);
}
diff --git
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index 56e0ddd1747..a0216156250 100644
---
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -19,14 +19,14 @@ package org.apache.shardingsphere.authority.rule;
import lombok.Getter;
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
+import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import java.util.Map;
import java.util.Optional;
/**
@@ -37,12 +37,12 @@ public final class AuthorityRule implements GlobalRule {
@Getter
private final AuthorityRuleConfiguration configuration;
- private final AuthorityRegistry authorityRegistry;
+ private final Map<Grantee, ShardingSpherePrivileges> privileges;
public AuthorityRule(final AuthorityRuleConfiguration ruleConfig) {
configuration = ruleConfig;
- AuthorityRegistryProvider provider =
TypedSPILoader.getService(AuthorityRegistryProvider.class,
ruleConfig.getAuthorityProvider().getType(),
ruleConfig.getAuthorityProvider().getProps());
- authorityRegistry = provider.build(ruleConfig.getUsers());
+ PrivilegeProvider provider =
TypedSPILoader.getService(PrivilegeProvider.class,
ruleConfig.getPrivilegeProvider().getType(),
ruleConfig.getPrivilegeProvider().getProps());
+ privileges = provider.build(ruleConfig.getUsers());
}
/**
@@ -74,6 +74,6 @@ public final class AuthorityRule implements GlobalRule {
* @return found privileges
*/
public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee
grantee) {
- return authorityRegistry.findPrivileges(grantee);
+ return privileges.keySet().stream().filter(each ->
each.accept(grantee)).findFirst().map(privileges::get);
}
}
diff --git
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
index fd32eee62d1..7915ef5531a 100644
---
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
+++
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
@@ -53,7 +53,7 @@ public final class NewYamlAuthorityRuleConfigurationSwapper
implements NewYamlGl
private YamlAuthorityRuleConfiguration swapToYamlConfiguration(final
AuthorityRuleConfiguration data) {
YamlAuthorityRuleConfiguration result = new
YamlAuthorityRuleConfiguration();
-
result.setPrivilege(algorithmSwapper.swapToYamlConfiguration(data.getAuthorityProvider()));
+
result.setPrivilege(algorithmSwapper.swapToYamlConfiguration(data.getPrivilegeProvider()));
result.setUsers(data.getUsers().stream().map(userSwapper::swapToYamlConfiguration).collect(Collectors.toList()));
result.setDefaultAuthenticator(data.getDefaultAuthenticator());
data.getAuthenticators().forEach((key, value) ->
result.getAuthenticators().put(key,
algorithmSwapper.swapToYamlConfiguration(value)));
@@ -76,7 +76,7 @@ public final class NewYamlAuthorityRuleConfigurationSwapper
implements NewYamlGl
Collection<ShardingSphereUser> users =
yamlConfig.getUsers().stream().map(userSwapper::swapToObject).collect(Collectors.toList());
AlgorithmConfiguration provider =
algorithmSwapper.swapToObject(yamlConfig.getPrivilege());
if (null == provider) {
- provider = new
DefaultAuthorityRuleConfigurationBuilder().build().getAuthorityProvider();
+ provider = new
DefaultAuthorityRuleConfigurationBuilder().build().getPrivilegeProvider();
}
Map<String, AlgorithmConfiguration> authenticators =
yamlConfig.getAuthenticators().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry ->
algorithmSwapper.swapToObject(entry.getValue())));
diff --git
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapper.java
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapper.java
index 828ffe4d0cd..be86009062c 100644
---
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapper.java
+++
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapper.java
@@ -43,7 +43,7 @@ public final class YamlAuthorityRuleConfigurationSwapper
implements YamlRuleConf
@Override
public YamlAuthorityRuleConfiguration swapToYamlConfiguration(final
AuthorityRuleConfiguration data) {
YamlAuthorityRuleConfiguration result = new
YamlAuthorityRuleConfiguration();
-
result.setPrivilege(algorithmSwapper.swapToYamlConfiguration(data.getAuthorityProvider()));
+
result.setPrivilege(algorithmSwapper.swapToYamlConfiguration(data.getPrivilegeProvider()));
result.setUsers(data.getUsers().stream().map(userSwapper::swapToYamlConfiguration).collect(Collectors.toList()));
result.setDefaultAuthenticator(data.getDefaultAuthenticator());
data.getAuthenticators().forEach((key, value) ->
result.getAuthenticators().put(key,
algorithmSwapper.swapToYamlConfiguration(value)));
@@ -55,7 +55,7 @@ public final class YamlAuthorityRuleConfigurationSwapper
implements YamlRuleConf
Collection<ShardingSphereUser> users =
yamlConfig.getUsers().stream().map(userSwapper::swapToObject).collect(Collectors.toList());
AlgorithmConfiguration provider =
algorithmSwapper.swapToObject(yamlConfig.getPrivilege());
if (null == provider) {
- provider = new
DefaultAuthorityRuleConfigurationBuilder().build().getAuthorityProvider();
+ provider = new
DefaultAuthorityRuleConfigurationBuilder().build().getPrivilegeProvider();
}
Map<String, AlgorithmConfiguration> authenticators =
yamlConfig.getAuthenticators().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry ->
algorithmSwapper.swapToObject(entry.getValue())));
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
similarity index 59%
rename from
kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
rename to
kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
index 7bd3e1e9eec..65c2799b49e 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/AuthorityRegistryProviderFixture.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
@@ -17,23 +17,30 @@
package org.apache.shardingsphere.authority.fixture;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
-import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
+import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import java.util.Collection;
-import java.util.Optional;
+import java.util.Map;
+import java.util.stream.Collectors;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class AuthorityRegistryProviderFixture implements
AuthorityRegistryProvider {
+public final class PrivilegeProviderFixture implements PrivilegeProvider {
@Override
- public AuthorityRegistry build(final Collection<ShardingSphereUser> users)
{
- AuthorityRegistry result = mock(AuthorityRegistry.class);
- when(result.findPrivileges(any())).thenReturn(Optional.of(new
ShardingSpherePrivilegesFixture()));
+ public Map<Grantee, ShardingSpherePrivileges> build(final
Collection<ShardingSphereUser> users) {
+ ShardingSpherePrivileges privileges = mockPrivileges();
+ return
users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee, each ->
privileges));
+ }
+
+ private static ShardingSpherePrivileges mockPrivileges() {
+ ShardingSpherePrivileges result = mock(ShardingSpherePrivileges.class);
+ when(result.hasPrivileges(any())).thenReturn(true);
return result;
}
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
deleted file mode 100644
index dc3e94528fe..00000000000
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/ShardingSpherePrivilegesFixture.java
+++ /dev/null
@@ -1,28 +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.fixture;
-
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-
-public final class ShardingSpherePrivilegesFixture implements
ShardingSpherePrivileges {
-
- @Override
- public boolean hasPrivileges(final String database) {
- return true;
- }
-}
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
index 4b951f800fe..74774d25ab8 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
@@ -28,7 +28,7 @@ class DefaultAuthorityRuleConfigurationBuilderTest {
@Test
void assertBuild() {
AuthorityRuleConfiguration actual = new
DefaultAuthorityRuleConfigurationBuilder().build();
- assertThat(actual.getAuthorityProvider().getType(),
is("ALL_PERMITTED"));
+ assertThat(actual.getPrivilegeProvider().getType(),
is("ALL_PERMITTED"));
assertThat(actual.getUsers().size(), is(1));
}
}
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
index 008f5a887e6..d6ec7208fc7 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
@@ -53,7 +53,7 @@ class YamlAuthorityRuleConfigurationSwapperTest {
authorityRuleConfig.setPrivilege(yamlAlgorithmConfig);
AuthorityRuleConfiguration actual =
swapper.swapToObject(authorityRuleConfig);
assertThat(actual.getUsers().size(), is(1));
- assertNotNull(actual.getAuthorityProvider());
+ assertNotNull(actual.getPrivilegeProvider());
}
@Test
@@ -62,7 +62,7 @@ class YamlAuthorityRuleConfigurationSwapperTest {
authorityRuleConfig.setUsers(Collections.singletonList(getYamlUser()));
AuthorityRuleConfiguration actual =
swapper.swapToObject(authorityRuleConfig);
assertThat(actual.getUsers().size(), is(1));
- assertThat(actual.getAuthorityProvider().getType(),
is("ALL_PERMITTED"));
+ assertThat(actual.getPrivilegeProvider().getType(),
is("ALL_PERMITTED"));
}
private YamlUserConfiguration getYamlUser() {
diff --git
a/kernel/authority/core/src/test/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.PrivilegeProvider
similarity index 91%
rename from
kernel/authority/core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
rename to
kernel/authority/core/src/test/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeProvider
index 121e823a7dc..e2dec81f2fc 100644
---
a/kernel/authority/core/src/test/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.PrivilegeProvider
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.fixture.AuthorityRegistryProviderFixture
+org.apache.shardingsphere.authority.fixture.PrivilegeProviderFixture
diff --git
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
index 884da140b7a..652f71ab30f 100644
---
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
+++
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
@@ -39,7 +39,7 @@ public final class ShowAuthorityRuleExecutor implements
MetaDataRequiredQueryabl
AuthorityRule rule =
metaData.getGlobalRuleMetaData().getSingleRule(AuthorityRule.class);
AuthorityRuleConfiguration ruleConfig = rule.getConfiguration();
return Collections.singleton(new
LocalDataQueryResultRow(ruleConfig.getUsers().stream().map(each ->
each.getGrantee().toString()).collect(Collectors.joining("; ")),
- ruleConfig.getAuthorityProvider().getType(),
ruleConfig.getAuthorityProvider().getProps().isEmpty() ? "" :
ruleConfig.getAuthorityProvider().getProps()));
+ ruleConfig.getPrivilegeProvider().getType(),
ruleConfig.getPrivilegeProvider().getProps().isEmpty() ? "" :
ruleConfig.getPrivilegeProvider().getProps()));
}
@Override
diff --git
a/kernel/authority/provider/database/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/DatabasePermittedPrivilegeProvider.java
similarity index 89%
rename from
kernel/authority/provider/database/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/DatabasePermittedPrivilegeProvider.java
index 082610fdf1d..14c3f0a651e 100644
---
a/kernel/authority/provider/database/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/DatabasePermittedPrivilegeProvider.java
@@ -18,10 +18,9 @@
package org.apache.shardingsphere.authority.provider.database;
import com.google.common.base.Preconditions;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import
org.apache.shardingsphere.authority.provider.database.privilege.DatabasePermittedPrivileges;
-import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
+import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -36,9 +35,9 @@ import java.util.Properties;
import java.util.stream.Collectors;
/**
- * Database permitted authority registry provider.
+ * Database permitted privilege provider.
*/
-public final class DatabasePermittedAuthorityRegistryProvider implements
AuthorityRegistryProvider {
+public final class DatabasePermittedPrivilegeProvider implements
PrivilegeProvider {
private static final String USER_DATABASE_MAPPINGS_KEY =
"user-database-mappings";
@@ -46,7 +45,7 @@ public final class DatabasePermittedAuthorityRegistryProvider
implements Authori
@Override
public void init(final Properties props) {
- userDatabaseMappings =
props.getProperty(DatabasePermittedAuthorityRegistryProvider.USER_DATABASE_MAPPINGS_KEY,
"");
+ userDatabaseMappings =
props.getProperty(DatabasePermittedPrivilegeProvider.USER_DATABASE_MAPPINGS_KEY,
"");
checkUserDatabaseMappings();
}
@@ -57,8 +56,8 @@ public final class DatabasePermittedAuthorityRegistryProvider
implements Authori
}
@Override
- public AuthorityRegistry build(final Collection<ShardingSphereUser> users)
{
- return new AuthorityRegistry(buildPrivileges(users,
convertUserDatabases()));
+ public Map<Grantee, ShardingSpherePrivileges> build(final
Collection<ShardingSphereUser> users) {
+ return buildPrivileges(users, convertUserDatabases());
}
private Map<Grantee, ShardingSpherePrivileges> buildPrivileges(final
Collection<ShardingSphereUser> users, final Map<ShardingSphereUser,
Collection<String>> userDatabaseMappings) {
diff --git
a/kernel/authority/provider/database/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.PrivilegeProvider
similarity index 96%
rename from
kernel/authority/provider/database/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.PrivilegeProvider
index 1ac13edabdc..2f78f7d0838 100644
---
a/kernel/authority/provider/database/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.PrivilegeProvider
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.provider.database.DatabasePermittedAuthorityRegistryProvider
+org.apache.shardingsphere.authority.provider.database.DatabasePermittedPrivilegeProvider
diff --git
a/kernel/authority/provider/database/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/DatabasePermittedPrivilegeProviderTest.java
similarity index 65%
rename from
kernel/authority/provider/database/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/DatabasePermittedPrivilegeProviderTest.java
index 74e3369974a..c387b7dadb2 100644
---
a/kernel/authority/provider/database/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/DatabasePermittedPrivilegeProviderTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.authority.provider.database;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
+import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -29,21 +28,17 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
-import java.util.Optional;
+import java.util.Map;
import java.util.Properties;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class DatabasePermittedAuthorityRegistryProviderTest {
+class DatabasePermittedPrivilegeProviderTest {
@Test
void assertBuild() {
Properties props = PropertiesBuilder.build(new
Property("user-database-mappings", "root@localhost=test,
[email protected]=db_dal_admin, user1@=test, user1@=test1, user1@=*"));
- AuthorityRegistryProvider provider =
TypedSPILoader.getService(AuthorityRegistryProvider.class,
"DATABASE_PERMITTED", props);
- 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());
- Assertions.assertTrue(privileges.get().hasPrivileges("test"));
- Assertions.assertTrue(privileges.get().hasPrivileges("db_dal_admin"));
+ PrivilegeProvider provider =
TypedSPILoader.getService(PrivilegeProvider.class, "DATABASE_PERMITTED", props);
+ Map<Grantee, ShardingSpherePrivileges> actual =
provider.build(Collections.singletonList(new ShardingSphereUser("user1", "",
"127.0.0.2")));
+ Assertions.assertTrue(actual.get(new Grantee("user1",
"127.0.0.2")).hasPrivileges("test"));
+ Assertions.assertTrue(actual.get(new Grantee("user1",
"127.0.0.2")).hasPrivileges("db_dal_admin"));
}
}
diff --git
a/kernel/authority/provider/simple/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/AllPermittedPrivilegeProvider.java
similarity index 72%
rename from
kernel/authority/provider/simple/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/AllPermittedPrivilegeProvider.java
index a7e563401f7..91b7fe7d785 100644
---
a/kernel/authority/provider/simple/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/AllPermittedPrivilegeProvider.java
@@ -17,23 +17,25 @@
package org.apache.shardingsphere.authority.provider.simple;
-import org.apache.shardingsphere.authority.model.AuthorityRegistry;
+import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
import
org.apache.shardingsphere.authority.provider.simple.privilege.AllPermittedPrivileges;
-import org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider;
+import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import java.util.stream.Collectors;
/**
- * All permitted authority registry provider.
+ * All permitted privilege provider.
*/
-public final class AllPermittedAuthorityRegistryProvider implements
AuthorityRegistryProvider {
+public final class AllPermittedPrivilegeProvider implements PrivilegeProvider {
@Override
- public AuthorityRegistry build(final Collection<ShardingSphereUser> users)
{
- return new
AuthorityRegistry(users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee,
each -> new AllPermittedPrivileges())));
+ public Map<Grantee, ShardingSpherePrivileges> build(final
Collection<ShardingSphereUser> users) {
+ return
users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee, each ->
new AllPermittedPrivileges()));
}
@Override
diff --git
a/kernel/authority/provider/simple/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.PrivilegeProvider
similarity index 97%
rename from
kernel/authority/provider/simple/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.AuthorityRegistryProvider
rename to
kernel/authority/provider/simple/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeProvider
index f0cd5e49618..b630e1e3605 100644
---
a/kernel/authority/provider/simple/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.PrivilegeProvider
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.provider.simple.AllPermittedAuthorityRegistryProvider
+org.apache.shardingsphere.authority.provider.simple.AllPermittedPrivilegeProvider