From f1d46c56c20027ff212e19a732aee88fd997fa36 Mon Sep 17 00:00:00 2001 From: Eric Maynard Date: Fri, 18 Oct 2024 21:03:54 -0400 Subject: [PATCH] DefaultContextResolver should respect the defaultRealm configuration (#309) --- .../config/PolarisApplicationConfig.java | 2 ++ .../context/DefaultContextResolver.java | 18 +++++++++++++----- .../service/context/RealmContextResolver.java | 5 +++++ 3 files changed, 20 insertions(+), 5 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 065b6d8f3..f3a089343 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 @@ -102,6 +102,7 @@ public void setPolarisAuthenticator( } public RealmContextResolver getRealmContextResolver() { + realmContextResolver.setDefaultRealm(this.defaultRealm); return realmContextResolver; } @@ -136,6 +137,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 b171a5981..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 @@ -49,13 +49,13 @@ 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"; private RealmEntityManagerFactory entityManagerFactory; private PolarisConfigurationStore configurationStore; + private String defaultRealm = "default-realm"; /** * During CallContext resolution that might depend on RealmContext, the {@code @@ -92,14 +92,22 @@ public RealmContext resolveRealmContext( if (!parsedProperties.containsKey(REALM_PROPERTY_KEY)) { LOGGER.warn( - "Failed to parse {} from headers; using {}", - REALM_PROPERTY_KEY, - REALM_PROPERTY_DEFAULT_VALUE); - parsedProperties.put(REALM_PROPERTY_KEY, REALM_PROPERTY_DEFAULT_VALUE); + "Failed to parse {} from headers; using {}", REALM_PROPERTY_KEY, getDefaultRealm()); + parsedProperties.put(REALM_PROPERTY_KEY, getDefaultRealm()); } 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 14759431d..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 @@ -26,10 +26,15 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") public interface RealmContextResolver extends Discoverable, HasEntityManagerFactory { + RealmContext resolveRealmContext( String requestURL, String method, String path, Map queryParams, Map headers); + + void setDefaultRealm(String defaultRealm); + + String getDefaultRealm(); }