// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.rpc.security;

import com.google.inject.Inject;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.security.NodeIdentifier;
import com.yahoo.container.di.componentgraph.Provider;
import com.yahoo.security.tls.TransportSecurityUtils;
import com.yahoo.vespa.config.server.host.HostRegistry;
import com.yahoo.vespa.config.server.rpc.RequestHandlerProvider;

/**
 * A provider for {@link RpcAuthorizer}. The instance provided is dependent on the configuration of the configserver.
 *
 * @author bjorncs
 */
public class DefaultRpcAuthorizerProvider implements Provider<RpcAuthorizer> {

    private final RpcAuthorizer rpcAuthorizer;

    @Inject
    public DefaultRpcAuthorizerProvider(ConfigserverConfig config,
                                        NodeIdentifier nodeIdentifier,
                                        HostRegistry hostRegistry,
                                        RequestHandlerProvider handlerProvider) {
        boolean useMultiTenantAuthorizer =
                TransportSecurityUtils.isTransportSecurityEnabled() && config.multitenant() && config.hostedVespa();
        this.rpcAuthorizer =
                useMultiTenantAuthorizer
                        ? new MultiTenantRpcAuthorizer(nodeIdentifier, hostRegistry, handlerProvider, getThreadPoolSize(config))
                        : new NoopRpcAuthorizer();
    }

    private static int getThreadPoolSize(ConfigserverConfig config) {
        return config.numRpcThreads() != 0 ? config.numRpcThreads() : 8;
    }

    @Override
    public RpcAuthorizer get() {
        return rpcAuthorizer;
    }

    @Override
    public void deconstruct() {}
}

@@ -246,103 +246,8 @@
 ig;%0A
-import com.yahoo.config.provision.ApplicationId;%0Aimport com.yahoo.config.provision.TenantName;%0A
 impo
@@ -297,24 +297,24 @@
 Identifier;%0A
+
 import com.y
@@ -451,16 +451,22 @@
 ver.
-host.Hos
+GlobalComponen
 tReg
@@ -1008,11 +1008,22 @@
     
-Hos
+GlobalComponen
 tReg
@@ -1028,19 +1028,24 @@
 egistry 
-hos
+componen
 tRegistr
@@ -1430,16 +1430,34 @@
 tifier, 
+componentRegistry.
 hostRegi
@@ -1460,16 +1460,18 @@
 Registry
+()
 , handle

Make sure to use the same host registry in DefaultRpcAuthorizerProvider