Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.time.Clock;
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisCredentialsBootstrap;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
Expand Down Expand Up @@ -71,16 +71,16 @@ protected PolarisEclipseLinkStore createBackingStore(@Nonnull PolarisDiagnostics
@Override
protected PolarisMetaStoreSession createMetaStoreSession(
@Nonnull PolarisEclipseLinkStore store,
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nullable PolarisCredentialsBootstrap credentialsBootstrap,
@Nonnull PolarisDiagnostics diagnostics) {
return new PolarisEclipseLinkMetaStoreSessionImpl(
store,
storageIntegrationProvider,
realmId,
realm,
configurationFile(),
persistenceUnitName(),
secretsGenerator(realmId, credentialsBootstrap),
secretsGenerator(realm, credentialsBootstrap),
diagnostics);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisChangeTrackingVersions;
import org.apache.polaris.core.entity.PolarisEntitiesActiveKey;
Expand Down Expand Up @@ -88,21 +88,21 @@ public class PolarisEclipseLinkMetaStoreSessionImpl implements PolarisMetaStoreS
*
* @param store Backing store of EclipseLink implementation
* @param storageIntegrationProvider Storage integration provider
* @param realmId Realm context used to communicate with different database.
* @param realm Realm used to communicate with different database.
* @param confFile Optional EclipseLink configuration file. Default to 'META-INF/persistence.xml'.
* @param persistenceUnitName Optional persistence-unit name in confFile. Default to 'polaris'.
*/
public PolarisEclipseLinkMetaStoreSessionImpl(
@Nonnull PolarisEclipseLinkStore store,
@Nonnull PolarisStorageIntegrationProvider storageIntegrationProvider,
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nullable String confFile,
@Nullable String persistenceUnitName,
@Nonnull PrincipalSecretsGenerator secretsGenerator,
@Nonnull PolarisDiagnostics diagnostics) {
this.diagnostics = diagnostics;
LOGGER.debug("Creating EclipseLink Meta Store Session for realm {}", realmId.id());
emf = createEntityManagerFactory(realmId, confFile, persistenceUnitName);
LOGGER.debug("Creating EclipseLink Meta Store Session for realm {}", realm.name());
emf = createEntityManagerFactory(realm, confFile, persistenceUnitName);

// init store
this.store = store;
Expand All @@ -120,16 +120,15 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
* realm.
*/
private EntityManagerFactory createEntityManagerFactory(
@Nonnull RealmId realmId, @Nullable String confFile, @Nullable String persistenceUnitName) {
String realm = realmId.id();
@Nonnull Realm realm, @Nullable String confFile, @Nullable String persistenceUnitName) {
return realmFactories.computeIfAbsent(
realm,
realm.name(),
key -> {
try {
PolarisEclipseLinkPersistenceUnit persistenceUnit =
PolarisEclipseLinkPersistenceUnit.locatePersistenceUnit(
confFile, persistenceUnitName);
return persistenceUnit.createEntityManagerFactory(realmId);
return persistenceUnit.createEntityManagerFactory(realm);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.ClasspathResourcePolarisEclipseLinkPersistenceUnit;
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.FileSystemPolarisEclipseLinkPersistenceUnit;
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.JarFilePolarisEclipseLinkPersistenceUnit;
Expand All @@ -57,15 +57,15 @@ sealed interface PolarisEclipseLinkPersistenceUnit
FileSystemPolarisEclipseLinkPersistenceUnit,
JarFilePolarisEclipseLinkPersistenceUnit {

EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException;
EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException;

record ClasspathResourcePolarisEclipseLinkPersistenceUnit(
URL resource, String resourceName, String persistenceUnitName)
implements PolarisEclipseLinkPersistenceUnit {

@Override
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
Map<String, String> properties = loadProperties(resource, persistenceUnitName, realmId);
public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException {
Map<String, String> properties = loadProperties(resource, persistenceUnitName, realm);
properties.put(ECLIPSELINK_PERSISTENCE_XML, resourceName);
return Persistence.createEntityManagerFactory(persistenceUnitName, properties);
}
Expand All @@ -75,9 +75,9 @@ record FileSystemPolarisEclipseLinkPersistenceUnit(Path path, String persistence
implements PolarisEclipseLinkPersistenceUnit {

@Override
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException {
Map<String, String> properties =
loadProperties(path.toUri().toURL(), persistenceUnitName, realmId);
loadProperties(path.toUri().toURL(), persistenceUnitName, realm);
Path archiveDirectory = path.getParent();
String descriptorPath = archiveDirectory.getParent().relativize(path).toString();
properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath);
Expand All @@ -99,8 +99,8 @@ record JarFilePolarisEclipseLinkPersistenceUnit(
implements PolarisEclipseLinkPersistenceUnit {

@Override
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
Map<String, String> properties = loadProperties(confUrl, persistenceUnitName, realmId);
public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException {
Map<String, String> properties = loadProperties(confUrl, persistenceUnitName, realm);
properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath);
ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
try (URLClassLoader currentClassLoader =
Expand Down Expand Up @@ -180,7 +180,7 @@ private static URL classpathResource(String resourceName) throws IOException {

/** Load the persistence unit properties from a given configuration file */
private static Map<String, String> loadProperties(
@Nonnull URL confFile, @Nonnull String persistenceUnitName, @Nonnull RealmId realmId)
@Nonnull URL confFile, @Nonnull String persistenceUnitName, @Nonnull Realm realm)
throws IOException {
try (InputStream input = confFile.openStream()) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Expand All @@ -200,7 +200,7 @@ private static Map<String, String> loadProperties(
}
// Replace database name in JDBC URL with realm
if (properties.containsKey(JDBC_URL)) {
properties.put(JDBC_URL, properties.get(JDBC_URL).replace("{realm}", realmId.id()));
properties.put(JDBC_URL, properties.get(JDBC_URL).replace("{realm}", realm.name()));
}
return properties;
} catch (XPathExpressionException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl;
Expand Down Expand Up @@ -101,13 +101,13 @@ static void deleteConfFiles() throws IOException {
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices);
RealmId realmId = RealmId.newRealmId("realm");
Realm realm = Realm.fromName("realm");
PolarisMetaStoreSession session =
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), realmId, null, "polaris", RANDOM_SECRETS, diagServices);
store, Mockito.mock(), realm, null, "polaris", RANDOM_SECRETS, diagServices);
return new PolarisTestMetaStoreManager(
new PolarisMetaStoreManagerImpl(
realmId,
realm,
diagServices,
new PolarisConfigurationStore() {},
timeSource.withZone(ZoneId.systemDefault())),
Expand All @@ -128,7 +128,7 @@ void testCreateStoreSession(String confFile, boolean success) {
new PolarisEclipseLinkMetaStoreSessionImpl(
store,
Mockito.mock(),
RealmId.newRealmId("realm"),
Realm.fromName("realm"),
confFile,
"polaris",
RANDOM_SECRETS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* the provided admin credentials or create new principals.
*/
public interface Server extends AutoCloseable {
String realmId();
String realm();

/**
* The base URI to all Polaris APIs (e.g. the common base of the Iceberg REST API endpoints and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static class Env implements CloseableResource {

private Env(Server server) {
this.server = server;
this.endpoints = new PolarisApiEndpoints(server.baseUri(), server.realmId());
this.endpoints = new PolarisApiEndpoints(server.baseUri(), server.realm());
}

PolarisApiEndpoints endpoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public interface PolarisServerManager {
* Returns server connection parameters for the tests under the specified context.
*
* <p>Implementations may reuse the same server for multiple contexts (with the same of different
* {@link Server#realmId() realm IDs}) or create a fresh server for each context. In any case,
* {@link Server#close()} will be invoked when the context provided as the argument to this call
* is closed.
* {@link Server#realm() realm}) or create a fresh server for each context. In any case, {@link
* Server#close()} will be invoked when the context provided as the argument to this call is
* closed.
*
* <p>Note: {@link Server} objects are generally attached to the test {@code class} context, but
* this is not guaranteed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.entity.CatalogEntity;

/**
Expand All @@ -35,11 +35,11 @@ public interface PolarisConfigurationStore {
* Retrieve the current value for a configuration key. May be null if not set.
*
* @param <T> the type of the configuration value
* @param realmId the realm context to check for overrides; may be null.
* @param realm the realm to check for overrides; may be null.
* @param configName the name of the configuration key to check
* @return the current value set for the configuration key or null if not set
*/
default <T> @Nullable T getConfiguration(@Nullable RealmId realmId, String configName) {
default <T> @Nullable T getConfiguration(@Nullable Realm realm, String configName) {
return null;
}

Expand All @@ -48,15 +48,15 @@ public interface PolarisConfigurationStore {
* value.
*
* @param <T> the type of the configuration value
* @param realmId the realm context to check for overrides; may be null.
* @param realm the realm to check for overrides; may be null.
* @param configName the name of the configuration key to check
* @param defaultValue the default value if the configuration key has no value
* @return the current value or the supplied default value
*/
default <T> @Nonnull T getConfiguration(
@Nullable RealmId realmId, String configName, @Nonnull T defaultValue) {
@Nullable Realm realm, String configName, @Nonnull T defaultValue) {
Preconditions.checkNotNull(defaultValue, "Cannot pass null as a default value");
T configValue = getConfiguration(realmId, configName);
T configValue = getConfiguration(realm, configName);
return configValue != null ? configValue : defaultValue;
}

Expand Down Expand Up @@ -88,13 +88,12 @@ public interface PolarisConfigurationStore {
* Retrieve the current value for a configuration.
*
* @param <T> the type of the configuration value
* @param realmId the realm context to check for overrides; may be null.
* @param realm the realm to check for overrides; may be null.
* @param config the configuration to load
* @return the current value set for the configuration key or null if not set
*/
default <T> @Nonnull T getConfiguration(
@Nullable RealmId realmId, PolarisConfiguration<T> config) {
T result = getConfiguration(realmId, config.key, config.defaultValue);
default <T> @Nonnull T getConfiguration(@Nullable Realm realm, PolarisConfiguration<T> config) {
T result = getConfiguration(realm, config.key, config.defaultValue);
return tryCast(config, result);
}

Expand All @@ -103,20 +102,18 @@ public interface PolarisConfigurationStore {
* present.
*
* @param <T> the type of the configuration value
* @param realmId the realm context to check for overrides; may be null.
* @param realm the realm to check for overrides; may be null.
* @param catalogEntity the catalog to check for an override
* @param config the configuration to load
* @return the current value set for the configuration key or null if not set
*/
default <T> @Nonnull T getConfiguration(
@Nullable RealmId realmId,
@Nonnull CatalogEntity catalogEntity,
PolarisConfiguration<T> config) {
@Nullable Realm realm, @Nonnull CatalogEntity catalogEntity, PolarisConfiguration<T> config) {
if (config.hasCatalogConfig()
&& catalogEntity.getPropertiesAsMap().containsKey(config.catalogConfig())) {
return tryCast(config, catalogEntity.getPropertiesAsMap().get(config.catalogConfig()));
} else {
return getConfiguration(realmId, config);
return getConfiguration(realm, config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Set;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;

/** Interface for invoking authorization checks. */
public interface PolarisAuthorizer {

void authorizeOrThrow(
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable PolarisResolvedPathWrapper target,
@Nullable PolarisResolvedPathWrapper secondary);

void authorizeOrThrow(
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.polaris.core.PolarisConfiguration;
import org.apache.polaris.core.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmId;
import org.apache.polaris.core.context.Realm;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisEntityCore;
Expand Down Expand Up @@ -487,14 +487,14 @@ public boolean matchesOrIsSubsumedBy(

@Override
public void authorizeOrThrow(
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable PolarisResolvedPathWrapper target,
@Nullable PolarisResolvedPathWrapper secondary) {
authorizeOrThrow(
realmId,
realm,
authenticatedPrincipal,
activatedEntities,
authzOp,
Expand All @@ -504,15 +504,15 @@ public void authorizeOrThrow(

@Override
public void authorizeOrThrow(
@Nonnull RealmId realmId,
@Nonnull Realm realm,
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
@Nonnull Set<PolarisBaseEntity> activatedEntities,
@Nonnull PolarisAuthorizableOperation authzOp,
@Nullable List<PolarisResolvedPathWrapper> targets,
@Nullable List<PolarisResolvedPathWrapper> secondaries) {
boolean enforceCredentialRotationRequiredState =
featureConfig.getConfiguration(
realmId, PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
realm, PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
if (enforceCredentialRotationRequiredState
&& authenticatedPrincipal
.getPrincipalEntity()
Expand Down
Loading