@Override protected void setup(Binder binder) { InternalCommunicationConfig internalCommunicationConfig = buildConfigObject(InternalCommunicationConfig.class); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, config -> { config.setKeyStorePath(internalCommunicationConfig.getKeyStorePath()); config.setKeyStorePassword(internalCommunicationConfig.getKeyStorePassword()); }); install(installModuleIf(InternalCommunicationConfig.class, InternalCommunicationConfig::isKerberosEnabled, kerberosInternalCommunicationModule())); }
private Module kerberosInternalCommunicationModule() { return binder -> { InternalCommunicationConfig clientKerberosConfig = buildConfigObject(InternalCommunicationConfig.class); com.facebook.presto.server.security.KerberosConfig serverKerberosConfig = buildConfigObject(com.facebook.presto.server.security.KerberosConfig.class); verify(serverKerberosConfig.getKeytab() != null, "%s must be set when %s is true", HTTP_SERVER_AUTHENTICATION_KRB5_KEYTAB, INTERNAL_COMMUNICATION_KERBEROS_ENABLED); configBinder(binder).bindConfigGlobalDefaults(KerberosConfig.class, kerberosConfig -> { kerberosConfig.setConfig(serverKerberosConfig.getKerberosConfig()); kerberosConfig.setKeytab(serverKerberosConfig.getKeytab()); kerberosConfig.setUseCanonicalHostname(clientKerberosConfig.isKerberosUseCanonicalHostname()); }); String kerberosPrincipal = serverKerberosConfig.getServiceName() + "/" + getLocalCanonicalHostName(); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, httpClientConfig -> { httpClientConfig.setAuthenticationEnabled(true); httpClientConfig.setKerberosPrincipal(kerberosPrincipal); httpClientConfig.setKerberosRemoteServiceName(serverKerberosConfig.getServiceName()); }); }; }
@Override protected void setup(Binder binder) { InternalCommunicationConfig internalCommunicationConfig = buildConfigObject(InternalCommunicationConfig.class); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, config -> { config.setKeyStorePath(internalCommunicationConfig.getKeyStorePath()); config.setKeyStorePassword(internalCommunicationConfig.getKeyStorePassword()); }); install(installModuleIf(InternalCommunicationConfig.class, InternalCommunicationConfig::isKerberosEnabled, kerberosInternalCommunicationModule())); }
@Override protected void setup(Binder binder) { InternalCommunicationConfig internalCommunicationConfig = buildConfigObject(InternalCommunicationConfig.class); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, config -> { config.setKeyStorePath(internalCommunicationConfig.getKeyStorePath()); config.setKeyStorePassword(internalCommunicationConfig.getKeyStorePassword()); }); install(installModuleIf(InternalCommunicationConfig.class, InternalCommunicationConfig::isKerberosEnabled, kerberosInternalCommunicationModule())); }
private Module kerberosInternalCommunicationModule() { return binder -> { InternalCommunicationConfig clientKerberosConfig = buildConfigObject(InternalCommunicationConfig.class); io.prestosql.server.security.KerberosConfig serverKerberosConfig = buildConfigObject(io.prestosql.server.security.KerberosConfig.class); verify(serverKerberosConfig.getKeytab() != null, "%s must be set when %s is true", HTTP_SERVER_AUTHENTICATION_KRB5_KEYTAB, INTERNAL_COMMUNICATION_KERBEROS_ENABLED); configBinder(binder).bindConfigGlobalDefaults(KerberosConfig.class, kerberosConfig -> { kerberosConfig.setConfig(serverKerberosConfig.getKerberosConfig()); kerberosConfig.setKeytab(serverKerberosConfig.getKeytab()); kerberosConfig.setUseCanonicalHostname(clientKerberosConfig.isKerberosUseCanonicalHostname()); }); String kerberosPrincipal = serverKerberosConfig.getServiceName() + "/" + getLocalCanonicalHostName(); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, httpClientConfig -> { httpClientConfig.setAuthenticationEnabled(true); httpClientConfig.setKerberosPrincipal(kerberosPrincipal); httpClientConfig.setKerberosRemoteServiceName(serverKerberosConfig.getServiceName()); }); }; }
@Test public void testConfigGlobalDefaults() throws Exception { int globalDefaultValue = 1; int defaultValue = 2; int customValue = 3; Module module = binder -> { configBinder(binder).bindConfigGlobalDefaults(Config1.class, (config -> { config.setByteOption((byte) globalDefaultValue); config.setIntegerOption(globalDefaultValue); config.setLongOption(globalDefaultValue); })); configBinder(binder).bindConfigDefaults(Config1.class, MyAnnotation.class, (config -> { config.setIntegerOption(defaultValue); config.setLongOption(defaultValue); })); configBinder(binder).bindConfig(Config1.class, MyAnnotation.class); }; Injector injector = createInjector(ImmutableMap.of("longOption", "" + customValue), module); Config1 config = injector.getInstance(Key.get(Config1.class, MyAnnotation.class)); assertEquals(config.getByteOption(), globalDefaultValue); assertEquals(config.getIntegerOption(), defaultValue); assertEquals(config.getLongOption(), customValue); }
private Module kerberosInternalCommunicationModule() { return binder -> { InternalCommunicationConfig clientKerberosConfig = buildConfigObject(InternalCommunicationConfig.class); io.prestosql.server.security.KerberosConfig serverKerberosConfig = buildConfigObject(io.prestosql.server.security.KerberosConfig.class); verify(serverKerberosConfig.getKeytab() != null, "%s must be set when %s is true", HTTP_SERVER_AUTHENTICATION_KRB5_KEYTAB, INTERNAL_COMMUNICATION_KERBEROS_ENABLED); configBinder(binder).bindConfigGlobalDefaults(KerberosConfig.class, kerberosConfig -> { kerberosConfig.setConfig(serverKerberosConfig.getKerberosConfig()); kerberosConfig.setKeytab(serverKerberosConfig.getKeytab()); kerberosConfig.setUseCanonicalHostname(clientKerberosConfig.isKerberosUseCanonicalHostname()); }); String kerberosPrincipal = serverKerberosConfig.getServiceName() + "/" + getLocalCanonicalHostName(); configBinder(binder).bindConfigGlobalDefaults(HttpClientConfig.class, httpClientConfig -> { httpClientConfig.setAuthenticationEnabled(true); httpClientConfig.setKerberosPrincipal(kerberosPrincipal); httpClientConfig.setKerberosRemoteServiceName(serverKerberosConfig.getServiceName()); }); }; }
@Test public void testConfigGlobalDefaults() throws Exception { int globalDefaultValue = 1; int defaultValue = 2; int customValue = 3; Module module = binder -> { configBinder(binder).bindConfigGlobalDefaults(Config1.class, (config -> { config.setByteOption((byte) globalDefaultValue); config.setIntegerOption(globalDefaultValue); config.setLongOption(globalDefaultValue); })); configBinder(binder).bindConfigDefaults(Config1.class, MyAnnotation.class, (config -> { config.setIntegerOption(defaultValue); config.setLongOption(defaultValue); })); configBinder(binder).bindConfig(Config1.class, MyAnnotation.class); }; Injector injector = createInjector(ImmutableMap.of("longOption", "" + customValue), module); Config1 config = injector.getInstance(Key.get(Config1.class, MyAnnotation.class)); assertEquals(config.getByteOption(), globalDefaultValue); assertEquals(config.getIntegerOption(), defaultValue); assertEquals(config.getLongOption(), customValue); }