You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by co...@apache.org on 2024/11/21 21:52:58 UTC
(polaris) branch mcollado-authz-use-grantmanager created (now 5e93cd3a)
This is an automated email from the ASF dual-hosted git repository.
collado pushed a change to branch mcollado-authz-use-grantmanager
in repository https://gitbox.apache.org/repos/asf/polaris.git
at 5e93cd3a Update PolarisAuthorizerImpl to use PolarisGrantManager interface and add EntityCache based PolarisGrantManager impl
This branch includes the following new commits:
new 5e93cd3a Update PolarisAuthorizerImpl to use PolarisGrantManager interface and add EntityCache based PolarisGrantManager impl
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(polaris) 01/01: Update PolarisAuthorizerImpl to use PolarisGrantManager interface and add EntityCache based PolarisGrantManager impl
Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
collado pushed a commit to branch mcollado-authz-use-grantmanager
in repository https://gitbox.apache.org/repos/asf/polaris.git
commit 5e93cd3a6bca3c3fb255cd33c66110a4f17b80b1
Author: Michael Collado <co...@gmail.com>
AuthorDate: Thu Nov 21 13:52:44 2024 -0800
Update PolarisAuthorizerImpl to use PolarisGrantManager interface and add EntityCache based PolarisGrantManager impl
---
.../polaris/core/auth/PolarisAuthorizerImpl.java | 28 +-
.../polaris/core/auth/PolarisGrantManager.java | 7 +
.../core/persistence/MetaStoreManagerFactory.java | 16 +-
.../core/persistence/PolarisEntityManager.java | 7 +-
.../persistence/cache/EntityCacheGrantManager.java | 185 +++++++++
.../persistence/cache/RealmEntityCacheFactory.java | 27 ++
.../storage/cache/EntityCacheGrantManagerTest.java | 435 +++++++++++++++++++++
.../apache/polaris/service/PolarisApplication.java | 16 +-
.../service/config/RealmEntityManagerFactory.java | 2 +
.../service/admin/PolarisAuthzTestBase.java | 37 +-
.../service/catalog/BasePolarisCatalogTest.java | 12 +-
.../catalog/BasePolarisCatalogViewTest.java | 10 +-
12 files changed, 750 insertions(+), 32 deletions(-)
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
index 3424f3bd..3125d8a5 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
@@ -95,6 +95,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.iceberg.exceptions.ForbiddenException;
+import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.PolarisConfiguration;
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.context.CallContext;
@@ -459,9 +460,12 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
}
private final PolarisConfigurationStore featureConfig;
+ private final PolarisGrantManager.Factory grantManagerFactory;
- public PolarisAuthorizerImpl(PolarisConfigurationStore featureConfig) {
+ public PolarisAuthorizerImpl(
+ PolarisConfigurationStore featureConfig, PolarisGrantManager.Factory grantManagerFactory) {
this.featureConfig = featureConfig;
+ this.grantManagerFactory = grantManagerFactory;
}
/**
@@ -602,15 +606,27 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
Set<Long> activatedGranteeIds,
PolarisPrivilege desiredPrivilege,
PolarisResolvedPathWrapper resolvedPath) {
+ PolarisGrantManager grantManager =
+ grantManagerFactory.getGrantManagerForRealm(
+ CallContext.getCurrentContext().getRealmContext());
+ PolarisCallContext callContext = CallContext.getCurrentContext().getPolarisCallContext();
// Iterate starting at the parent, since the most common case should be to manage grants as
// high up in the resource hierarchy as possible, so we expect earlier termination.
for (ResolvedPolarisEntity resolvedSecurableEntity : resolvedPath.getResolvedFullPath()) {
- Preconditions.checkState(
- resolvedSecurableEntity.getGrantRecordsAsSecurable() != null,
- "Got null grantRecordsAsSecurable for resolvedSecurableEntity %s",
- resolvedSecurableEntity);
- for (PolarisGrantRecord grantRecord : resolvedSecurableEntity.getGrantRecordsAsSecurable()) {
+ PolarisGrantManager.LoadGrantsResult grantsResult =
+ grantManager.loadGrantsOnSecurable(
+ callContext,
+ resolvedSecurableEntity.getEntity().getCatalogId(),
+ resolvedSecurableEntity.getEntity().getId());
+ callContext
+ .getDiagServices()
+ .check(
+ grantsResult.isSuccess(),
+ "no_grants_for_securable",
+ "unable to load grants for securable %s",
+ resolvedSecurableEntity.getEntity().getId());
+ for (PolarisGrantRecord grantRecord : grantsResult.getGrantRecords()) {
if (matchesOrIsSubsumedBy(
desiredPrivilege, PolarisPrivilege.fromCode(grantRecord.getPrivilegeCode()))) {
// Found a potential candidate for satisfying our authz goal.
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java
index 0bc2870f..25384593 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
import org.apache.polaris.core.entity.PolarisGrantRecord;
@@ -35,6 +36,12 @@ import org.jetbrains.annotations.Nullable;
/** Manage grants for Polaris entities. */
public interface PolarisGrantManager {
+
+ @FunctionalInterface
+ interface Factory {
+ PolarisGrantManager getGrantManagerForRealm(RealmContext realm);
+ }
+
/**
* Grant usage on a role to a grantee, for example granting usage on a catalog role to a principal
* role or granting a principal role to a principal.
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java
index 821d139a..e8ed11d6 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java
@@ -23,6 +23,7 @@ import io.dropwizard.jackson.Discoverable;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.polaris.core.auth.PolarisGrantManager;
import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.monitor.PolarisMetricRegistry;
@@ -34,7 +35,7 @@ import org.apache.polaris.core.storage.cache.StorageCredentialCache;
* configuration
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
-public interface MetaStoreManagerFactory extends Discoverable {
+public interface MetaStoreManagerFactory extends Discoverable, PolarisGrantManager.Factory {
PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmContext realmContext);
@@ -50,4 +51,17 @@ public interface MetaStoreManagerFactory extends Discoverable {
/** Purge all metadata for the realms provided */
void purgeRealms(List<String> realms);
+
+ /**
+ * Default {@link PolarisGrantManager} factory that returns the {@link PolarisMetaStoreManager} as
+ * the grant manager.
+ *
+ * @param realm the current realm
+ * @return the {@link PolarisMetaStoreManager} returned by {@link
+ * #getOrCreateMetaStoreManager(RealmContext)}
+ */
+ @Override
+ default PolarisGrantManager getGrantManagerForRealm(RealmContext realm) {
+ return getOrCreateMetaStoreManager(realm);
+ }
}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisEntityManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisEntityManager.java
index 4709ec89..c13d60ed 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisEntityManager.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisEntityManager.java
@@ -51,11 +51,14 @@ public class PolarisEntityManager {
/**
* @param metaStoreManager the metastore manager for the current realm
* @param credentialCache the storage credential cache for the current realm
+ * @param entityCache
*/
public PolarisEntityManager(
- PolarisMetaStoreManager metaStoreManager, StorageCredentialCache credentialCache) {
+ PolarisMetaStoreManager metaStoreManager,
+ EntityCache entityCache,
+ StorageCredentialCache credentialCache) {
this.metaStoreManager = metaStoreManager;
- this.entityCache = new EntityCache(metaStoreManager);
+ this.entityCache = entityCache;
this.credentialCache = credentialCache;
}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCacheGrantManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCacheGrantManager.java
new file mode 100644
index 00000000..7c723a43
--- /dev/null
+++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCacheGrantManager.java
@@ -0,0 +1,185 @@
+/*
+ * 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.polaris.core.persistence.cache;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.auth.PolarisGrantManager;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntityCore;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+import org.apache.polaris.core.persistence.BaseResult;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * PolarisGrantManger implementation that uses an EntityCache to retrieve entities and is backed by
+ * a delegate grant manager for persisting grant changes. This allows consumers to reuse cache
+ * entities without necessarily being aware of the {@link EntityCache} or the {@link
+ * EntityCacheEntry} specifics.
+ */
+public class EntityCacheGrantManager implements PolarisGrantManager {
+ private final PolarisGrantManager delegateGrantManager;
+ private final EntityCache entityCache;
+
+ public static final class EntityCacheGrantManagerFactory implements PolarisGrantManager.Factory {
+ private final PolarisGrantManager.Factory delegateGrantManagerFactory;
+ private final RealmEntityCacheFactory realmEntityCacheFactory;
+
+ public EntityCacheGrantManagerFactory(
+ Factory delegateGrantManagerFactory, RealmEntityCacheFactory realmEntityCacheFactory) {
+ this.delegateGrantManagerFactory = delegateGrantManagerFactory;
+ this.realmEntityCacheFactory = realmEntityCacheFactory;
+ }
+
+ @Override
+ public PolarisGrantManager getGrantManagerForRealm(RealmContext realm) {
+ return new EntityCacheGrantManager(
+ delegateGrantManagerFactory.getGrantManagerForRealm(realm),
+ realmEntityCacheFactory.getOrCreateEntityCache(realm));
+ }
+ }
+
+ public EntityCacheGrantManager(
+ PolarisGrantManager delegateGrantManager, EntityCache entityCache) {
+ this.delegateGrantManager = delegateGrantManager;
+ this.entityCache = entityCache;
+ }
+
+ @Override
+ public @NotNull PrivilegeResult grantUsageOnRoleToGrantee(
+ @NotNull PolarisCallContext callCtx,
+ @Nullable PolarisEntityCore catalog,
+ @NotNull PolarisEntityCore role,
+ @NotNull PolarisEntityCore grantee) {
+ try {
+ return delegateGrantManager.grantUsageOnRoleToGrantee(callCtx, catalog, role, grantee);
+ } finally {
+ invalidate(role);
+ invalidate(grantee);
+ }
+ }
+
+ private void invalidate(@NotNull PolarisEntityCore role) {
+ EntityCacheEntry roleEntity = entityCache.getEntityById(role.getId());
+ if (roleEntity != null) {
+ entityCache.removeCacheEntry(roleEntity);
+ }
+ }
+
+ @Override
+ public @NotNull PrivilegeResult revokeUsageOnRoleFromGrantee(
+ @NotNull PolarisCallContext callCtx,
+ @Nullable PolarisEntityCore catalog,
+ @NotNull PolarisEntityCore role,
+ @NotNull PolarisEntityCore grantee) {
+ try {
+ return delegateGrantManager.revokeUsageOnRoleFromGrantee(callCtx, catalog, role, grantee);
+ } finally {
+ invalidate(role);
+ invalidate(grantee);
+ }
+ }
+
+ @Override
+ public @NotNull PrivilegeResult grantPrivilegeOnSecurableToRole(
+ @NotNull PolarisCallContext callCtx,
+ @NotNull PolarisEntityCore grantee,
+ @Nullable List<PolarisEntityCore> catalogPath,
+ @NotNull PolarisEntityCore securable,
+ @NotNull PolarisPrivilege privilege) {
+ try {
+ return delegateGrantManager.grantPrivilegeOnSecurableToRole(
+ callCtx, grantee, catalogPath, securable, privilege);
+ } finally {
+ invalidate(securable);
+ invalidate(grantee);
+ }
+ }
+
+ @Override
+ public @NotNull PrivilegeResult revokePrivilegeOnSecurableFromRole(
+ @NotNull PolarisCallContext callCtx,
+ @NotNull PolarisEntityCore grantee,
+ @Nullable List<PolarisEntityCore> catalogPath,
+ @NotNull PolarisEntityCore securable,
+ @NotNull PolarisPrivilege privilege) {
+ try {
+ return delegateGrantManager.revokePrivilegeOnSecurableFromRole(
+ callCtx, grantee, catalogPath, securable, privilege);
+ } finally {
+ invalidate(securable);
+ invalidate(grantee);
+ }
+ }
+
+ @Override
+ public @NotNull LoadGrantsResult loadGrantsOnSecurable(
+ @NotNull PolarisCallContext callCtx, long securableCatalogId, long securableId) {
+ EntityCacheLookupResult lookupResult =
+ entityCache.getOrLoadEntityById(callCtx, securableCatalogId, securableId);
+ if (lookupResult == null || lookupResult.getCacheEntry() == null) {
+ return new LoadGrantsResult(BaseResult.ReturnStatus.GRANT_NOT_FOUND, null);
+ }
+ List<PolarisBaseEntity> granteeList =
+ lookupResult.getCacheEntry().getGrantRecordsAsSecurable().stream()
+ .map(
+ gr ->
+ entityCache.getOrLoadEntityById(
+ callCtx, gr.getGranteeCatalogId(), gr.getGranteeId()))
+ .filter(lr -> lr != null && lr.getCacheEntry() != null)
+ .map(lr -> lr.getCacheEntry().getEntity())
+ .collect(Collectors.toList());
+ return new LoadGrantsResult(
+ lookupResult.getCacheEntry().getEntity().getGrantRecordsVersion(),
+ lookupResult.getCacheEntry().getGrantRecordsAsSecurable(),
+ granteeList);
+ }
+
+ @Override
+ public @NotNull LoadGrantsResult loadGrantsToGrantee(
+ PolarisCallContext callCtx, long granteeCatalogId, long granteeId) {
+ EntityCacheLookupResult lookupResult =
+ entityCache.getOrLoadEntityById(callCtx, granteeCatalogId, granteeId);
+ if (lookupResult == null || lookupResult.getCacheEntry() == null) {
+ return new LoadGrantsResult(BaseResult.ReturnStatus.GRANT_NOT_FOUND, null);
+ }
+ List<PolarisBaseEntity> granteeList =
+ lookupResult.getCacheEntry().getGrantRecordsAsGrantee().stream()
+ .map(
+ gr ->
+ entityCache.getOrLoadEntityById(
+ callCtx, gr.getSecurableCatalogId(), gr.getSecurableId()))
+ .takeWhile(
+ lr -> {
+ if (lr == null || lr.getCacheEntry() == null) {
+ throw new IllegalStateException("Grantee not found");
+ }
+ return true;
+ })
+ .map(lr -> lr.getCacheEntry().getEntity())
+ .collect(Collectors.toList());
+ return new LoadGrantsResult(
+ lookupResult.getCacheEntry().getEntity().getGrantRecordsVersion(),
+ lookupResult.getCacheEntry().getGrantRecordsAsGrantee(),
+ granteeList);
+ }
+}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/RealmEntityCacheFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/RealmEntityCacheFactory.java
new file mode 100644
index 00000000..f44e1663
--- /dev/null
+++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/RealmEntityCacheFactory.java
@@ -0,0 +1,27 @@
+/*
+ * 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.polaris.core.persistence.cache;
+
+import org.apache.polaris.core.context.RealmContext;
+
+/** Factory interface for finding the {@link EntityCache} for a realm */
+@FunctionalInterface
+public interface RealmEntityCacheFactory {
+ EntityCache getOrCreateEntityCache(RealmContext realm);
+}
diff --git a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/EntityCacheGrantManagerTest.java b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/EntityCacheGrantManagerTest.java
new file mode 100644
index 00000000..e8a232c8
--- /dev/null
+++ b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/EntityCacheGrantManagerTest.java
@@ -0,0 +1,435 @@
+/*
+ * 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.polaris.core.storage.cache;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
+import org.apache.polaris.core.auth.PolarisGrantManager;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.entity.CatalogEntity;
+import org.apache.polaris.core.entity.CatalogRoleEntity;
+import org.apache.polaris.core.entity.NamespaceEntity;
+import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityCore;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.entity.PolarisGrantRecord;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+import org.apache.polaris.core.entity.PrincipalEntity;
+import org.apache.polaris.core.entity.PrincipalRoleEntity;
+import org.apache.polaris.core.entity.TableLikeEntity;
+import org.apache.polaris.core.persistence.BaseResult;
+import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
+import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
+import org.apache.polaris.core.persistence.PolarisEntityManager;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.PolarisTreeMapMetaStoreSessionImpl;
+import org.apache.polaris.core.persistence.PolarisTreeMapStore;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.cache.EntityCacheGrantManager;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
+import org.apache.polaris.core.persistence.resolver.ResolverPath;
+import org.apache.polaris.core.persistence.resolver.ResolverStatus;
+import org.assertj.core.api.Assertions;
+import org.assertj.core.api.InstanceOfAssertFactories;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+public class EntityCacheGrantManagerTest {
+
+ public static final String NS_1 = "ns1";
+ public static final String NS_2 = "ns2";
+ public static final String TABLE_1 = "table1";
+ private MetaStoreManagerFactory metastoreManagerFactory;
+ private RealmContext realmContext;
+ private PolarisMetaStoreManager metaStoreManager;
+ private PolarisCallContext polarisCallContext;
+ private CatalogEntity catalog;
+ private PrincipalEntity principal;
+ private PrincipalRoleEntity principalRole1;
+ private PrincipalRoleEntity principalRole2;
+ private CatalogRoleEntity catalogRole1;
+ private CatalogRoleEntity catalogRole2;
+
+ @BeforeEach
+ public void setup() {
+ // Create a MetastoreManager
+ PolarisDefaultDiagServiceImpl diagServices = new PolarisDefaultDiagServiceImpl();
+ PolarisTreeMapStore treeMapStore = new PolarisTreeMapStore(diagServices);
+ PolarisTreeMapMetaStoreSessionImpl session =
+ new PolarisTreeMapMetaStoreSessionImpl(treeMapStore, Mockito.mock());
+ metastoreManagerFactory =
+ new LocalPolarisMetaStoreManagerFactory<PolarisTreeMapStore>() {
+
+ @Override
+ protected PolarisTreeMapStore createBackingStore(
+ @NotNull PolarisDiagnostics diagnostics) {
+ return treeMapStore;
+ }
+
+ @Override
+ protected PolarisMetaStoreSession createMetaStoreSession(
+ @NotNull PolarisTreeMapStore store, @NotNull RealmContext realmContext) {
+ return session;
+ }
+ };
+ // Create a Resolver and an EntityCacheGrantManager
+ realmContext = () -> "realm";
+ metastoreManagerFactory.bootstrapRealms(List.of(realmContext.getRealmIdentifier()));
+ metaStoreManager = metastoreManagerFactory.getOrCreateMetaStoreManager(realmContext);
+ polarisCallContext = new PolarisCallContext(session, diagServices);
+
+ // Create a principal with three Principal roles
+ principal =
+ new PrincipalEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("principal1")
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+ principalRole1 =
+ new PrincipalRoleEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("principalRole1")
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+ principalRole2 =
+ new PrincipalRoleEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("principalRole2")
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+
+ // Persist the principal and principal roles
+ metaStoreManager.createPrincipal(polarisCallContext, principal);
+ metaStoreManager.createEntityIfNotExists(polarisCallContext, null, principalRole1);
+ metaStoreManager.createEntityIfNotExists(polarisCallContext, null, principalRole2);
+
+ // Create a catalog with two catalog roles
+ catalog =
+ new CatalogEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("mycatalog")
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+ catalogRole1 =
+ new CatalogRoleEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("mycatrole1")
+ .setCatalogId(catalog.getId())
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+ catalogRole2 =
+ new CatalogRoleEntity.Builder()
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setName("mycatrole2")
+ .setCatalogId(catalog.getId())
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build();
+ metaStoreManager.createCatalog(polarisCallContext, catalog, List.of(principalRole1));
+ metaStoreManager.createEntityIfNotExists(polarisCallContext, List.of(catalog), catalogRole1);
+ metaStoreManager.createEntityIfNotExists(polarisCallContext, List.of(catalog), catalogRole2);
+ metaStoreManager.grantUsageOnRoleToGrantee(
+ polarisCallContext, catalog, catalogRole1, principalRole1);
+ metaStoreManager.grantUsageOnRoleToGrantee(
+ polarisCallContext, catalog, catalogRole2, principalRole2);
+ metaStoreManager.grantUsageOnRoleToGrantee(polarisCallContext, null, principalRole1, principal);
+ metaStoreManager.grantUsageOnRoleToGrantee(polarisCallContext, null, principalRole2, principal);
+
+ PolarisBaseEntity ns1 =
+ metaStoreManager
+ .createEntityIfNotExists(
+ polarisCallContext,
+ List.of(catalog),
+ new NamespaceEntity.Builder(Namespace.of(NS_1))
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setCatalogId(catalog.getId())
+ .setParentId(catalog.getId())
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build())
+ .getEntity();
+
+ Namespace ns2Namespace = Namespace.of(NS_1, NS_2);
+ PolarisBaseEntity ns2 =
+ metaStoreManager
+ .createEntityIfNotExists(
+ polarisCallContext,
+ List.of(catalog, ns1),
+ new NamespaceEntity.Builder(ns2Namespace)
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setCatalogId(catalog.getId())
+ .setParentId(ns1.getId())
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build())
+ .getEntity();
+
+ TableIdentifier tbId = TableIdentifier.of(ns2Namespace, TABLE_1);
+ PolarisBaseEntity tb1 =
+ metaStoreManager
+ .createEntityIfNotExists(
+ polarisCallContext,
+ List.of(catalog),
+ new TableLikeEntity.Builder(tbId, "file://abc")
+ .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId())
+ .setCatalogId(catalog.getId())
+ .setParentId(ns2.getId())
+ .setCreateTimestamp(System.currentTimeMillis())
+ .setEntityVersion(1)
+ .build())
+ .getEntity();
+ metaStoreManager.grantPrivilegeOnSecurableToRole(
+ polarisCallContext,
+ new PolarisEntityCore(catalogRole1),
+ List.of(PolarisEntity.toCore(catalog)),
+ PolarisEntity.toCore(ns1),
+ PolarisPrivilege.NAMESPACE_LIST);
+ metaStoreManager.grantPrivilegeOnSecurableToRole(
+ polarisCallContext,
+ new PolarisEntityCore(catalogRole1),
+ List.of(PolarisEntity.toCore(catalog), PolarisEntity.toCore(ns1)),
+ PolarisEntity.toCore(ns2),
+ PolarisPrivilege.TABLE_CREATE);
+ metaStoreManager.grantPrivilegeOnSecurableToRole(
+ polarisCallContext,
+ new PolarisEntityCore(catalogRole2),
+ List.of(
+ PolarisEntity.toCore(catalog), PolarisEntity.toCore(ns1), PolarisEntity.toCore(ns2)),
+ PolarisEntity.toCore(tb1),
+ PolarisPrivilege.TABLE_READ_DATA);
+ }
+
+ @Test
+ public void testReadFromResolverPopulatedCache() {
+ Namespace ns2 = Namespace.of(NS_1, NS_2);
+ TableIdentifier tbId = TableIdentifier.of(ns2, TABLE_1);
+ EntityCache entityCache = new EntityCache(metaStoreManager);
+ PolarisResolutionManifest manifest =
+ new PolarisResolutionManifest(
+ CallContext.of(realmContext, polarisCallContext),
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache()),
+ new AuthenticatedPolarisPrincipal(
+ principal, Set.of(principalRole1.getName(), principalRole2.getName())),
+ catalog.getName());
+ manifest.addPath(new ResolverPath(List.of(NS_1, NS_2), PolarisEntityType.NAMESPACE), ns2);
+ manifest.addPath(
+ new ResolverPath(List.of(NS_1, NS_2, TABLE_1), PolarisEntityType.TABLE_LIKE), tbId);
+
+ ResolverStatus resolverStatus = manifest.resolveAll();
+ Assertions.assertThat(resolverStatus.getStatus()).isEqualTo(ResolverStatus.StatusEnum.SUCCESS);
+
+ // now create an EntityCacheGrantManager with a dummy grantManager implementation.
+ // everything should be returned from the cache
+ EntityCacheGrantManager grantManager = new EntityCacheGrantManager(Mockito.mock(), entityCache);
+ PolarisResolvedPathWrapper resolvedNamespace = manifest.getResolvedPath(ns2, false);
+
+ PolarisGrantManager.LoadGrantsResult grantsResult =
+ grantManager.loadGrantsOnSecurable(
+ polarisCallContext,
+ manifest.getResolvedReferenceCatalogEntity().getRawLeafEntity().getId(),
+ resolvedNamespace.getRawLeafEntity().getId());
+ Assertions.assertThat(grantsResult)
+ .returns(true, PolarisGrantManager.LoadGrantsResult::isSuccess)
+ .extracting(PolarisGrantManager.LoadGrantsResult::getGrantRecords)
+ .asInstanceOf(InstanceOfAssertFactories.list(PolarisGrantRecord.class))
+ .hasSize(1)
+ .satisfiesExactly(
+ grant -> {
+ Assertions.assertThat(grant)
+ .returns(catalogRole1.getId(), PolarisGrantRecord::getGranteeId)
+ .returns(
+ PolarisPrivilege.TABLE_CREATE.getCode(),
+ PolarisGrantRecord::getPrivilegeCode);
+ });
+
+ PolarisResolvedPathWrapper resolvedTable = manifest.getResolvedPath(tbId, false);
+ PolarisGrantManager.LoadGrantsResult tbGrantsResult =
+ grantManager.loadGrantsOnSecurable(
+ polarisCallContext,
+ manifest.getResolvedReferenceCatalogEntity().getRawLeafEntity().getId(),
+ resolvedTable.getRawLeafEntity().getId());
+ Assertions.assertThat(tbGrantsResult)
+ .returns(true, PolarisGrantManager.LoadGrantsResult::isSuccess)
+ .extracting(PolarisGrantManager.LoadGrantsResult::getGrantRecords)
+ .asInstanceOf(InstanceOfAssertFactories.list(PolarisGrantRecord.class))
+ .hasSize(1)
+ .satisfiesExactly(
+ grant -> {
+ Assertions.assertThat(grant)
+ .returns(catalogRole2.getId(), PolarisGrantRecord::getGranteeId)
+ .returns(
+ PolarisPrivilege.TABLE_READ_DATA.getCode(),
+ PolarisGrantRecord::getPrivilegeCode);
+ });
+ }
+
+ @Test
+ public void testRevokeGrantsClearsCache() {
+ Namespace ns2 = Namespace.of(NS_1, NS_2);
+ TableIdentifier tbId = TableIdentifier.of(ns2, TABLE_1);
+ EntityCache entityCache = new EntityCache(metaStoreManager);
+ PolarisResolutionManifest manifest =
+ new PolarisResolutionManifest(
+ CallContext.of(realmContext, polarisCallContext),
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache()),
+ new AuthenticatedPolarisPrincipal(
+ principal, Set.of(principalRole1.getName(), principalRole2.getName())),
+ catalog.getName());
+ manifest.addPath(new ResolverPath(List.of(NS_1, NS_2), PolarisEntityType.NAMESPACE), ns2);
+ manifest.addPath(
+ new ResolverPath(List.of(NS_1, NS_2, TABLE_1), PolarisEntityType.TABLE_LIKE), tbId);
+
+ ResolverStatus resolverStatus = manifest.resolveAll();
+ Assertions.assertThat(resolverStatus.getStatus()).isEqualTo(ResolverStatus.StatusEnum.SUCCESS);
+
+ PolarisGrantManager mockGrantManager = Mockito.mock();
+ EntityCacheGrantManager grantManager =
+ new EntityCacheGrantManager(mockGrantManager, entityCache);
+ PolarisResolvedPathWrapper resolvedNamespace = manifest.getResolvedPath(ns2, false);
+
+ // update the mock to return a successful response when we revoke the privilege
+ Mockito.when(
+ grantManager.revokePrivilegeOnSecurableFromRole(
+ polarisCallContext,
+ catalogRole1,
+ resolvedNamespace.getRawParentPath().stream()
+ .map(PolarisEntity::toCore)
+ .collect(Collectors.toList()),
+ resolvedNamespace.getRawLeafEntity(),
+ PolarisPrivilege.TABLE_CREATE))
+ .thenReturn(new PolarisGrantManager.PrivilegeResult(BaseResult.ReturnStatus.SUCCESS, null));
+ PolarisGrantManager.PrivilegeResult result =
+ grantManager.revokePrivilegeOnSecurableFromRole(
+ polarisCallContext,
+ catalogRole1,
+ resolvedNamespace.getRawParentPath().stream()
+ .map(PolarisEntity::toCore)
+ .collect(Collectors.toList()),
+ resolvedNamespace.getRawLeafEntity(),
+ PolarisPrivilege.TABLE_CREATE);
+ Assertions.assertThat(result)
+ .returns(
+ BaseResult.ReturnStatus.SUCCESS, PolarisGrantManager.PrivilegeResult::getReturnStatus);
+
+ // the cache is cleared
+ Assertions.assertThat(entityCache.getEntityById(resolvedNamespace.getRawLeafEntity().getId()))
+ .isNull();
+
+ // update the mock to return a successful, but empty response when we load the grants
+ Mockito.when(
+ mockGrantManager.loadGrantsOnSecurable(
+ polarisCallContext,
+ manifest.getResolvedReferenceCatalogEntity().getRawLeafEntity().getId(),
+ resolvedNamespace.getRawLeafEntity().getId()))
+ .thenReturn(new PolarisGrantManager.LoadGrantsResult(2, List.of(), List.of()));
+ PolarisGrantManager.LoadGrantsResult grantsResult =
+ mockGrantManager.loadGrantsOnSecurable(
+ polarisCallContext,
+ manifest.getResolvedReferenceCatalogEntity().getRawLeafEntity().getId(),
+ resolvedNamespace.getRawLeafEntity().getId());
+ Assertions.assertThat(grantsResult)
+ .returns(true, PolarisGrantManager.LoadGrantsResult::isSuccess)
+ .extracting(PolarisGrantManager.LoadGrantsResult::getGrantRecords)
+ .asInstanceOf(InstanceOfAssertFactories.list(PolarisGrantRecord.class))
+ .isEmpty();
+ }
+
+ @Test
+ public void testUpdateGrantsClearsCache() {
+ Namespace ns2 = Namespace.of(NS_1, NS_2);
+ TableIdentifier tbId = TableIdentifier.of(ns2, TABLE_1);
+ EntityCache entityCache = new EntityCache(metaStoreManager);
+ PolarisResolutionManifest manifest =
+ new PolarisResolutionManifest(
+ CallContext.of(realmContext, polarisCallContext),
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache()),
+ new AuthenticatedPolarisPrincipal(
+ principal, Set.of(principalRole1.getName(), principalRole2.getName())),
+ catalog.getName());
+ manifest.addPath(new ResolverPath(List.of(NS_1, NS_2), PolarisEntityType.NAMESPACE), ns2);
+ manifest.addPath(
+ new ResolverPath(List.of(NS_1, NS_2, TABLE_1), PolarisEntityType.TABLE_LIKE), tbId);
+
+ ResolverStatus resolverStatus = manifest.resolveAll();
+ Assertions.assertThat(resolverStatus.getStatus()).isEqualTo(ResolverStatus.StatusEnum.SUCCESS);
+
+ EntityCacheGrantManager grantManager =
+ new EntityCacheGrantManager(metaStoreManager, entityCache);
+ PolarisResolvedPathWrapper resolvedTable = manifest.getResolvedPath(tbId, false);
+
+ PolarisGrantManager.PrivilegeResult result =
+ grantManager.grantPrivilegeOnSecurableToRole(
+ polarisCallContext,
+ catalogRole2,
+ resolvedTable.getRawParentPath().stream()
+ .map(PolarisEntity::toCore)
+ .collect(Collectors.toList()),
+ resolvedTable.getRawLeafEntity(),
+ PolarisPrivilege.TABLE_DROP);
+ Assertions.assertThat(result)
+ .returns(
+ BaseResult.ReturnStatus.SUCCESS, PolarisGrantManager.PrivilegeResult::getReturnStatus);
+
+ // the cache is cleared
+ Assertions.assertThat(entityCache.getEntityById(resolvedTable.getRawLeafEntity().getId()))
+ .isNull();
+
+ PolarisGrantManager.LoadGrantsResult grantsResult =
+ grantManager.loadGrantsOnSecurable(
+ polarisCallContext,
+ manifest.getResolvedReferenceCatalogEntity().getRawLeafEntity().getId(),
+ resolvedTable.getRawLeafEntity().getId());
+ Assertions.assertThat(grantsResult)
+ .returns(true, PolarisGrantManager.LoadGrantsResult::isSuccess)
+ .extracting(PolarisGrantManager.LoadGrantsResult::getGrantRecords)
+ .asInstanceOf(InstanceOfAssertFactories.list(PolarisGrantRecord.class))
+ .hasSize(2)
+ .satisfiesExactlyInAnyOrder(
+ (PolarisGrantRecord gr) ->
+ Assertions.assertThat(gr)
+ .returns(catalogRole2.getId(), PolarisGrantRecord::getGranteeId)
+ .returns(
+ PolarisPrivilege.TABLE_READ_DATA.getCode(),
+ PolarisGrantRecord::getPrivilegeCode),
+ (PolarisGrantRecord gr) ->
+ Assertions.assertThat(gr)
+ .returns(catalogRole2.getId(), PolarisGrantRecord::getGranteeId)
+ .returns(
+ PolarisPrivilege.TABLE_DROP.getCode(),
+ PolarisGrantRecord::getPrivilegeCode));
+ }
+}
diff --git a/polaris-service/src/main/java/org/apache/polaris/service/PolarisApplication.java b/polaris-service/src/main/java/org/apache/polaris/service/PolarisApplication.java
index 908496da..88e685dd 100644
--- a/polaris-service/src/main/java/org/apache/polaris/service/PolarisApplication.java
+++ b/polaris-service/src/main/java/org/apache/polaris/service/PolarisApplication.java
@@ -66,6 +66,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -75,11 +76,14 @@ import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.auth.PolarisAuthorizerImpl;
+import org.apache.polaris.core.auth.PolarisGrantManager;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.monitor.MetricRegistryAware;
import org.apache.polaris.core.monitor.PolarisMetricRegistry;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.cache.EntityCacheGrantManager;
import org.apache.polaris.service.admin.PolarisServiceImpl;
import org.apache.polaris.service.admin.api.PolarisCatalogsApi;
import org.apache.polaris.service.admin.api.PolarisPrincipalRolesApi;
@@ -226,7 +230,17 @@ public class PolarisApplication extends Application<PolarisApplicationConfig> {
new PolarisCallContextCatalogFactory(
entityManagerFactory, metaStoreManagerFactory, taskExecutor, fileIOFactory);
- PolarisAuthorizer authorizer = new PolarisAuthorizerImpl(configurationStore);
+ ConcurrentHashMap<RealmContext, EntityCache> realmEntityCache = new ConcurrentHashMap<>();
+ PolarisGrantManager.Factory factory =
+ new EntityCacheGrantManager.EntityCacheGrantManagerFactory(
+ metaStoreManagerFactory,
+ realm ->
+ realmEntityCache.computeIfAbsent(
+ realm,
+ (r) ->
+ new EntityCache(
+ metaStoreManagerFactory.getOrCreateMetaStoreManager(realm))));
+ PolarisAuthorizer authorizer = new PolarisAuthorizerImpl(configurationStore, factory);
IcebergCatalogAdapter catalogAdapter =
new IcebergCatalogAdapter(
catalogFactory, entityManagerFactory, metaStoreManagerFactory, authorizer);
diff --git a/polaris-service/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java b/polaris-service/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java
index b5fb48a7..38da2975 100644
--- a/polaris-service/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java
+++ b/polaris-service/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisEntityManager;
+import org.apache.polaris.core.persistence.cache.EntityCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,6 +55,7 @@ public class RealmEntityManagerFactory {
entityManagerInstance =
new PolarisEntityManager(
metaStoreManagerFactory.getOrCreateMetaStoreManager(context),
+ new EntityCache(metaStoreManagerFactory.getOrCreateMetaStoreManager(context)),
metaStoreManagerFactory.getOrCreateStorageCredentialCache(context));
cachedEntityManagers.put(realm, entityManagerInstance);
diff --git a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java
index 6fc24a2b..f2893365 100644
--- a/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java
+++ b/polaris-service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java
@@ -62,6 +62,8 @@ import org.apache.polaris.core.entity.PrincipalEntity;
import org.apache.polaris.core.entity.PrincipalRoleEntity;
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.cache.EntityCacheGrantManager;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.core.storage.cache.StorageCredentialCache;
import org.apache.polaris.service.catalog.BasePolarisCatalog;
@@ -130,12 +132,7 @@ public abstract class PolarisAuthzTestBase {
new Schema(
required(3, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(4, "data", Types.StringType.get()));
- protected final PolarisAuthorizer polarisAuthorizer =
- new PolarisAuthorizerImpl(
- new DefaultConfigurationStore(
- Map.of(
- PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING.key,
- true)));
+ protected PolarisAuthorizer polarisAuthorizer;
protected BasePolarisCatalog baseCatalog;
protected PolarisAdminService adminService;
@@ -162,6 +159,7 @@ public abstract class PolarisAuthzTestBase {
Map<String, Object> configMap =
Map.of(
"ALLOW_SPECIFYING_FILE_IO_IMPL", true, "ALLOW_EXTERNAL_METADATA_FILE_LOCATION", true);
+
PolarisCallContext polarisContext =
new PolarisCallContext(
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
@@ -173,20 +171,23 @@ public abstract class PolarisAuthzTestBase {
}
},
Clock.systemDefaultZone());
- this.entityManager = new PolarisEntityManager(metaStoreManager, new StorageCredentialCache());
- this.metaStoreManager = metaStoreManager;
-
- callContext =
- CallContext.of(
- new RealmContext() {
- @Override
- public String getRealmIdentifier() {
- return "test-realm";
- }
- },
- polarisContext);
+ callContext = CallContext.of(realmContext, polarisContext);
CallContext.setCurrentContext(callContext);
+ EntityCache entityCache = new EntityCache(metaStoreManager);
+ polarisAuthorizer =
+ new PolarisAuthorizerImpl(
+ new DefaultConfigurationStore(
+ Map.of(
+ PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING
+ .key,
+ true)),
+ new EntityCacheGrantManager.EntityCacheGrantManagerFactory(
+ metaStoreManagerFactory, (realm) -> entityCache));
+ this.entityManager =
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache());
+ this.metaStoreManager = metaStoreManager;
+
PrincipalEntity rootEntity =
new PrincipalEntity(
PolarisEntity.of(
diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogTest.java
index 7b0270c4..6349e40c 100644
--- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogTest.java
+++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogTest.java
@@ -80,6 +80,8 @@ import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.cache.EntityCacheGrantManager;
import org.apache.polaris.core.storage.PolarisCredentialProperty;
import org.apache.polaris.core.storage.PolarisStorageIntegration;
import org.apache.polaris.core.storage.PolarisStorageIntegrationProvider;
@@ -157,7 +159,9 @@ public class BasePolarisCatalogTest extends CatalogTests<BasePolarisCatalog> {
}
},
Clock.systemDefaultZone());
- entityManager = new PolarisEntityManager(metaStoreManager, new StorageCredentialCache());
+ EntityCache entityCache = new EntityCache(metaStoreManager);
+ entityManager =
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache());
CallContext callContext = CallContext.of(realmContext, polarisContext);
CallContext.setCurrentContext(callContext);
@@ -182,7 +186,11 @@ public class BasePolarisCatalogTest extends CatalogTests<BasePolarisCatalog> {
entityManager,
metaStoreManager,
authenticatedRoot,
- new PolarisAuthorizerImpl(new PolarisConfigurationStore() {}));
+ new PolarisAuthorizerImpl(
+ new PolarisConfigurationStore() {},
+ new EntityCacheGrantManager.EntityCacheGrantManagerFactory(
+ (realm) -> metaStoreManager, (realm) -> entityCache)));
+
String storageLocation = "s3://my-bucket/path/to/data";
storageConfigModel =
AwsStorageConfigInfo.builder()
diff --git a/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogViewTest.java b/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogViewTest.java
index 252cd16f..b9c8600d 100644
--- a/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogViewTest.java
+++ b/polaris-service/src/test/java/org/apache/polaris/service/catalog/BasePolarisCatalogViewTest.java
@@ -48,6 +48,8 @@ import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.entity.PrincipalEntity;
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.cache.EntityCacheGrantManager;
import org.apache.polaris.core.storage.cache.StorageCredentialCache;
import org.apache.polaris.service.admin.PolarisAdminService;
import org.apache.polaris.service.catalog.io.DefaultFileIOFactory;
@@ -88,8 +90,9 @@ public class BasePolarisCatalogViewTest extends ViewCatalogTests<BasePolarisCata
},
Clock.systemDefaultZone());
+ EntityCache entityCache = new EntityCache(metaStoreManager);
PolarisEntityManager entityManager =
- new PolarisEntityManager(metaStoreManager, new StorageCredentialCache());
+ new PolarisEntityManager(metaStoreManager, entityCache, new StorageCredentialCache());
CallContext callContext = CallContext.of(null, polarisContext);
CallContext.setCurrentContext(callContext);
@@ -114,7 +117,10 @@ public class BasePolarisCatalogViewTest extends ViewCatalogTests<BasePolarisCata
entityManager,
metaStoreManager,
authenticatedRoot,
- new PolarisAuthorizerImpl(new PolarisConfigurationStore() {}));
+ new PolarisAuthorizerImpl(
+ new PolarisConfigurationStore() {},
+ new EntityCacheGrantManager.EntityCacheGrantManagerFactory(
+ (realm) -> metaStoreManager, (realm) -> entityCache)));
adminService.createCatalog(
new CatalogEntity.Builder()
.setName(CATALOG_NAME)