1818 */
1919package org .apache .polaris .service .quarkus .catalog ;
2020
21- import com .google .common .collect .ImmutableMap ;
2221import io .quarkus .test .junit .QuarkusTest ;
2322import io .quarkus .test .junit .TestProfile ;
2423import jakarta .ws .rs .core .SecurityContext ;
3433import org .apache .iceberg .SortOrder ;
3534import org .apache .iceberg .TableMetadata ;
3635import org .apache .iceberg .TableMetadataParser ;
37- import org .apache .iceberg .catalog .Catalog ;
3836import org .apache .iceberg .catalog .Namespace ;
3937import org .apache .iceberg .catalog .TableIdentifier ;
4038import org .apache .iceberg .exceptions .ForbiddenException ;
5452import org .apache .polaris .core .admin .model .PrincipalWithCredentialsCredentials ;
5553import org .apache .polaris .core .admin .model .StorageConfigInfo ;
5654import org .apache .polaris .core .auth .AuthenticatedPolarisPrincipal ;
57- import org .apache .polaris .core .context .RealmContext ;
5855import org .apache .polaris .core .entity .CatalogEntity ;
5956import org .apache .polaris .core .entity .CatalogRoleEntity ;
6057import org .apache .polaris .core .entity .PolarisPrivilege ;
6158import org .apache .polaris .core .entity .PrincipalEntity ;
6259import org .apache .polaris .core .persistence .PolarisMetaStoreManager ;
63- import org .apache .polaris .core .persistence .resolver .PolarisResolutionManifest ;
6460import org .apache .polaris .service .catalog .PolarisCatalogHandlerWrapper ;
6561import org .apache .polaris .service .catalog .io .DefaultFileIOFactory ;
66- import org .apache .polaris .service .context .CallContextCatalogFactory ;
67- import org .apache .polaris .service .context .PolarisCallContextCatalogFactory ;
6862import org .apache .polaris .service .quarkus .admin .PolarisAuthzTestBase ;
6963import org .apache .polaris .service .types .NotificationRequest ;
7064import org .apache .polaris .service .types .NotificationType ;
@@ -90,27 +84,24 @@ private PolarisCatalogHandlerWrapper newWrapper() {
9084 }
9185
9286 private PolarisCatalogHandlerWrapper newWrapper (Set <String > activatedPrincipalRoles ) {
93- return newWrapper (activatedPrincipalRoles , CATALOG_NAME , newCatalogFactory () );
87+ return newWrapper (activatedPrincipalRoles , CATALOG_NAME );
9488 }
9589
9690 private PolarisCatalogHandlerWrapper newWrapper (
97- Set <String > activatedPrincipalRoles , String catalogName , CallContextCatalogFactory factory ) {
91+ Set <String > activatedPrincipalRoles , String catalogName ) {
9892 final AuthenticatedPolarisPrincipal authenticatedPrincipal =
9993 new AuthenticatedPolarisPrincipal (principalEntity , activatedPrincipalRoles );
100- return new PolarisCatalogHandlerWrapper (
101- realmContext ,
102- metaStoreSession ,
103- configurationStore ,
104- diagServices ,
105- entityManager ,
106- metaStoreManager ,
107- securityContext (authenticatedPrincipal , activatedPrincipalRoles ),
108- factory ,
109- catalogName ,
110- polarisAuthorizer );
94+ SecurityContext securityContext =
95+ securityContext (authenticatedPrincipal , activatedPrincipalRoles );
96+ return newWrapper (securityContext , catalogName );
11197 }
11298
11399 private PolarisCatalogHandlerWrapper newWrapper (SecurityContext securityContext ) {
100+ return newWrapper (securityContext , CATALOG_NAME );
101+ }
102+
103+ private PolarisCatalogHandlerWrapper newWrapper (
104+ SecurityContext securityContext , String catalogName ) {
114105 return new PolarisCatalogHandlerWrapper (
115106 realmContext ,
116107 metaStoreSession ,
@@ -119,18 +110,8 @@ private PolarisCatalogHandlerWrapper newWrapper(SecurityContext securityContext)
119110 entityManager ,
120111 metaStoreManager ,
121112 securityContext ,
122- newCatalogFactory (),
123- CATALOG_NAME ,
124- polarisAuthorizer );
125- }
126-
127- private CallContextCatalogFactory newCatalogFactory () {
128- return new TestPolarisCallContextCatalogFactory (
129- entityManager ,
130- metaStoreManager ,
131- metaStoreSession ,
132- configurationStore ,
133- diagServices ,
113+ catalogName ,
114+ polarisAuthorizer ,
134115 Mockito .mock (),
135116 new DefaultFileIOFactory ());
136117 }
@@ -1637,6 +1618,8 @@ public void testSendNotificationSufficientPrivileges() {
16371618 .setName (externalCatalog )
16381619 .setDefaultBaseLocation (storageLocation )
16391620 .setStorageConfigurationInfo (storageConfigModel , storageLocation )
1621+ .addProperty (
1622+ CatalogProperties .FILE_IO_IMPL , "org.apache.iceberg.inmemory.InMemoryFileIO" )
16401623 .setCatalogType ("EXTERNAL" )
16411624 .build ());
16421625 adminService .createCatalogRole (
@@ -1699,48 +1682,23 @@ public void testSendNotificationSufficientPrivileges() {
16991682 validatePayload .setTimestamp (530950845L );
17001683 validateRequest .setPayload (validatePayload );
17011684
1702- PolarisCallContextCatalogFactory factory =
1703- new PolarisCallContextCatalogFactory (
1704- entityManager ,
1705- metaStoreManager ,
1706- metaStoreSession ,
1707- configurationStore ,
1708- diagServices ,
1709- Mockito .mock (),
1710- new DefaultFileIOFactory ()) {
1711- @ Override
1712- public Catalog createCallContextCatalog (
1713- RealmContext realmContext ,
1714- AuthenticatedPolarisPrincipal authenticatedPolarisPrincipal ,
1715- SecurityContext securityContext ,
1716- PolarisResolutionManifest resolvedManifest ) {
1717- Catalog catalog =
1718- super .createCallContextCatalog (
1719- realmContext , authenticatedPolarisPrincipal , securityContext , resolvedManifest );
1720- String fileIoImpl = "org.apache.iceberg.inmemory.InMemoryFileIO" ;
1721- catalog .initialize (
1722- externalCatalog , ImmutableMap .of (CatalogProperties .FILE_IO_IMPL , fileIoImpl ));
1723-
1724- try (FileIO fileIO =
1725- CatalogUtil .loadFileIO (fileIoImpl , Map .of (), new Configuration ())) {
1726- TableMetadata tableMetadata =
1727- TableMetadata .buildFromEmpty ()
1728- .addSchema (SCHEMA , SCHEMA .highestFieldId ())
1729- .setLocation (
1730- String .format (
1731- "%s/bucket/table/metadata/v1.metadata.json" , storageLocation ))
1732- .addPartitionSpec (PartitionSpec .unpartitioned ())
1733- .addSortOrder (SortOrder .unsorted ())
1734- .assignUUID ()
1735- .build ();
1736- TableMetadataParser .overwrite (
1737- tableMetadata , fileIO .newOutputFile (createPayload .getMetadataLocation ()));
1738- TableMetadataParser .overwrite (
1739- tableMetadata , fileIO .newOutputFile (updatePayload .getMetadataLocation ()));
1740- }
1741- return catalog ;
1742- }
1743- };
1685+ try (FileIO fileIO =
1686+ CatalogUtil .loadFileIO (
1687+ "org.apache.iceberg.inmemory.InMemoryFileIO" , Map .of (), new Configuration ())) {
1688+ TableMetadata tableMetadata =
1689+ TableMetadata .buildFromEmpty ()
1690+ .addSchema (SCHEMA , SCHEMA .highestFieldId ())
1691+ .setLocation (
1692+ String .format ("%s/bucket/table/metadata/v1.metadata.json" , storageLocation ))
1693+ .addPartitionSpec (PartitionSpec .unpartitioned ())
1694+ .addSortOrder (SortOrder .unsorted ())
1695+ .assignUUID ()
1696+ .build ();
1697+ TableMetadataParser .overwrite (
1698+ tableMetadata , fileIO .newOutputFile (createPayload .getMetadataLocation ()));
1699+ TableMetadataParser .overwrite (
1700+ tableMetadata , fileIO .newOutputFile (updatePayload .getMetadataLocation ()));
1701+ }
17441702
17451703 List <Set <PolarisPrivilege >> sufficientPrivilegeSets =
17461704 List .of (
@@ -1764,19 +1722,18 @@ public Catalog createCallContextCatalog(
17641722 doTestSufficientPrivilegeSets (
17651723 sufficientPrivilegeSets ,
17661724 () -> {
1767- newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog , factory )
1725+ newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog )
17681726 .sendNotification (table , createRequest );
1769- newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog , factory )
1727+ newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog )
17701728 .sendNotification (table , updateRequest );
1771- newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog , factory )
1772- .sendNotification (table , dropRequest );
1773- newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog , factory )
1729+ newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog ).sendNotification (table , dropRequest );
1730+ newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog )
17741731 .sendNotification (table , validateRequest );
17751732 },
17761733 () -> {
1777- newWrapper (Set .of (PRINCIPAL_ROLE2 ), externalCatalog , factory )
1734+ newWrapper (Set .of (PRINCIPAL_ROLE2 ), externalCatalog )
17781735 .dropNamespace (Namespace .of ("extns1" , "extns2" ));
1779- newWrapper (Set .of (PRINCIPAL_ROLE2 ), externalCatalog , factory )
1736+ newWrapper (Set .of (PRINCIPAL_ROLE2 ), externalCatalog )
17801737 .dropNamespace (Namespace .of ("extns1" ));
17811738 },
17821739 PRINCIPAL_NAME ,
@@ -1786,7 +1743,7 @@ public Catalog createCallContextCatalog(
17861743 doTestSufficientPrivilegeSets (
17871744 sufficientPrivilegeSets ,
17881745 () -> {
1789- newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog , factory )
1746+ newWrapper (Set .of (PRINCIPAL_ROLE1 ), externalCatalog )
17901747 .sendNotification (table , validateRequest );
17911748 },
17921749 null /* cleanupAction */ ,
0 commit comments