snazy commented on code in PR #848:
URL: https://github.com/apache/polaris/pull/848#discussion_r1930961344


##########
service/common/src/main/java/org/apache/polaris/service/context/RealmContextConfiguration.java:
##########
@@ -33,6 +33,16 @@ public interface RealmContextConfiguration {
   /** The header name that contains the realm identifier. */
   String headerName();
 
+  /**
+   * Whether to require the realm header to be present in the request. If this 
is true and the realm
+   * header is not present, the request will be rejected. If this is false and 
the realm header is
+   * not present, the default realm will be used.
+   *
+   * <p>Note: this is actually only enforced when using {@link 
DefaultRealmIdResolver}. When using
+   * {@link TestRealmIdResolver}, this setting is ignored.
+   */
+  boolean requireHeader();

Review Comment:
   Should this be true by default?



##########
integration-tests/src/main/java/org/apache/polaris/service/it/env/PolarisApiEndpoints.java:
##########
@@ -49,4 +49,8 @@ public URI managementApiEndpoint() {
   public String realm() {
     return realm;
   }
+
+  public String realmHeader() {

Review Comment:
   Maybe rename to `realmHeaderName()` + `realmId()` (latter for consistency w/ 
`Server`)?



##########
service/common/src/main/java/org/apache/polaris/service/context/RealmContextConfiguration.java:
##########
@@ -33,6 +33,16 @@ public interface RealmContextConfiguration {
   /** The header name that contains the realm identifier. */
   String headerName();
 
+  /**
+   * Whether to require the realm header to be present in the request. If this 
is true and the realm
+   * header is not present, the request will be rejected. If this is false and 
the realm header is
+   * not present, the default realm will be used.
+   *
+   * <p>Note: this is actually only enforced when using {@link 
DefaultRealmIdResolver}. When using
+   * {@link TestRealmIdResolver}, this setting is ignored.

Review Comment:
   ```suggestion
      * <p>Note: this setting is only enforced in production setups. 
   ```



##########
service/common/src/main/java/org/apache/polaris/service/context/RealmIdFilter.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.context;
+
+import jakarta.annotation.Priority;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.ext.Provider;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polaris.core.context.RealmId;
+import org.apache.polaris.service.config.PolarisFilterPriorities;
+
+@PreMatching
+@ApplicationScoped
+@Priority(PolarisFilterPriorities.REALM_ID_FILTER)
+@Provider
+public class RealmIdFilter implements ContainerRequestFilter {
+
+  public static final String REALM_ID_KEY = "realmId";
+
+  @Inject RealmIdResolver realmIdResolver;
+
+  @Override
+  public void filter(ContainerRequestContext rc) {
+    RealmId realmId =
+        realmIdResolver.resolveRealmId(
+            rc.getUriInfo().getRequestUri().toString(),
+            rc.getMethod(),
+            rc.getUriInfo().getPath(),
+            rc.getHeaders().entrySet().stream()
+                .collect(
+                    HashMap::new,
+                    (m, e) -> m.put(e.getKey(), e.getValue().getFirst()),
+                    Map::putAll));

Review Comment:
   Wonder if it makes more sense to change `RealmIdResolver` to expect a 
`Function<String, String>` rather than a "full blown map" (and use 
`request::getHeader` here).



##########
integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.java:
##########
@@ -36,4 +39,8 @@ public interface Server extends AutoCloseable {
   URI baseUri();
 
   ClientPrincipal adminCredentials();
+
+  default String realmHeader() {

Review Comment:
   ```suggestion
     default String realmHeaderName() {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to