dimas-b commented on code in PR #2680: URL: https://github.com/apache/polaris/pull/2680#discussion_r2453387664
########## extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerFactory.java: ########## @@ -0,0 +1,176 @@ +/* + * 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.extension.auth.opa; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.smallrye.common.annotation.Identifier; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import java.io.IOException; +import java.net.URI; +import java.time.Clock; +import java.time.Duration; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.polaris.core.auth.PolarisAuthorizer; +import org.apache.polaris.core.auth.PolarisAuthorizerFactory; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.extension.auth.opa.token.BearerTokenProvider; +import org.apache.polaris.extension.auth.opa.token.FileBearerTokenProvider; +import org.apache.polaris.extension.auth.opa.token.StaticBearerTokenProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Factory for creating OPA-based Polaris authorizer implementations. */ +@ApplicationScoped +@Identifier("opa") +class OpaPolarisAuthorizerFactory implements PolarisAuthorizerFactory { + + private static final Logger logger = LoggerFactory.getLogger(OpaPolarisAuthorizerFactory.class); + + private final OpaAuthorizationConfig opaConfig; + private final Clock clock; + private CloseableHttpClient httpClient; + private BearerTokenProvider bearerTokenProvider; + private ObjectMapper objectMapper; + + @Inject + public OpaPolarisAuthorizerFactory(OpaAuthorizationConfig opaConfig, Clock clock) { + this.opaConfig = opaConfig; + this.clock = clock; + this.objectMapper = new ObjectMapper(); + } + + /** + * Gets the OPA authorization configuration. Used by OpaProductionReadinessCheck + * + * @return the OPA configuration + */ + OpaAuthorizationConfig getConfig() { + return opaConfig; + } + + @PostConstruct + public void initialize() { + // Validate configuration once during startup + opaConfig.validate(); + + // Create HTTP client once during startup + httpClient = createHttpClient(); + + // Setup authentication once during startup + setupAuthentication(opaConfig.auth()); Review Comment: fair point :+1: -- 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]
