Skip to content

Commit

Permalink
DefaultContextResolver should respect the defaultRealm configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-maynard authored Oct 19, 2024
1 parent 3191ea0 commit f1d46c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void setPolarisAuthenticator(
}

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

Expand Down Expand Up @@ -136,6 +137,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 @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> queryParams,
Map<String, String> headers);

void setDefaultRealm(String defaultRealm);

String getDefaultRealm();
}

0 comments on commit f1d46c5

Please sign in to comment.