Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultContextResolver should respect the defaultRealm configuration #309

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -91,6 +91,7 @@ public void setPolarisAuthenticator(
}

public RealmContextResolver getRealmContextResolver() {
realmContextResolver.setDefaultRealm(this.defaultRealm);
return realmContextResolver;
}

Expand Down Expand Up @@ -125,6 +126,7 @@ public String getDefaultRealm() {
@JsonProperty("defaultRealm")
public void setDefaultRealm(String defaultRealm) {
this.defaultRealm = defaultRealm;
realmContextResolver.setDefaultRealm(defaultRealm);
}

@JsonProperty("cors")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@
* <p>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";
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";
Expand Down Expand Up @@ -92,10 +91,8 @@ 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "default-realm";

public abstract RealmContext resolveRealmContext(
String requestURL,
String method,
String path,
Map<String, String> queryParams,
Map<String, String> headers);

public final void setDefaultRealm(String defaultRealm) {
this.defaultRealm = defaultRealm;
}

public final String getDefaultRealm() {
return this.defaultRealm;
}
}
Loading