You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/04/10 14:18:26 UTC
[shardingsphere] branch master updated: Add
AuthorityProvideAlgorithm.refresh() (#10031)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 1af075d Add AuthorityProvideAlgorithm.refresh() (#10031)
1af075d is described below
commit 1af075d64838057fd4830cda9617e56a03714735
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Apr 10 22:18:00 2021 +0800
Add AuthorityProvideAlgorithm.refresh() (#10031)
---
.../shardingsphere/authority/spi/AuthorityProvideAlgorithm.java | 8 ++++++++
.../provider/natived/NativeAuthorityProviderAlgorithm.java | 5 +++++
.../governance/context/authority/GovernanceAuthorityContext.java | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProvideAlgorithm.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProvideAlgorithm.java
index f5a404b..4ad62bc 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProvideAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-api/src/main/java/org/apache/shardingsphere/authority/spi/AuthorityProvideAlgorithm.java
@@ -39,6 +39,14 @@ public interface AuthorityProvideAlgorithm extends ShardingSphereAlgorithm {
* @param users users
*/
void init(Map<String, ShardingSphereMetaData> mataDataMap, Collection<ShardingSphereUser> users);
+
+ /**
+ * Refresh authority.
+ *
+ * @param mataDataMap mata data map
+ * @param users users
+ */
+ void refresh(Map<String, ShardingSphereMetaData> mataDataMap, Collection<ShardingSphereUser> users);
/**
* Find Privileges.
diff --git a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java
index 6544210..b9a6707 100644
--- a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/NativeAuthorityProviderAlgorithm.java
@@ -43,6 +43,11 @@ public final class NativeAuthorityProviderAlgorithm implements AuthorityProvideA
}
@Override
+ public void refresh(final Map<String, ShardingSphereMetaData> mataDataMap, final Collection<ShardingSphereUser> users) {
+ userPrivilegeMap.putAll(StoragePrivilegeBuilder.build(new LinkedList<>(mataDataMap.values()), users));
+ }
+
+ @Override
public Optional<ShardingSpherePrivileges> findPrivileges(final Grantee grantee) {
return userPrivilegeMap.keySet().stream().filter(each -> each.getGrantee().equals(grantee)).findFirst().map(userPrivilegeMap::get);
}
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 031fea4..2f949fd 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
@@ -53,7 +53,7 @@ public final class GovernanceAuthorityContext implements MetaDataAwareEventSubsc
Optional<AuthorityRule> authorityRule = metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof AuthorityRule).findAny().map(each -> (AuthorityRule) each);
Preconditions.checkState(authorityRule.isPresent());
AuthorityProvideAlgorithm provider = authorityRule.get().getProvider();
- provider.init(metaDataContexts.getMetaDataMap(), users);
+ provider.refresh(metaDataContexts.getMetaDataMap(), users);
AuthorityContext.getInstance().init(provider);
}
}