Skip to content

Commit f86f02d

Browse files
committed
Make ResolverFactory + ResolutionManifestFactory request-scoped
this avoids passing around the `CallContext` parameter note that ideally the `SecurityContext` would also be injected from the request however our tests around `PolarisAuthzTestBase` are written in a way that does not easily support this currently.
1 parent fcb6b33 commit f86f02d

File tree

19 files changed

+102
-146
lines changed

19 files changed

+102
-146
lines changed

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/PolarisResolutionManifest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Set;
3131
import org.apache.polaris.core.PolarisDiagnostics;
3232
import org.apache.polaris.core.auth.PolarisPrincipal;
33-
import org.apache.polaris.core.context.CallContext;
33+
import org.apache.polaris.core.context.RealmContext;
3434
import org.apache.polaris.core.entity.PolarisBaseEntity;
3535
import org.apache.polaris.core.entity.PolarisEntityConstants;
3636
import org.apache.polaris.core.entity.PolarisEntitySubType;
@@ -52,8 +52,8 @@ public class PolarisResolutionManifest implements PolarisResolutionManifestCatal
5252
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisResolutionManifest.class);
5353

5454
private final ResolverFactory resolverFactory;
55-
private final CallContext callContext;
5655
private final SecurityContext securityContext;
56+
private final RealmContext realmContext;
5757
private final String catalogName;
5858
private final Resolver primaryResolver;
5959
private final PolarisDiagnostics diagnostics;
@@ -71,15 +71,14 @@ public class PolarisResolutionManifest implements PolarisResolutionManifestCatal
7171

7272
public PolarisResolutionManifest(
7373
PolarisDiagnostics diagnostics,
74-
CallContext callContext,
74+
RealmContext realmContext,
7575
ResolverFactory resolverFactory,
7676
SecurityContext securityContext,
7777
String catalogName) {
78-
this.callContext = callContext;
78+
this.realmContext = realmContext;
7979
this.resolverFactory = resolverFactory;
8080
this.catalogName = catalogName;
81-
this.primaryResolver =
82-
resolverFactory.createResolver(callContext, securityContext, catalogName);
81+
this.primaryResolver = resolverFactory.createResolver(securityContext, catalogName);
8382
this.diagnostics = diagnostics;
8483
this.diagnostics.checkNotNull(securityContext, "null_security_context_for_resolution_manifest");
8584
this.securityContext = securityContext;
@@ -187,8 +186,7 @@ public PolarisResolvedPathWrapper getPassthroughResolvedPath(Object key) {
187186
ResolverPath requestedPath = passthroughPaths.get(key);
188187

189188
// Run a single-use Resolver for this path.
190-
Resolver passthroughResolver =
191-
resolverFactory.createResolver(callContext, securityContext, catalogName);
189+
Resolver passthroughResolver = resolverFactory.createResolver(securityContext, catalogName);
192190
passthroughResolver.addPath(requestedPath);
193191
ResolverStatus status = passthroughResolver.resolveAll();
194192

@@ -273,7 +271,7 @@ public Set<PolarisBaseEntity> getAllActivatedPrincipalRoleEntities() {
273271
if (resolvedEntity == null) {
274272
LOGGER.warn(
275273
"Failed to find rootContainer for realm: {} and catalog: {}",
276-
callContext.getRealmContext().getRealmIdentifier(),
274+
realmContext.getRealmIdentifier(),
277275
catalogName);
278276
}
279277
return resolvedEntity;

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/ResolutionManifestFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
import jakarta.annotation.Nonnull;
2323
import jakarta.annotation.Nullable;
2424
import jakarta.ws.rs.core.SecurityContext;
25-
import org.apache.polaris.core.context.CallContext;
2625

2726
public interface ResolutionManifestFactory {
2827

2928
@Nonnull
3029
PolarisResolutionManifest createResolutionManifest(
31-
@Nonnull CallContext callContext,
32-
@Nonnull SecurityContext securityContext,
33-
@Nullable String referenceCatalogName);
30+
@Nonnull SecurityContext securityContext, @Nullable String referenceCatalogName);
3431
}

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/ResolutionManifestFactoryImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,28 @@
2323
import jakarta.annotation.Nullable;
2424
import jakarta.ws.rs.core.SecurityContext;
2525
import org.apache.polaris.core.PolarisDiagnostics;
26-
import org.apache.polaris.core.context.CallContext;
26+
import org.apache.polaris.core.context.RealmContext;
2727

2828
public class ResolutionManifestFactoryImpl implements ResolutionManifestFactory {
2929

3030
private final PolarisDiagnostics diagnostics;
31+
private final RealmContext realmContext;
3132
private final ResolverFactory resolverFactory;
3233

3334
public ResolutionManifestFactoryImpl(
34-
@Nonnull PolarisDiagnostics diagnostics, @Nonnull ResolverFactory resolverFactory) {
35+
@Nonnull PolarisDiagnostics diagnostics,
36+
@Nonnull RealmContext realmContext,
37+
@Nonnull ResolverFactory resolverFactory) {
3538
this.diagnostics = diagnostics;
39+
this.realmContext = realmContext;
3640
this.resolverFactory = resolverFactory;
3741
}
3842

3943
@Nonnull
4044
@Override
4145
public PolarisResolutionManifest createResolutionManifest(
42-
@Nonnull CallContext callContext,
43-
@Nonnull SecurityContext securityContext,
44-
@Nullable String referenceCatalogName) {
46+
@Nonnull SecurityContext securityContext, @Nullable String referenceCatalogName) {
4547
return new PolarisResolutionManifest(
46-
diagnostics, callContext, resolverFactory, securityContext, referenceCatalogName);
48+
diagnostics, realmContext, resolverFactory, securityContext, referenceCatalogName);
4749
}
4850
}

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/ResolverFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
import jakarta.annotation.Nonnull;
2323
import jakarta.annotation.Nullable;
2424
import jakarta.ws.rs.core.SecurityContext;
25-
import org.apache.polaris.core.context.CallContext;
2625

2726
public interface ResolverFactory {
2827
Resolver createResolver(
29-
@Nonnull CallContext callContext,
30-
@Nonnull SecurityContext securityContext,
31-
@Nullable String referenceCatalogName);
28+
@Nonnull SecurityContext securityContext, @Nullable String referenceCatalogName);
3229
}

runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ private UserSecretsManager getUserSecretsManager() {
189189
return userSecretsManager;
190190
}
191191

192+
private PolarisResolutionManifest newResolutionManifest(@Nullable String catalogName) {
193+
return resolutionManifestFactory.createResolutionManifest(securityContext, catalogName);
194+
}
195+
192196
private Optional<CatalogEntity> findCatalogByName(String name) {
193197
return Optional.ofNullable(resolutionManifest.getResolvedReferenceCatalogEntity())
194198
.map(path -> CatalogEntity.of(path.getRawLeafEntity()));
@@ -212,9 +216,7 @@ private Optional<CatalogRoleEntity> findCatalogRoleByName(String catalogName, St
212216
}
213217

214218
private void authorizeBasicRootOperationOrThrow(PolarisAuthorizableOperation op) {
215-
resolutionManifest =
216-
resolutionManifestFactory.createResolutionManifest(
217-
callContext, securityContext, null /* referenceCatalogName */);
219+
resolutionManifest = newResolutionManifest(null);
218220
resolutionManifest.resolveAll();
219221
PolarisResolvedPathWrapper rootContainerWrapper =
220222
resolutionManifest.getResolvedRootContainerEntityAsPath();
@@ -239,9 +241,7 @@ private void authorizeBasicTopLevelEntityOperationOrThrow(
239241
String topLevelEntityName,
240242
PolarisEntityType entityType,
241243
@Nullable String referenceCatalogName) {
242-
resolutionManifest =
243-
resolutionManifestFactory.createResolutionManifest(
244-
callContext, securityContext, referenceCatalogName);
244+
resolutionManifest = newResolutionManifest(referenceCatalogName);
245245
resolutionManifest.addTopLevelName(topLevelEntityName, entityType, false /* isOptional */);
246246
ResolverStatus status = resolutionManifest.resolveAll();
247247
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -292,9 +292,7 @@ private static boolean isSelfOperation(PolarisAuthorizableOperation op) {
292292

293293
private void authorizeBasicCatalogRoleOperationOrThrow(
294294
PolarisAuthorizableOperation op, String catalogName, String catalogRoleName) {
295-
resolutionManifest =
296-
resolutionManifestFactory.createResolutionManifest(
297-
callContext, securityContext, catalogName);
295+
resolutionManifest = newResolutionManifest(catalogName);
298296
resolutionManifest.addPath(
299297
new ResolverPath(List.of(catalogRoleName), PolarisEntityType.CATALOG_ROLE),
300298
catalogRoleName);
@@ -313,8 +311,7 @@ private void authorizeBasicCatalogRoleOperationOrThrow(
313311

314312
private void authorizeGrantOnRootContainerToPrincipalRoleOperationOrThrow(
315313
PolarisAuthorizableOperation op, String principalRoleName) {
316-
resolutionManifest =
317-
resolutionManifestFactory.createResolutionManifest(callContext, securityContext, null);
314+
resolutionManifest = newResolutionManifest(null);
318315
resolutionManifest.addTopLevelName(
319316
principalRoleName, PolarisEntityType.PRINCIPAL_ROLE, false /* isOptional */);
320317
ResolverStatus status = resolutionManifest.resolveAll();
@@ -341,8 +338,7 @@ private void authorizeGrantOnRootContainerToPrincipalRoleOperationOrThrow(
341338

342339
private void authorizeGrantOnPrincipalRoleToPrincipalOperationOrThrow(
343340
PolarisAuthorizableOperation op, String principalRoleName, String principalName) {
344-
resolutionManifest =
345-
resolutionManifestFactory.createResolutionManifest(callContext, securityContext, null);
341+
resolutionManifest = newResolutionManifest(null);
346342
resolutionManifest.addTopLevelName(
347343
principalRoleName, PolarisEntityType.PRINCIPAL_ROLE, false /* isOptional */);
348344
resolutionManifest.addTopLevelName(
@@ -374,9 +370,7 @@ private void authorizeGrantOnCatalogRoleToPrincipalRoleOperationOrThrow(
374370
String catalogName,
375371
String catalogRoleName,
376372
String principalRoleName) {
377-
resolutionManifest =
378-
resolutionManifestFactory.createResolutionManifest(
379-
callContext, securityContext, catalogName);
373+
resolutionManifest = newResolutionManifest(catalogName);
380374
resolutionManifest.addPath(
381375
new ResolverPath(List.of(catalogRoleName), PolarisEntityType.CATALOG_ROLE),
382376
catalogRoleName);
@@ -410,9 +404,7 @@ private void authorizeGrantOnCatalogRoleToPrincipalRoleOperationOrThrow(
410404

411405
private void authorizeGrantOnCatalogOperationOrThrow(
412406
PolarisAuthorizableOperation op, String catalogName, String catalogRoleName) {
413-
resolutionManifest =
414-
resolutionManifestFactory.createResolutionManifest(
415-
callContext, securityContext, catalogName);
407+
resolutionManifest = newResolutionManifest(catalogName);
416408
resolutionManifest.addTopLevelName(
417409
catalogName, PolarisEntityType.CATALOG, false /* isOptional */);
418410
resolutionManifest.addPath(
@@ -443,9 +435,7 @@ private void authorizeGrantOnNamespaceOperationOrThrow(
443435
String catalogName,
444436
Namespace namespace,
445437
String catalogRoleName) {
446-
resolutionManifest =
447-
resolutionManifestFactory.createResolutionManifest(
448-
callContext, securityContext, catalogName);
438+
resolutionManifest = newResolutionManifest(catalogName);
449439
resolutionManifest.addPath(
450440
new ResolverPath(Arrays.asList(namespace.levels()), PolarisEntityType.NAMESPACE),
451441
namespace);
@@ -484,9 +474,7 @@ private void authorizeGrantOnTableLikeOperationOrThrow(
484474
List<PolarisEntitySubType> subTypes,
485475
TableIdentifier identifier,
486476
String catalogRoleName) {
487-
resolutionManifest =
488-
resolutionManifestFactory.createResolutionManifest(
489-
callContext, securityContext, catalogName);
477+
resolutionManifest = newResolutionManifest(catalogName);
490478
resolutionManifest.addPath(
491479
new ResolverPath(
492480
PolarisCatalogHelpers.tableIdentifierToList(identifier), PolarisEntityType.TABLE_LIKE),
@@ -529,9 +517,7 @@ private void authorizeGrantOnPolicyOperationOrThrow(
529517
String catalogName,
530518
PolicyIdentifier identifier,
531519
String catalogRoleName) {
532-
resolutionManifest =
533-
resolutionManifestFactory.createResolutionManifest(
534-
callContext, securityContext, catalogName);
520+
resolutionManifest = newResolutionManifest(catalogName);
535521
resolutionManifest.addPath(
536522
new ResolverPath(
537523
PolarisCatalogHelpers.identifierToList(identifier.getNamespace(), identifier.getName()),

runtime/service/src/main/java/org/apache/polaris/service/catalog/common/CatalogHandler.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ protected UserSecretsManager getUserSecretsManager() {
102102
return userSecretsManager;
103103
}
104104

105+
protected PolarisResolutionManifest newResolutionManifest() {
106+
return resolutionManifestFactory.createResolutionManifest(securityContext, catalogName);
107+
}
108+
105109
/** Initialize the catalog once authorized. Called after all `authorize...` methods. */
106110
protected abstract void initializeCatalog();
107111

@@ -116,9 +120,7 @@ protected void authorizeBasicNamespaceOperationOrThrow(
116120
List<Namespace> extraPassthroughNamespaces,
117121
List<TableIdentifier> extraPassthroughTableLikes,
118122
List<PolicyIdentifier> extraPassThroughPolicies) {
119-
resolutionManifest =
120-
resolutionManifestFactory.createResolutionManifest(
121-
callContext, securityContext, catalogName);
123+
resolutionManifest = newResolutionManifest();
122124
resolutionManifest.addPath(
123125
new ResolverPath(Arrays.asList(namespace.levels()), PolarisEntityType.NAMESPACE),
124126
namespace);
@@ -170,9 +172,7 @@ protected void authorizeBasicNamespaceOperationOrThrow(
170172

171173
protected void authorizeCreateNamespaceUnderNamespaceOperationOrThrow(
172174
PolarisAuthorizableOperation op, Namespace namespace) {
173-
resolutionManifest =
174-
resolutionManifestFactory.createResolutionManifest(
175-
callContext, securityContext, catalogName);
175+
resolutionManifest = newResolutionManifest();
176176

177177
Namespace parentNamespace = PolarisCatalogHelpers.getParentNamespace(namespace);
178178
resolutionManifest.addPath(
@@ -206,9 +206,7 @@ protected void authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
206206
PolarisAuthorizableOperation op, TableIdentifier identifier) {
207207
Namespace namespace = identifier.namespace();
208208

209-
resolutionManifest =
210-
resolutionManifestFactory.createResolutionManifest(
211-
callContext, securityContext, catalogName);
209+
resolutionManifest = newResolutionManifest();
212210
resolutionManifest.addPath(
213211
new ResolverPath(Arrays.asList(namespace.levels()), PolarisEntityType.NAMESPACE),
214212
namespace);
@@ -242,9 +240,7 @@ protected void authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
242240

243241
protected void authorizeBasicTableLikeOperationOrThrow(
244242
PolarisAuthorizableOperation op, PolarisEntitySubType subType, TableIdentifier identifier) {
245-
resolutionManifest =
246-
resolutionManifestFactory.createResolutionManifest(
247-
callContext, securityContext, catalogName);
243+
resolutionManifest = newResolutionManifest();
248244

249245
// The underlying Catalog is also allowed to fetch "fresh" versions of the target entity.
250246
resolutionManifest.addPassthroughPath(
@@ -273,9 +269,7 @@ protected void authorizeCollectionOfTableLikeOperationOrThrow(
273269
PolarisAuthorizableOperation op,
274270
final PolarisEntitySubType subType,
275271
List<TableIdentifier> ids) {
276-
resolutionManifest =
277-
resolutionManifestFactory.createResolutionManifest(
278-
callContext, securityContext, catalogName);
272+
resolutionManifest = newResolutionManifest();
279273
ids.forEach(
280274
identifier ->
281275
resolutionManifest.addPassthroughPath(
@@ -325,9 +319,7 @@ protected void authorizeRenameTableLikeOperationOrThrow(
325319
PolarisEntitySubType subType,
326320
TableIdentifier src,
327321
TableIdentifier dst) {
328-
resolutionManifest =
329-
resolutionManifestFactory.createResolutionManifest(
330-
callContext, securityContext, catalogName);
322+
resolutionManifest = newResolutionManifest();
331323
// Add src, dstParent, and dst(optional)
332324
resolutionManifest.addPath(
333325
new ResolverPath(

runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ private <T extends PolarisEntity & LocationBasedEntity> void validateNoLocationO
12251225
PolarisResolutionManifest resolutionManifest =
12261226
new PolarisResolutionManifest(
12271227
diagnostics,
1228-
callContext,
1228+
callContext.getRealmContext(),
12291229
resolverFactory,
12301230
securityContext,
12311231
parentPath.getFirst().getName());

runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public Response getConfig(
800800
if (warehouse == null) {
801801
throw new BadRequestException("Please specify a warehouse");
802802
}
803-
Resolver resolver = resolverFactory.createResolver(callContext, securityContext, warehouse);
803+
Resolver resolver = resolverFactory.createResolver(securityContext, warehouse);
804804
ResolverStatus resolverStatus = resolver.resolveAll();
805805
if (!resolverStatus.getStatus().equals(ResolverStatus.StatusEnum.SUCCESS)) {
806806
throw new NotFoundException("Unable to find warehouse %s", warehouse);

runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ public GetApplicablePoliciesResponse getApplicablePolicies(
165165

166166
private void authorizeBasicPolicyOperationOrThrow(
167167
PolarisAuthorizableOperation op, PolicyIdentifier identifier) {
168-
resolutionManifest =
169-
resolutionManifestFactory.createResolutionManifest(
170-
callContext, securityContext, catalogName);
168+
resolutionManifest = newResolutionManifest();
171169
resolutionManifest.addPassthroughPath(
172170
new ResolverPath(
173171
PolarisCatalogHelpers.identifierToList(identifier.getNamespace(), identifier.getName()),
@@ -215,9 +213,7 @@ private void authorizeGetApplicablePoliciesOperationOrThrow(
215213
}
216214

217215
private void authorizeBasicCatalogOperationOrThrow(PolarisAuthorizableOperation op) {
218-
resolutionManifest =
219-
resolutionManifestFactory.createResolutionManifest(
220-
callContext, securityContext, catalogName);
216+
resolutionManifest = newResolutionManifest();
221217
resolutionManifest.resolveAll();
222218

223219
PolarisResolvedPathWrapper targetCatalog =
@@ -237,9 +233,7 @@ private void authorizeBasicCatalogOperationOrThrow(PolarisAuthorizableOperation
237233

238234
private void authorizePolicyMappingOperationOrThrow(
239235
PolicyIdentifier identifier, PolicyAttachmentTarget target, boolean isAttach) {
240-
resolutionManifest =
241-
resolutionManifestFactory.createResolutionManifest(
242-
callContext, securityContext, catalogName);
236+
resolutionManifest = newResolutionManifest();
243237
resolutionManifest.addPassthroughPath(
244238
new ResolverPath(
245239
PolarisCatalogHelpers.identifierToList(identifier.getNamespace(), identifier.getName()),

0 commit comments

Comments
 (0)