From 3b549fb86ed08cfdc0c830b83dc499520860b80b Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Thu, 19 Sep 2024 14:55:56 -0700 Subject: [PATCH 1/8] apply fix --- .../apache/polaris/service/PolarisApplication.java | 12 +++++++++--- .../service/config/PolarisApplicationConfig.java | 1 + .../service/context/DefaultContextResolver.java | 5 ++--- .../service/context/RealmContextResolver.java | 14 ++++++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) 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 5706fb272..ddd6a9b53 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 @@ -34,6 +34,7 @@ import io.dropwizard.configuration.EnvironmentVariableSubstitutor; import io.dropwizard.configuration.SubstitutingSourceProvider; import io.dropwizard.core.Application; +import io.dropwizard.core.Configuration; import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; import io.micrometer.prometheusmetrics.PrometheusConfig; @@ -187,7 +188,7 @@ public void run(PolarisApplicationConfig configuration, Environment environment) environment .servlets() .addFilter( - "realmContext", new ContextResolverFilter(realmContextResolver, callContextResolver)) + "realmContext", new ContextResolverFilter(realmContextResolver, callContextResolver, configuration)) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FileIOFactory fileIOFactory = configuration.getFileIOFactory(); @@ -346,11 +347,15 @@ private static OpenTelemetry setupTracing() { private static class ContextResolverFilter implements Filter { private final RealmContextResolver realmContextResolver; private final CallContextResolver callContextResolver; + private final PolarisApplicationConfig configuration; public ContextResolverFilter( - RealmContextResolver realmContextResolver, CallContextResolver callContextResolver) { + RealmContextResolver realmContextResolver, + CallContextResolver callContextResolver, + PolarisApplicationConfig configuration) { this.realmContextResolver = realmContextResolver; this.callContextResolver = callContextResolver; + this.configuration = configuration; } @Override @@ -368,7 +373,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha request.getParameterMap().entrySet().stream() .collect( Collectors.toMap(Map.Entry::getKey, (e) -> ((String[]) e.getValue())[0])), - headers); + headers, + configuration.getDefaultRealm()); CallContext currentCallContext = callContextResolver.resolveCallContext( currentRealmContext, diff --git a/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java b/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java index 56b83b972..311142b34 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java @@ -91,6 +91,7 @@ public void setPolarisAuthenticator( } public RealmContextResolver getRealmContextResolver() { + realmContextResolver.setDefaultRealm(this.defaultRealm); return realmContextResolver; } diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java index b171a5981..b4408471c 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java @@ -49,7 +49,6 @@ public class DefaultContextResolver private static final Logger LOGGER = LoggerFactory.getLogger(DefaultContextResolver.class); public static final String REALM_PROPERTY_KEY = "realm"; - public static final String REALM_PROPERTY_DEFAULT_VALUE = "default-realm"; public static final String PRINCIPAL_PROPERTY_KEY = "principal"; public static final String PRINCIPAL_PROPERTY_DEFAULT_VALUE = "default-principal"; @@ -94,8 +93,8 @@ public RealmContext resolveRealmContext( LOGGER.warn( "Failed to parse {} from headers; using {}", REALM_PROPERTY_KEY, - REALM_PROPERTY_DEFAULT_VALUE); - parsedProperties.put(REALM_PROPERTY_KEY, REALM_PROPERTY_DEFAULT_VALUE); + getDefaultRealm()); + parsedProperties.put(REALM_PROPERTY_KEY, getDefaultRealm()); } return () -> parsedProperties.get(REALM_PROPERTY_KEY); } diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java index 14759431d..2262529a5 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java @@ -25,11 +25,21 @@ import org.apache.polaris.service.config.HasEntityManagerFactory; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") -public interface RealmContextResolver extends Discoverable, HasEntityManagerFactory { - RealmContext resolveRealmContext( +public abstract class RealmContextResolver implements Discoverable, HasEntityManagerFactory { + private String defaultRealm; + + public abstract RealmContext resolveRealmContext( String requestURL, String method, String path, Map queryParams, Map headers); + + public final void setDefaultRealm(String defaultRealm) { + this.defaultRealm = defaultRealm; + } + + public final String getDefaultRealm() { + return this.defaultRealm; + } } From 9d3f890a91428753d978ca436c47a6b9654bf707 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Thu, 19 Sep 2024 14:56:15 -0700 Subject: [PATCH 2/8] autolint --- .../java/org/apache/polaris/service/PolarisApplication.java | 4 ++-- .../polaris/service/context/DefaultContextResolver.java | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) 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 ddd6a9b53..61b4de2c0 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 @@ -34,7 +34,6 @@ import io.dropwizard.configuration.EnvironmentVariableSubstitutor; import io.dropwizard.configuration.SubstitutingSourceProvider; import io.dropwizard.core.Application; -import io.dropwizard.core.Configuration; import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; import io.micrometer.prometheusmetrics.PrometheusConfig; @@ -188,7 +187,8 @@ public void run(PolarisApplicationConfig configuration, Environment environment) environment .servlets() .addFilter( - "realmContext", new ContextResolverFilter(realmContextResolver, callContextResolver, configuration)) + "realmContext", + new ContextResolverFilter(realmContextResolver, callContextResolver, configuration)) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FileIOFactory fileIOFactory = configuration.getFileIOFactory(); diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java index b4408471c..c37863406 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java @@ -91,9 +91,7 @@ public RealmContext resolveRealmContext( if (!parsedProperties.containsKey(REALM_PROPERTY_KEY)) { LOGGER.warn( - "Failed to parse {} from headers; using {}", - REALM_PROPERTY_KEY, - getDefaultRealm()); + "Failed to parse {} from headers; using {}", REALM_PROPERTY_KEY, getDefaultRealm()); parsedProperties.put(REALM_PROPERTY_KEY, getDefaultRealm()); } return () -> parsedProperties.get(REALM_PROPERTY_KEY); From 9961af553f8b94ca8da34b7d400a32123b3c8104 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Thu, 19 Sep 2024 14:59:10 -0700 Subject: [PATCH 3/8] be extra safe --- .../polaris/service/config/PolarisApplicationConfig.java | 1 + .../polaris/service/context/DefaultContextResolver.java | 4 ++-- .../apache/polaris/service/context/RealmContextResolver.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java b/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java index 311142b34..4d72d7e36 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/config/PolarisApplicationConfig.java @@ -126,6 +126,7 @@ public String getDefaultRealm() { @JsonProperty("defaultRealm") public void setDefaultRealm(String defaultRealm) { this.defaultRealm = defaultRealm; + realmContextResolver.setDefaultRealm(defaultRealm); } @JsonProperty("cors") diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java index c37863406..4f60f1017 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java @@ -44,8 +44,8 @@ *

Example: principal:data-engineer;password:test;realm:acct123 */ @JsonTypeName("default") -public class DefaultContextResolver - implements RealmContextResolver, CallContextResolver, ConfigurationStoreAware { +public class DefaultContextResolver extends RealmContextResolver + implements CallContextResolver, ConfigurationStoreAware { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultContextResolver.class); public static final String REALM_PROPERTY_KEY = "realm"; diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java index 2262529a5..d7413768d 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java @@ -26,7 +26,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") public abstract class RealmContextResolver implements Discoverable, HasEntityManagerFactory { - private String defaultRealm; + private String defaultRealm = "default-realm"; public abstract RealmContext resolveRealmContext( String requestURL, From 59bb502d7ee76eecb042d8898967d38e06d67e61 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Thu, 19 Sep 2024 15:01:47 -0700 Subject: [PATCH 4/8] simplify --- .../apache/polaris/service/PolarisApplication.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) 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 61b4de2c0..eab824748 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 @@ -187,8 +187,7 @@ public void run(PolarisApplicationConfig configuration, Environment environment) environment .servlets() .addFilter( - "realmContext", - new ContextResolverFilter(realmContextResolver, callContextResolver, configuration)) + "realmContext", new ContextResolverFilter(realmContextResolver, callContextResolver)) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FileIOFactory fileIOFactory = configuration.getFileIOFactory(); @@ -347,15 +346,12 @@ private static OpenTelemetry setupTracing() { private static class ContextResolverFilter implements Filter { private final RealmContextResolver realmContextResolver; private final CallContextResolver callContextResolver; - private final PolarisApplicationConfig configuration; public ContextResolverFilter( RealmContextResolver realmContextResolver, - CallContextResolver callContextResolver, - PolarisApplicationConfig configuration) { + CallContextResolver callContextResolver) { this.realmContextResolver = realmContextResolver; this.callContextResolver = callContextResolver; - this.configuration = configuration; } @Override @@ -373,8 +369,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha request.getParameterMap().entrySet().stream() .collect( Collectors.toMap(Map.Entry::getKey, (e) -> ((String[]) e.getValue())[0])), - headers, - configuration.getDefaultRealm()); + headers); CallContext currentCallContext = callContextResolver.resolveCallContext( currentRealmContext, From 54e1a833b7c15d78d6e3c81d0fbd31206ae9f23a Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Thu, 19 Sep 2024 15:01:51 -0700 Subject: [PATCH 5/8] autolint --- .../java/org/apache/polaris/service/PolarisApplication.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 eab824748..5706fb272 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 @@ -348,8 +348,7 @@ private static class ContextResolverFilter implements Filter { private final CallContextResolver callContextResolver; public ContextResolverFilter( - RealmContextResolver realmContextResolver, - CallContextResolver callContextResolver) { + RealmContextResolver realmContextResolver, CallContextResolver callContextResolver) { this.realmContextResolver = realmContextResolver; this.callContextResolver = callContextResolver; } From d1b8d933144e311f1d5f4b29b0cdd33abfdcbb83 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Mon, 23 Sep 2024 11:55:18 -0700 Subject: [PATCH 6/8] rebase From 0373a5a38da5693caf2bacfad748e45e529076d5 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Mon, 7 Oct 2024 12:40:07 -0700 Subject: [PATCH 7/8] revert back to interface --- .../service/context/DefaultContextResolver.java | 14 ++++++++++++-- .../service/context/RealmContextResolver.java | 13 ++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java index 4f60f1017..006805c9d 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java @@ -44,8 +44,7 @@ *

Example: principal:data-engineer;password:test;realm:acct123 */ @JsonTypeName("default") -public class DefaultContextResolver extends RealmContextResolver - implements CallContextResolver, ConfigurationStoreAware { +public class DefaultContextResolver implements RealmContextResolver, CallContextResolver, ConfigurationStoreAware { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultContextResolver.class); public static final String REALM_PROPERTY_KEY = "realm"; @@ -55,6 +54,7 @@ public class DefaultContextResolver extends RealmContextResolver private RealmEntityManagerFactory entityManagerFactory; private PolarisConfigurationStore configurationStore; + private String defaultRealm = "default-realm"; /** * During CallContext resolution that might depend on RealmContext, the {@code @@ -97,6 +97,16 @@ public RealmContext resolveRealmContext( return () -> parsedProperties.get(REALM_PROPERTY_KEY); } + @Override + public void setDefaultRealm(String defaultRealm) { + this.defaultRealm = defaultRealm; + } + + @Override + public String getDefaultRealm() { + return this.defaultRealm; + } + @Override public CallContext resolveCallContext( final RealmContext realmContext, diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java index d7413768d..43c448012 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/RealmContextResolver.java @@ -25,21 +25,16 @@ import org.apache.polaris.service.config.HasEntityManagerFactory; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") -public abstract class RealmContextResolver implements Discoverable, HasEntityManagerFactory { - private String defaultRealm = "default-realm"; +public interface RealmContextResolver extends Discoverable, HasEntityManagerFactory { - public abstract RealmContext resolveRealmContext( + RealmContext resolveRealmContext( String requestURL, String method, String path, Map queryParams, Map headers); - public final void setDefaultRealm(String defaultRealm) { - this.defaultRealm = defaultRealm; - } + void setDefaultRealm(String defaultRealm); - public final String getDefaultRealm() { - return this.defaultRealm; - } + String getDefaultRealm(); } From 1a0ac4ca6d8a72c39f4336434f418eb8818ccd7c Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Mon, 7 Oct 2024 12:40:12 -0700 Subject: [PATCH 8/8] autolint --- .../apache/polaris/service/context/DefaultContextResolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java index 006805c9d..ed0aa7084 100644 --- a/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java +++ b/polaris-service/src/main/java/org/apache/polaris/service/context/DefaultContextResolver.java @@ -44,7 +44,8 @@ *

Example: principal:data-engineer;password:test;realm:acct123 */ @JsonTypeName("default") -public class DefaultContextResolver implements RealmContextResolver, CallContextResolver, ConfigurationStoreAware { +public class DefaultContextResolver + implements RealmContextResolver, CallContextResolver, ConfigurationStoreAware { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultContextResolver.class); public static final String REALM_PROPERTY_KEY = "realm";