adutra commented on code in PR #570:
URL: https://github.com/apache/polaris/pull/570#discussion_r1888131631
##########
service/common/src/main/java/org/apache/polaris/service/auth/JWTSymmetricKeyFactory.java:
##########
@@ -19,56 +19,58 @@
package org.apache.polaris.service.auth;
import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.Nullable;
import jakarta.inject.Inject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Objects;
import java.util.function.Supplier;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
@Identifier("symmetric-key")
public class JWTSymmetricKeyFactory implements TokenBrokerFactory {
- @Inject private MetaStoreManagerFactory metaStoreManagerFactory;
- private int maxTokenGenerationInSeconds = 3600;
- private String file;
- private String secret;
+
+ private final MetaStoreManagerFactory metaStoreManagerFactory;
+ private final Config config;
+
+ @Inject
+ public JWTSymmetricKeyFactory(MetaStoreManagerFactory
metaStoreManagerFactory, Config config) {
+ this.metaStoreManagerFactory = metaStoreManagerFactory;
+ this.config = config;
+ }
@Override
public TokenBroker apply(RealmContext realmContext) {
- if (file == null && secret == null) {
+ String secret = config.secret();
Review Comment:
I guess this check can be moved to the constructor.
##########
service/common/src/main/java/org/apache/polaris/service/auth/JWTRSAKeyPairFactory.java:
##########
@@ -25,18 +25,24 @@
@Identifier("rsa-key-pair")
public class JWTRSAKeyPairFactory implements TokenBrokerFactory {
- private int maxTokenGenerationInSeconds = 3600;
- @Inject private MetaStoreManagerFactory metaStoreManagerFactory;
+ private final Config config;
+ private final MetaStoreManagerFactory metaStoreManagerFactory;
- public void setMaxTokenGenerationInSeconds(int maxTokenGenerationInSeconds) {
- this.maxTokenGenerationInSeconds = maxTokenGenerationInSeconds;
+ @Inject
+ public JWTRSAKeyPairFactory(Config config, MetaStoreManagerFactory
metaStoreManagerFactory) {
+ this.config = config;
+ this.metaStoreManagerFactory = metaStoreManagerFactory;
}
@Override
public TokenBroker apply(RealmContext realmContext) {
return new JWTRSAKeyPair(
metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext),
- maxTokenGenerationInSeconds);
+ config.maxTokenGenerationInSeconds());
+ }
+
+ public interface Config {
Review Comment:
Would it be better / simpler to have one config interface for all token
broker factories?
##########
dropwizard/service/src/main/java/org/apache/polaris/service/dropwizard/config/TokenBrokerConfig.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.dropwizard.config;
+
+import jakarta.annotation.Nullable;
+import org.apache.polaris.service.auth.JWTRSAKeyPairFactory;
+import org.apache.polaris.service.auth.JWTSymmetricKeyFactory;
+
+public class TokenBrokerConfig
+ implements JWTSymmetricKeyFactory.Config, JWTRSAKeyPairFactory.Config {
+ private String type = "none";
+ private int maxTokenGenerationInSeconds = 3600;
+ private String file;
+ private String secret;
+
+ public String getType() {
Review Comment:
Or a `@JsonCreator` constructor?
--
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]