You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2018/01/11 17:39:10 UTC
[43/53] [abbrv] knox git commit: KNOX-998 - Merge from trunk 0.14.0
code
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/ZooKeeperClientServiceProvider.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/ZooKeeperClientServiceProvider.java b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/ZooKeeperClientServiceProvider.java
new file mode 100644
index 0000000..96b931c
--- /dev/null
+++ b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/ZooKeeperClientServiceProvider.java
@@ -0,0 +1,34 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.service.config.remote.zk;
+
+import org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider;
+
+
+public class ZooKeeperClientServiceProvider implements RemoteConfigurationRegistryClientServiceProvider {
+
+ @Override
+ public String getType() {
+ return ZooKeeperClientService.TYPE;
+ }
+
+ @Override
+ public ZooKeeperClientService newInstance() {
+ return new CuratorClientService();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider b/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
deleted file mode 100644
index 7f2312a..0000000
--- a/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
+++ /dev/null
@@ -1,19 +0,0 @@
-##########################################################################
-# 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.
-##########################################################################
-
-org.apache.hadoop.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider b/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
new file mode 100644
index 0000000..fe12e48
--- /dev/null
+++ b/gateway-service-remoteconfig/src/main/resources/META-INF/services/org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceProvider
@@ -0,0 +1,19 @@
+##########################################################################
+# 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.
+##########################################################################
+
+org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
deleted file mode 100644
index a33fcc2..0000000
--- a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.gateway.service.config.remote.config;
-
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.junit.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
-public class DefaultRemoteConfigurationRegistriesTest {
-
- /**
- * Test a single registry configuration with digest auth configuration.
- */
- @Test
- public void testPropertiesRemoteConfigurationRegistriesSingleDigest() throws Exception {
- Map<String, Properties> testProperties = new HashMap<>();
- Properties p = new Properties();
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "hostx:2181");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "zkDigestUser");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "digest");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS, "zkDigestAlias");
- testProperties.put("testDigest", p);
-
- doTestPropertiesRemoteConfigurationRegistries(testProperties);
- }
-
-
- /**
- * Test a single registry configuration with kerberos auth configuration.
- */
- @Test
- public void testPropertiesRemoteConfigurationRegistriesSingleKerberos() throws Exception {
- Map<String, Properties> testProperties = new HashMap<>();
- Properties p = new Properties();
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "hostx:2181");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "zkUser");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "kerberos");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB, "/home/user/remoteregistry.keytab");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB, "true");
- p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE, "false");
- testProperties.put("testKerb", p);
-
- doTestPropertiesRemoteConfigurationRegistries(testProperties);
- }
-
- /**
- * Test multiple registry configuration with varying auth configurations.
- */
- @Test
- public void testPropertiesRemoteConfigurationRegistriesMultipleMixed() throws Exception {
- Map<String, Properties> testProperties = new HashMap<>();
-
- Properties kerb = new Properties();
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host1:2181");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_NAMESPACE, "/knox/config");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "kerbPrincipal");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "kerberos");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB, "/home/user/mykrb.keytab");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB, "true");
- kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE, "false");
- testProperties.put("testKerb1", kerb);
-
- Properties digest = new Properties();
- digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
- digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host2:2181");
- digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "digestPrincipal");
- digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "digest");
- digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS, "digestPwdAlias");
- testProperties.put("testDigest1", digest);
-
- Properties unsecured = new Properties();
- unsecured.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
- unsecured.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host2:2181");
- testProperties.put("testUnsecured", unsecured);
-
- doTestPropertiesRemoteConfigurationRegistries(testProperties);
- }
-
-
- /**
- * Perform the actual test.
- *
- * @param testProperties The test properties
- */
- private void doTestPropertiesRemoteConfigurationRegistries(Map<String, Properties> testProperties) throws Exception {
- // Mock gateway config
- GatewayConfig gc = mockGatewayConfig(testProperties);
-
- // Create the RemoteConfigurationRegistries object to be tested from the GatewayConfig
- RemoteConfigurationRegistries registries = new DefaultRemoteConfigurationRegistries(gc);
-
- // Basic validation
- assertNotNull(registries);
- List<RemoteConfigurationRegistry> registryConfigs = registries.getRegistryConfigurations();
- assertNotNull(registryConfigs);
- assertEquals(testProperties.size(), registryConfigs.size());
-
- // Validate the contents of the created object
- for (RemoteConfigurationRegistry regConfig : registryConfigs) {
- validateRemoteRegistryConfig(regConfig.getName(), testProperties.get(regConfig.getName()), regConfig);
- }
- }
-
-
- /**
- * Create a mock GatewayConfig based on the specified test properties.
- *
- * @param testProperties The test properties to set on the config
- */
- private GatewayConfig mockGatewayConfig(Map<String, Properties> testProperties) {
- // Mock gateway config
- GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
- List<String> configNames = new ArrayList<>();
- for (String registryName : testProperties.keySet()) {
- configNames.add(registryName);
-
- String propertyValueString = "";
- Properties props = testProperties.get(registryName);
- Enumeration names = props.propertyNames();
- while (names.hasMoreElements()) {
- String propertyName = (String) names.nextElement();
- propertyValueString += propertyName + "=" + props.get(propertyName);
- if (names.hasMoreElements()) {
- propertyValueString += ";";
- }
- }
- EasyMock.expect(gc.getRemoteRegistryConfiguration(registryName))
- .andReturn(propertyValueString)
- .anyTimes();
- }
- EasyMock.expect(gc.getRemoteRegistryConfigurationNames()).andReturn(configNames).anyTimes();
- EasyMock.replay(gc);
-
- return gc;
- }
-
-
- /**
- * Validate the specified RemoteConfigurationRegistry based on the expected test properties.
- */
- private void validateRemoteRegistryConfig(String configName,
- Properties expected,
- RemoteConfigurationRegistry registryConfig) throws Exception {
- assertEquals(configName, registryConfig.getName());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE), registryConfig.getRegistryType());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS), registryConfig.getConnectionString());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_NAMESPACE), registryConfig.getNamespace());
- assertEquals(registryConfig.isSecureRegistry(), expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE) != null);
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE), registryConfig.getAuthType());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL), registryConfig.getPrincipal());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS), registryConfig.getCredentialAlias());
- assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB), registryConfig.getKeytab());
- assertEquals(Boolean.valueOf((String)expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB)), registryConfig.isUseKeyTab());
- assertEquals(Boolean.valueOf((String)expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE)), registryConfig.isUseTicketCache());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
deleted file mode 100644
index 386e332..0000000
--- a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.gateway.service.config.remote.config;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryConfig;
-import org.apache.hadoop.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import static org.apache.hadoop.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils.*;
-
-public class RemoteConfigurationRegistryConfigParserTest {
-
- @Test
- public void testExternalXMLParsing() throws Exception {
- final String CONN_STR = "http://my.zookeeper.host:2181";
-
- Map<String, Map<String, String>> testRegistryConfigurations = new HashMap<>();
-
- Map<String, String> config1 = new HashMap<>();
- config1.put(PROPERTY_TYPE, "ZooKeeper");
- config1.put(PROPERTY_NAME, "registry1");
- config1.put(PROPERTY_ADDRESS, CONN_STR);
- config1.put(PROPERTY_SECURE, "true");
- config1.put(PROPERTY_AUTH_TYPE, "Digest");
- config1.put(PROPERTY_PRINCIPAL, "knox");
- config1.put(PROPERTY_CRED_ALIAS, "zkCredential");
- testRegistryConfigurations.put(config1.get("name"), config1);
-
- Map<String, String> config2 = new HashMap<>();
- config2.put(PROPERTY_TYPE, "ZooKeeper");
- config2.put(PROPERTY_NAME, "MyKerberos");
- config2.put(PROPERTY_ADDRESS, CONN_STR);
- config2.put(PROPERTY_SECURE, "true");
- config2.put(PROPERTY_AUTH_TYPE, "Kerberos");
- config2.put(PROPERTY_PRINCIPAL, "knox");
- File myKeyTab = File.createTempFile("mytest", "keytab");
- config2.put(PROPERTY_KEYTAB, myKeyTab.getAbsolutePath());
- config2.put(PROPERTY_USE_KEYTAB, "false");
- config2.put(PROPERTY_USE_TICKET_CACHE, "true");
- testRegistryConfigurations.put(config2.get("name"), config2);
-
- Map<String, String> config3 = new HashMap<>();
- config3.put(PROPERTY_TYPE, "ZooKeeper");
- config3.put(PROPERTY_NAME, "anotherRegistry");
- config3.put(PROPERTY_ADDRESS, "whatever:1281");
- testRegistryConfigurations.put(config3.get("name"), config3);
-
- String configXML =
- RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(testRegistryConfigurations.values());
-
- File registryConfigFile = File.createTempFile("remote-registries", "xml");
- try {
- FileUtils.writeStringToFile(registryConfigFile, configXML);
-
- List<RemoteConfigurationRegistryConfig> configs =
- RemoteConfigurationRegistriesParser.getConfig(registryConfigFile.getAbsolutePath());
- assertNotNull(configs);
- assertEquals(testRegistryConfigurations.keySet().size(), configs.size());
-
- for (RemoteConfigurationRegistryConfig registryConfig : configs) {
- Map<String, String> expected = testRegistryConfigurations.get(registryConfig.getName());
- assertNotNull(expected);
- validateParsedRegistryConfiguration(registryConfig, expected);
- }
- } finally {
- registryConfigFile.delete();
- }
- }
-
- private void validateParsedRegistryConfiguration(RemoteConfigurationRegistryConfig config,
- Map<String, String> expected) throws Exception {
- assertEquals(expected.get(PROPERTY_TYPE), config.getRegistryType());
- assertEquals(expected.get(PROPERTY_ADDRESS), config.getConnectionString());
- assertEquals(expected.get(PROPERTY_NAME), config.getName());
- assertEquals(expected.get(PROPERTY_NAMESAPCE), config.getNamespace());
- assertEquals(Boolean.valueOf(expected.get(PROPERTY_SECURE)), config.isSecureRegistry());
- assertEquals(expected.get(PROPERTY_AUTH_TYPE), config.getAuthType());
- assertEquals(expected.get(PROPERTY_PRINCIPAL), config.getPrincipal());
- assertEquals(expected.get(PROPERTY_CRED_ALIAS), config.getCredentialAlias());
- assertEquals(expected.get(PROPERTY_KEYTAB), config.getKeytab());
- assertEquals(Boolean.valueOf(expected.get(PROPERTY_USE_KEYTAB)), config.isUseKeyTab());
- assertEquals(Boolean.valueOf(expected.get(PROPERTY_USE_TICKET_CACHE)), config.isUseTicketCache());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java b/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
deleted file mode 100644
index 35919d0..0000000
--- a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.gateway.service.config.remote.util;
-
-import java.util.Collection;
-import java.util.Map;
-
-public class RemoteRegistryConfigTestUtils {
-
- public static final String PROPERTY_TYPE = "type";
- public static final String PROPERTY_NAME = "name";
- public static final String PROPERTY_ADDRESS = "address";
- public static final String PROPERTY_NAMESAPCE = "namespace";
- public static final String PROPERTY_SECURE = "secure";
- public static final String PROPERTY_AUTH_TYPE = "authType";
- public static final String PROPERTY_PRINCIPAL = "principal";
- public static final String PROPERTY_CRED_ALIAS = "credentialAlias";
- public static final String PROPERTY_KEYTAB = "keyTab";
- public static final String PROPERTY_USE_KEYTAB = "useKeyTab";
- public static final String PROPERTY_USE_TICKET_CACHE = "useTicketCache";
-
- public static String createRemoteConfigRegistriesXML(Collection<Map<String, String>> configProperties) {
- String result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
- "<remote-configuration-registries>\n";
-
- for (Map<String, String> props : configProperties) {
- String authType = props.get(PROPERTY_AUTH_TYPE);
- if ("Kerberos".equalsIgnoreCase(authType)) {
- result +=
- createRemoteConfigRegistryXMLWithKerberosAuth(props.get(PROPERTY_TYPE),
- props.get(PROPERTY_NAME),
- props.get(PROPERTY_ADDRESS),
- props.get(PROPERTY_PRINCIPAL),
- props.get(PROPERTY_KEYTAB),
- Boolean.valueOf(props.get(PROPERTY_USE_KEYTAB)),
- Boolean.valueOf(props.get(PROPERTY_USE_TICKET_CACHE)));
- } else if ("Digest".equalsIgnoreCase(authType)) {
- result +=
- createRemoteConfigRegistryXMLWithDigestAuth(props.get(PROPERTY_TYPE),
- props.get(PROPERTY_NAME),
- props.get(PROPERTY_ADDRESS),
- props.get(PROPERTY_PRINCIPAL),
- props.get(PROPERTY_CRED_ALIAS));
- } else {
- result += createRemoteConfigRegistryXMLNoAuth(props.get(PROPERTY_TYPE),
- props.get(PROPERTY_NAME),
- props.get(PROPERTY_ADDRESS));
- }
- }
-
- result += "</remote-configuration-registries>\n";
-
- return result;
- }
-
- public static String createRemoteConfigRegistryXMLWithKerberosAuth(String type,
- String name,
- String address,
- String principal,
- String keyTab,
- boolean userKeyTab,
- boolean useTicketCache) {
- return " <remote-configuration-registry>\n" +
- " <name>" + name + "</name>\n" +
- " <type>" + type + "</type>\n" +
- " <address>" + address + "</address>\n" +
- " <secure>true</secure>\n" +
- " <auth-type>" + "Kerberos" + "</auth-type>\n" +
- " <principal>" + principal + "</principal>\n" +
- " <keytab>" + keyTab + "</keytab>\n" +
- " <use-keytab>" + String.valueOf(userKeyTab) + "</use-keytab>\n" +
- " <use-ticket-cache>" + String.valueOf(useTicketCache) + "</use-ticket-cache>\n" +
- " </remote-configuration-registry>\n";
- }
-
- public static String createRemoteConfigRegistryXMLWithDigestAuth(String type,
- String name,
- String address,
- String principal,
- String credentialAlias) {
- return " <remote-configuration-registry>\n" +
- " <name>" + name + "</name>\n" +
- " <type>" + type + "</type>\n" +
- " <address>" + address + "</address>\n" +
- " <secure>true</secure>\n" +
- " <auth-type>" + "Digest" + "</auth-type>\n" +
- " <principal>" + principal + "</principal>\n" +
- " <credential-alias>" + credentialAlias + "</credential-alias>\n" +
- " </remote-configuration-registry>\n";
- }
-
-
- public static String createRemoteConfigRegistryXMLNoAuth(String type,
- String name,
- String address) {
- return " <remote-configuration-registry>\n" +
- " <name>" + name + "</name>\n" +
- " <type>" + type + "</type>\n" +
- " <address>" + address + "</address>\n" +
- " </remote-configuration-registry>\n";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
deleted file mode 100644
index 0292ee3..0000000
--- a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
+++ /dev/null
@@ -1,424 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.gateway.service.config.remote.zk;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.curator.test.InstanceSpec;
-import org.apache.curator.test.TestingCluster;
-import org.apache.hadoop.gateway.config.GatewayConfig;
-import org.apache.hadoop.gateway.services.config.client.RemoteConfigurationRegistryClient.ChildEntryListener;
-import org.apache.hadoop.gateway.services.config.client.RemoteConfigurationRegistryClient;
-import org.apache.hadoop.gateway.services.config.client.RemoteConfigurationRegistryClientService;
-import org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceFactory;
-import org.apache.hadoop.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils;
-import org.apache.hadoop.gateway.services.security.AliasService;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Id;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class RemoteConfigurationRegistryClientServiceTest {
-
- /**
- * Test a configuration for an unsecured remote registry, included in the gateway configuration.
- */
- @Test
- public void testUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
- final String REGISTRY_CLIENT_NAME = "unsecured-zk-registry-name";
- final String PRINCIPAL = null;
- final String PWD = null;
- final String CRED_ALIAS = null;
-
- // Configure and start a secure ZK cluster
- TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
-
- try {
- // Create the setup client for the test cluster, and initialize the test znodes
- CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
- EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
- .andReturn(registryConfigValue)
- .anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
- .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD);
- } finally {
- zkCluster.stop();
- }
- }
-
- /**
- * Test multiple configurations for an unsecured remote registry.
- */
- @Test
- public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig() throws Exception {
- final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
- final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
- final String PRINCIPAL = null;
- final String PWD = null;
- final String CRED_ALIAS = null;
-
- // Configure and start a secure ZK cluster
- TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
-
- try {
- // Create the setup client for the test cluster, and initialize the test znodes
- CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue1 =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
- EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1))
- .andReturn(registryConfigValue1).anyTimes();
- final String registryConfigValue2 =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString();
- EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2))
- .andReturn(registryConfigValue2).anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
- .andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes();
- EasyMock.replay(config);
-
- // Create the client service instance
- RemoteConfigurationRegistryClientService clientService =
- RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
- assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class);
- clientService.setAliasService(null);
- clientService.init(config, null);
- clientService.start();
-
- RemoteConfigurationRegistryClient client1 = clientService.get(REGISTRY_CLIENT_NAME_1);
- assertNotNull(client1);
-
- RemoteConfigurationRegistryClient client2 = clientService.get(REGISTRY_CLIENT_NAME_2);
- assertNotNull(client2);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1, clientService, false);
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2, clientService, false);
- } finally {
- zkCluster.stop();
- }
- }
-
- /**
- * Test a configuration for a secure remote registry, included in the gateway configuration.
- */
- @Test
- public void testZooKeeperWithSimpleRegistryConfig() throws Exception {
- final String AUTH_TYPE = "digest";
- final String REGISTRY_CLIENT_NAME = "zk-registry-name";
- final String PRINCIPAL = "knox";
- final String PWD = "knoxtest";
- final String CRED_ALIAS = "zkCredential";
-
- // Configure and start a secure ZK cluster
- TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
-
- try {
- // Create the setup client for the test cluster, and initialize the test znodes
- CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString() + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" + AUTH_TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" + PRINCIPAL + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS + "=" + CRED_ALIAS;
- EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
- .andReturn(registryConfigValue)
- .anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
- .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD);
- } finally {
- zkCluster.stop();
- }
- }
-
- /**
- * Test the remote registry configuration external to, and referenced from, the gateway configuration, for a secure
- * client.
- */
- @Test
- public void testZooKeeperWithSingleExternalRegistryConfig() throws Exception {
- final String AUTH_TYPE = "digest";
- final String REGISTRY_CLIENT_NAME = "my-zookeeper_registryNAME";
- final String PRINCIPAL = "knox";
- final String PWD = "knoxtest";
- final String CRED_ALIAS = "zkCredential";
-
- // Configure and start a secure ZK cluster
- TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD);
-
- File tmpRegConfigFile = null;
-
- try {
- // Create the setup client for the test cluster, and initialize the test znodes
- CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- Map<String, String> registryConfigProps = new HashMap<>();
- registryConfigProps.put("type", ZooKeeperClientService.TYPE);
- registryConfigProps.put("name", REGISTRY_CLIENT_NAME);
- registryConfigProps.put("address", zkCluster.getConnectString());
- registryConfigProps.put("secure", "true");
- registryConfigProps.put("authType", AUTH_TYPE);
- registryConfigProps.put("principal", PRINCIPAL);
- registryConfigProps.put("credentialAlias", CRED_ALIAS);
- String registryConfigXML =
- RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(Collections.singleton(registryConfigProps));
- tmpRegConfigFile = File.createTempFile("myRemoteRegistryConfig", "xml");
- FileUtils.writeStringToFile(tmpRegConfigFile, registryConfigXML);
-
- System.setProperty("org.apache.knox.gateway.remote.registry.config.file", tmpRegConfigFile.getAbsolutePath());
-
- GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD);
- } finally {
- zkCluster.stop();
- if (tmpRegConfigFile != null && tmpRegConfigFile.exists()) {
- tmpRegConfigFile.delete();
- }
- System.clearProperty("org.apache.knox.gateway.remote.registry.config.file");
- }
- }
-
- /**
- * Setup and start a secure test ZooKeeper cluster.
- */
- private TestingCluster setupAndStartSecureTestZooKeeper(String principal, String digestPassword) throws Exception {
- final boolean applyAuthentication = (principal != null);
-
- // Configure security for the ZK cluster instances
- Map<String, Object> customInstanceSpecProps = new HashMap<>();
-
- if (applyAuthentication) {
- customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
- customInstanceSpecProps.put("requireClientAuthScheme", "sasl");
- }
-
- // Define the test cluster
- List<InstanceSpec> instanceSpecs = new ArrayList<>();
- for (int i = 0 ; i < 3 ; i++) {
- InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i+1), -1, -1, customInstanceSpecProps);
- instanceSpecs.add(is);
- }
- TestingCluster zkCluster = new TestingCluster(instanceSpecs);
-
- if (applyAuthentication) {
- // Setup ZooKeeper server SASL
- Map<String, String> digestOptions = new HashMap<>();
- digestOptions.put("user_" + principal, digestPassword);
- final AppConfigurationEntry[] serverEntries =
- {new AppConfigurationEntry("org.apache.zookeeper.server.auth.DigestLoginModule",
- AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
- digestOptions)};
- Configuration.setConfiguration(new Configuration() {
- @Override
- public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
- return ("Server".equalsIgnoreCase(name)) ? serverEntries : null;
- }
- });
- }
-
- // Start the cluster
- zkCluster.start();
-
- return zkCluster;
- }
-
- /**
- * Create a ZooKeeper client with SASL digest auth configured, and initialize the test znodes.
- */
- private CuratorFramework initializeTestClientAndZNodes(TestingCluster zkCluster, String principal) throws Exception {
- // Create the client for the test cluster
- CuratorFramework setupClient = CuratorFrameworkFactory.builder()
- .connectString(zkCluster.getConnectString())
- .retryPolicy(new ExponentialBackoffRetry(100, 3))
- .build();
- assertNotNull(setupClient);
- setupClient.start();
-
- List<ACL> acls = new ArrayList<>();
- if (principal != null) {
- acls.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", principal)));
- } else {
- acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
- }
- setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/descriptors");
- setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/shared-providers");
-
- List<ACL> negativeACLs = new ArrayList<>();
- if (principal != null) {
- negativeACLs.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", "notyou")));
- } else {
- negativeACLs.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
- }
- setupClient.create().creatingParentsIfNeeded().withACL(negativeACLs).forPath("/someotherconfig");
-
- return setupClient;
- }
-
- private void doTestZooKeeperClient(final CuratorFramework setupClient,
- final String testClientName,
- final GatewayConfig config,
- final String credentialAlias,
- final String digestPassword) throws Exception {
- boolean isSecureTest = (credentialAlias != null && digestPassword != null);
-
- // Mock alias service
- AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
- EasyMock.expect(aliasService.getPasswordFromAliasForGateway(credentialAlias))
- .andReturn(isSecureTest ? digestPassword.toCharArray() : null)
- .anyTimes();
- EasyMock.replay(aliasService);
-
- // Create the client service instance
- RemoteConfigurationRegistryClientService clientService =
- RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
- assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class);
- clientService.setAliasService(aliasService);
- clientService.init(config, null);
- clientService.start();
-
- doTestZooKeeperClient(setupClient, testClientName, clientService, isSecureTest);
- }
-
- /**
- * Test secure ZooKeeper client interactions.
- *
- * @param setupClient The client used for interacting with ZooKeeper independent from the registry client service.
- * @param testClientName The name of the client to use from the registry client service.
- * @param clientService The RemoteConfigurationRegistryClientService
- * @param isSecureTest Flag to indicate whether this is a secure interaction test
- */
- private void doTestZooKeeperClient(final CuratorFramework setupClient,
- final String testClientName,
- final RemoteConfigurationRegistryClientService clientService,
- boolean isSecureTest) throws Exception {
-
- RemoteConfigurationRegistryClient client = clientService.get(testClientName);
- assertNotNull(client);
- List<String> descriptors = client.listChildEntries("/knox/config/descriptors");
- assertNotNull(descriptors);
- for (String descriptor : descriptors) {
- System.out.println("Descriptor: " + descriptor);
- }
-
- List<String> providerConfigs = client.listChildEntries("/knox/config/shared-providers");
- assertNotNull(providerConfigs);
- for (String providerConfig : providerConfigs) {
- System.out.println("Provider config: " + providerConfig);
- }
-
- List<String> someotherConfig = client.listChildEntries("/someotherconfig");
- if (isSecureTest) {
- assertNull("Expected null because of the ACL mismatch.", someotherConfig);
- } else {
- assertNotNull(someotherConfig);
- }
-
- // Test listeners
- final String MY_NEW_ZNODE = "/clientServiceTestNode";
- final String MY_NEW_DATA_ZNODE = MY_NEW_ZNODE + "/mydata";
-
- if (setupClient.checkExists().forPath(MY_NEW_ZNODE) != null) {
- setupClient.delete().deletingChildrenIfNeeded().forPath(MY_NEW_ZNODE);
- }
-
- final List<String> listenerLog = new ArrayList<>();
- client.addChildEntryListener(MY_NEW_ZNODE, (c, type, path) -> {
- listenerLog.add("EXTERNAL: " + type.toString() + ":" + path);
- if (ChildEntryListener.Type.ADDED.equals(type)) {
- try {
- c.addEntryListener(path, (cc, p, d) -> listenerLog.add("EXTERNAL: " + p + ":" + (d != null ? new String(d) : "null")));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
-
- client.createEntry(MY_NEW_ZNODE);
- client.createEntry(MY_NEW_DATA_ZNODE, "more test data");
- String testData = client.getEntryData(MY_NEW_DATA_ZNODE);
- assertNotNull(testData);
- assertEquals("more test data", testData);
-
- assertTrue(client.entryExists(MY_NEW_DATA_ZNODE));
- client.setEntryData(MY_NEW_DATA_ZNODE, "still more data");
-
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //
- }
-
- client.setEntryData(MY_NEW_DATA_ZNODE, "changed completely");
-
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //
- }
-
- client.deleteEntry(MY_NEW_DATA_ZNODE);
-
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //
- }
-
- assertFalse(listenerLog.isEmpty());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfigTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfigTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfigTest.java
deleted file mode 100644
index 6cbef9b..0000000
--- a/gateway-service-remoteconfig/src/test/java/org/apache/hadoop/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfigTest.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.hadoop.gateway.service.config.remote.zk;
-
-import org.apache.hadoop.gateway.service.config.remote.RemoteConfigurationRegistryConfig;
-import org.apache.hadoop.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig;
-import org.apache.hadoop.gateway.services.security.AliasService;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class RemoteConfigurationRegistryJAASConfigTest {
-
- @Test
- public void testZooKeeperDigestContextEntry() throws Exception {
- List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
- final String ENTRY_NAME = "my_digest_context";
- final String DIGEST_PRINCIPAL = "myIdentity";
- final String DIGEST_PWD_ALIAS = "myAlias";
- final String DIGEST_PWD = "mysecret";
-
- AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
- EasyMock.expect(aliasService.getPasswordFromAliasForGateway(DIGEST_PWD_ALIAS)).andReturn(DIGEST_PWD.toCharArray()).anyTimes();
- EasyMock.replay(aliasService);
-
- registryConfigs.add(createDigestConfig(ENTRY_NAME, DIGEST_PRINCIPAL, DIGEST_PWD_ALIAS));
-
- try {
- RemoteConfigurationRegistryJAASConfig jaasConfig =
- RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);
-
- // Make sure there are no entries for an invalid context entry name
- assertNull(jaasConfig.getAppConfigurationEntry("invalid"));
-
- // Validate the intended context entry
- validateDigestContext(jaasConfig,
- ENTRY_NAME,
- RemoteConfigurationRegistryJAASConfig.digestLoginModules.get("ZOOKEEPER"),
- DIGEST_PRINCIPAL,
- DIGEST_PWD);
- } finally {
- Configuration.setConfiguration(null);
- }
- }
-
- @Test
- public void testKerberosContextEntry() throws Exception {
- List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
- final String ENTRY_NAME = "my_kerberos_context";
- final String PRINCIPAL = "myIdentity";
-
- File dummyKeyTab = File.createTempFile("my_context", "keytab");
- registryConfigs.add(createKerberosConfig(ENTRY_NAME, PRINCIPAL, dummyKeyTab.getAbsolutePath()));
-
- try {
- RemoteConfigurationRegistryJAASConfig jaasConfig =
- RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, null);
-
- // Make sure there are no entries for an invalid context entry name
- assertNull(jaasConfig.getAppConfigurationEntry("invalid"));
-
- // Validate the intended context entry
- validateKerberosContext(jaasConfig,
- ENTRY_NAME,
- PRINCIPAL,
- dummyKeyTab.getAbsolutePath(),
- true,
- false);
-
- } finally {
- Configuration.setConfiguration(null);
- }
- }
-
- @Test
- public void testZooKeeperMultipleContextEntries() throws Exception {
- List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
- final String KERBEROS_ENTRY_NAME = "my_kerberos_context";
- final String KERBEROS_PRINCIPAL = "myKerberosIdentity";
- final String DIGEST_ENTRY_NAME = "my_digest_context";
- final String DIGEST_PRINCIPAL = "myDigestIdentity";
- final String DIGEST_PWD_ALIAS = "myAlias";
- final String DIGEST_PWD = "mysecret";
-
- AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
- EasyMock.expect(aliasService.getPasswordFromAliasForGateway(DIGEST_PWD_ALIAS)).andReturn(DIGEST_PWD.toCharArray()).anyTimes();
- EasyMock.replay(aliasService);
-
- File dummyKeyTab = File.createTempFile("my_context", "keytab");
- registryConfigs.add(createKerberosConfig(KERBEROS_ENTRY_NAME, KERBEROS_PRINCIPAL, dummyKeyTab.getAbsolutePath()));
- registryConfigs.add(createDigestConfig(DIGEST_ENTRY_NAME, DIGEST_PRINCIPAL, DIGEST_PWD_ALIAS));
-
- try {
- RemoteConfigurationRegistryJAASConfig jaasConfig =
- RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);
-
- // Make sure there are no entries for an invalid context entry name
- assertNull(jaasConfig.getAppConfigurationEntry("invalid"));
-
- // Validate the kerberos context entry
- validateKerberosContext(jaasConfig,
- KERBEROS_ENTRY_NAME,
- KERBEROS_PRINCIPAL,
- dummyKeyTab.getAbsolutePath(),
- true,
- false);
-
- // Validate the digest context entry
- validateDigestContext(jaasConfig,
- DIGEST_ENTRY_NAME,
- RemoteConfigurationRegistryJAASConfig.digestLoginModules.get("ZOOKEEPER"),
- DIGEST_PRINCIPAL,
- DIGEST_PWD);
-
- } finally {
- Configuration.setConfiguration(null);
- }
- }
-
- @Test
- public void testZooKeeperDigestContextEntryWithoutAliasService() throws Exception {
- List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
- final String ENTRY_NAME = "my_digest_context";
- final String DIGEST_PRINCIPAL = "myIdentity";
- final String DIGEST_PWD_ALIAS = "myAlias";
-
- registryConfigs.add(createDigestConfig(ENTRY_NAME, DIGEST_PRINCIPAL, DIGEST_PWD_ALIAS));
-
- try {
- RemoteConfigurationRegistryJAASConfig jaasConfig =
- RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, null);
- fail("Expected IllegalArgumentException because the AliasService is not available.");
- } catch (IllegalArgumentException e) {
- // Expected
- assertTrue(e.getMessage().contains("AliasService"));
- } catch (Throwable e) {
- fail("Wrong exception encountered: " + e.getClass().getName() + ", " + e.getMessage());
- } finally {
- Configuration.setConfiguration(null);
- }
- }
-
- private static RemoteConfigurationRegistryConfig createDigestConfig(String entryName,
- String principal,
- String credentialAlias) {
- return createDigestConfig(entryName, principal, credentialAlias, "ZooKeeper");
- }
-
- private static RemoteConfigurationRegistryConfig createDigestConfig(String entryName,
- String principal,
- String credentialAlias,
- String registryType) {
- RemoteConfigurationRegistryConfig rc = EasyMock.createNiceMock(RemoteConfigurationRegistryConfig.class);
- EasyMock.expect(rc.getRegistryType()).andReturn(registryType).anyTimes();
- EasyMock.expect(rc.getName()).andReturn(entryName).anyTimes();
- EasyMock.expect(rc.isSecureRegistry()).andReturn(true).anyTimes();
- EasyMock.expect(rc.getAuthType()).andReturn("digest").anyTimes();
- EasyMock.expect(rc.getPrincipal()).andReturn(principal).anyTimes();
- EasyMock.expect(rc.getCredentialAlias()).andReturn(credentialAlias).anyTimes();
- EasyMock.replay(rc);
- return rc;
- }
-
-
- private static RemoteConfigurationRegistryConfig createKerberosConfig(String entryName,
- String principal,
- String keyTabPath) {
- return createKerberosConfig(entryName, principal, keyTabPath, "ZooKeeper");
- }
-
- private static RemoteConfigurationRegistryConfig createKerberosConfig(String entryName,
- String principal,
- String keyTabPath,
- String registryType) {
- return createKerberosConfig(entryName, principal, keyTabPath, null, null, registryType);
- }
-
- private static RemoteConfigurationRegistryConfig createKerberosConfig(String entryName,
- String principal,
- String keyTabPath,
- Boolean useKeyTab,
- Boolean useTicketCache,
- String registryType) {
- RemoteConfigurationRegistryConfig rc = EasyMock.createNiceMock(RemoteConfigurationRegistryConfig.class);
- EasyMock.expect(rc.getRegistryType()).andReturn(registryType).anyTimes();
- EasyMock.expect(rc.getName()).andReturn(entryName).anyTimes();
- EasyMock.expect(rc.isSecureRegistry()).andReturn(true).anyTimes();
- EasyMock.expect(rc.getAuthType()).andReturn("kerberos").anyTimes();
- EasyMock.expect(rc.getPrincipal()).andReturn(principal).anyTimes();
- EasyMock.expect(rc.getKeytab()).andReturn(keyTabPath).anyTimes();
- EasyMock.expect(rc.isUseKeyTab()).andReturn(useKeyTab != null ? useKeyTab : true).anyTimes();
- EasyMock.expect(rc.isUseTicketCache()).andReturn(useTicketCache != null ? useTicketCache : false).anyTimes();
- EasyMock.replay(rc);
- return rc;
- }
-
- private static void validateDigestContext(RemoteConfigurationRegistryJAASConfig config,
- String entryName,
- String loginModule,
- String principal,
- String password) throws Exception {
- AppConfigurationEntry[] myContextEntries = config.getAppConfigurationEntry(entryName);
- assertNotNull(myContextEntries);
- assertEquals(1, myContextEntries.length);
- AppConfigurationEntry entry = myContextEntries[0];
- assertTrue(entry.getLoginModuleName().equals(loginModule));
- Map<String, ?> entryOpts = entry.getOptions();
- assertEquals(principal, entryOpts.get("username"));
- assertEquals(password, entryOpts.get("password"));
- }
-
- private static void validateKerberosContext(RemoteConfigurationRegistryJAASConfig config,
- String entryName,
- String principal,
- String keyTab,
- boolean useKeyTab,
- boolean useTicketCache) throws Exception {
- AppConfigurationEntry[] myContextEntries = config.getAppConfigurationEntry(entryName);
- assertNotNull(myContextEntries);
- assertEquals(1, myContextEntries.length);
- AppConfigurationEntry entry = myContextEntries[0];
- assertTrue(entry.getLoginModuleName().endsWith(".security.auth.module.Krb5LoginModule"));
- Map<String, ?> entryOpts = entry.getOptions();
- assertEquals(principal, entryOpts.get("principal"));
- assertEquals(keyTab, entryOpts.get("keyTab"));
- assertEquals(useKeyTab, Boolean.valueOf((String)entryOpts.get("isUseKeyTab")));
- assertEquals(useTicketCache, Boolean.valueOf((String)entryOpts.get("isUseTicketCache")));
- }
-}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
new file mode 100644
index 0000000..ce223e9
--- /dev/null
+++ b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/DefaultRemoteConfigurationRegistriesTest.java
@@ -0,0 +1,184 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.service.config.remote.config;
+
+import org.apache.knox.gateway.config.GatewayConfig;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+public class DefaultRemoteConfigurationRegistriesTest {
+
+ /**
+ * Test a single registry configuration with digest auth configuration.
+ */
+ @Test
+ public void testPropertiesRemoteConfigurationRegistriesSingleDigest() throws Exception {
+ Map<String, Properties> testProperties = new HashMap<>();
+ Properties p = new Properties();
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "hostx:2181");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "zkDigestUser");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "digest");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS, "zkDigestAlias");
+ testProperties.put("testDigest", p);
+
+ doTestPropertiesRemoteConfigurationRegistries(testProperties);
+ }
+
+
+ /**
+ * Test a single registry configuration with kerberos auth configuration.
+ */
+ @Test
+ public void testPropertiesRemoteConfigurationRegistriesSingleKerberos() throws Exception {
+ Map<String, Properties> testProperties = new HashMap<>();
+ Properties p = new Properties();
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "hostx:2181");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "zkUser");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "kerberos");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB, "/home/user/remoteregistry.keytab");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB, "true");
+ p.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE, "false");
+ testProperties.put("testKerb", p);
+
+ doTestPropertiesRemoteConfigurationRegistries(testProperties);
+ }
+
+ /**
+ * Test multiple registry configuration with varying auth configurations.
+ */
+ @Test
+ public void testPropertiesRemoteConfigurationRegistriesMultipleMixed() throws Exception {
+ Map<String, Properties> testProperties = new HashMap<>();
+
+ Properties kerb = new Properties();
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host1:2181");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_NAMESPACE, "/knox/config");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "kerbPrincipal");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "kerberos");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB, "/home/user/mykrb.keytab");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB, "true");
+ kerb.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE, "false");
+ testProperties.put("testKerb1", kerb);
+
+ Properties digest = new Properties();
+ digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
+ digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host2:2181");
+ digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL, "digestPrincipal");
+ digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE, "digest");
+ digest.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS, "digestPwdAlias");
+ testProperties.put("testDigest1", digest);
+
+ Properties unsecured = new Properties();
+ unsecured.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE, "ZooKeeper");
+ unsecured.setProperty(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS, "host2:2181");
+ testProperties.put("testUnsecured", unsecured);
+
+ doTestPropertiesRemoteConfigurationRegistries(testProperties);
+ }
+
+
+ /**
+ * Perform the actual test.
+ *
+ * @param testProperties The test properties
+ */
+ private void doTestPropertiesRemoteConfigurationRegistries(Map<String, Properties> testProperties) throws Exception {
+ // Mock gateway config
+ GatewayConfig gc = mockGatewayConfig(testProperties);
+
+ // Create the RemoteConfigurationRegistries object to be tested from the GatewayConfig
+ RemoteConfigurationRegistries registries = new DefaultRemoteConfigurationRegistries(gc);
+
+ // Basic validation
+ assertNotNull(registries);
+ List<RemoteConfigurationRegistry> registryConfigs = registries.getRegistryConfigurations();
+ assertNotNull(registryConfigs);
+ assertEquals(testProperties.size(), registryConfigs.size());
+
+ // Validate the contents of the created object
+ for (RemoteConfigurationRegistry regConfig : registryConfigs) {
+ validateRemoteRegistryConfig(regConfig.getName(), testProperties.get(regConfig.getName()), regConfig);
+ }
+ }
+
+
+ /**
+ * Create a mock GatewayConfig based on the specified test properties.
+ *
+ * @param testProperties The test properties to set on the config
+ */
+ private GatewayConfig mockGatewayConfig(Map<String, Properties> testProperties) {
+ // Mock gateway config
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ List<String> configNames = new ArrayList<>();
+ for (String registryName : testProperties.keySet()) {
+ configNames.add(registryName);
+
+ String propertyValueString = "";
+ Properties props = testProperties.get(registryName);
+ Enumeration names = props.propertyNames();
+ while (names.hasMoreElements()) {
+ String propertyName = (String) names.nextElement();
+ propertyValueString += propertyName + "=" + props.get(propertyName);
+ if (names.hasMoreElements()) {
+ propertyValueString += ";";
+ }
+ }
+ EasyMock.expect(gc.getRemoteRegistryConfiguration(registryName))
+ .andReturn(propertyValueString)
+ .anyTimes();
+ }
+ EasyMock.expect(gc.getRemoteRegistryConfigurationNames()).andReturn(configNames).anyTimes();
+ EasyMock.replay(gc);
+
+ return gc;
+ }
+
+
+ /**
+ * Validate the specified RemoteConfigurationRegistry based on the expected test properties.
+ */
+ private void validateRemoteRegistryConfig(String configName,
+ Properties expected,
+ RemoteConfigurationRegistry registryConfig) throws Exception {
+ assertEquals(configName, registryConfig.getName());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE), registryConfig.getRegistryType());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS), registryConfig.getConnectionString());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_NAMESPACE), registryConfig.getNamespace());
+ assertEquals(registryConfig.isSecureRegistry(), expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE) != null);
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE), registryConfig.getAuthType());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL), registryConfig.getPrincipal());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS), registryConfig.getCredentialAlias());
+ assertEquals(expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_KEYTAB), registryConfig.getKeytab());
+ assertEquals(Boolean.valueOf((String)expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_KEYTAB)), registryConfig.isUseKeyTab());
+ assertEquals(Boolean.valueOf((String)expected.get(GatewayConfig.REMOTE_CONFIG_REGISTRY_USE_TICKET_CACHE)), registryConfig.isUseTicketCache());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/e766b3b7/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
new file mode 100644
index 0000000..1ff5dec
--- /dev/null
+++ b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/config/RemoteConfigurationRegistryConfigParserTest.java
@@ -0,0 +1,115 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.knox.gateway.service.config.remote.config;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig;
+import org.apache.knox.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import static org.apache.knox.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils.*;
+
+public class RemoteConfigurationRegistryConfigParserTest {
+
+ @Test
+ public void testExternalXMLParsing() throws Exception {
+ final String CONN_STR = "http://my.zookeeper.host:2181";
+
+ Map<String, Map<String, String>> testRegistryConfigurations = new HashMap<>();
+
+ Map<String, String> config1 = new HashMap<>();
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_TYPE, "ZooKeeper");
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_NAME, "registry1");
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_ADDRESS, CONN_STR);
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_SECURE, "true");
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_AUTH_TYPE, "Digest");
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_PRINCIPAL, "knox");
+ config1.put(RemoteRegistryConfigTestUtils.PROPERTY_CRED_ALIAS, "zkCredential");
+ testRegistryConfigurations.put(config1.get("name"), config1);
+
+ Map<String, String> config2 = new HashMap<>();
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_TYPE, "ZooKeeper");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_NAME, "MyKerberos");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_ADDRESS, CONN_STR);
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_SECURE, "true");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_AUTH_TYPE, "Kerberos");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_PRINCIPAL, "knox");
+ File myKeyTab = File.createTempFile("mytest", "keytab");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_KEYTAB, myKeyTab.getAbsolutePath());
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_USE_KEYTAB, "false");
+ config2.put(RemoteRegistryConfigTestUtils.PROPERTY_USE_TICKET_CACHE, "true");
+ testRegistryConfigurations.put(config2.get("name"), config2);
+
+ Map<String, String> config3 = new HashMap<>();
+ config3.put(RemoteRegistryConfigTestUtils.PROPERTY_TYPE, "ZooKeeper");
+ config3.put(RemoteRegistryConfigTestUtils.PROPERTY_NAME, "anotherRegistry");
+ config3.put(RemoteRegistryConfigTestUtils.PROPERTY_ADDRESS, "whatever:1281");
+ testRegistryConfigurations.put(config3.get("name"), config3);
+
+ String configXML =
+ RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(testRegistryConfigurations.values());
+
+ File registryConfigFile = File.createTempFile("remote-registries", "xml");
+ try {
+ FileUtils.writeStringToFile(registryConfigFile, configXML);
+
+ List<RemoteConfigurationRegistryConfig> configs =
+ RemoteConfigurationRegistriesParser.getConfig(registryConfigFile.getAbsolutePath());
+ assertNotNull(configs);
+ assertEquals(testRegistryConfigurations.keySet().size(), configs.size());
+
+ for (RemoteConfigurationRegistryConfig registryConfig : configs) {
+ Map<String, String> expected = testRegistryConfigurations.get(registryConfig.getName());
+ assertNotNull(expected);
+ validateParsedRegistryConfiguration(registryConfig, expected);
+ }
+ } finally {
+ registryConfigFile.delete();
+ }
+ }
+
+ private void validateParsedRegistryConfiguration(RemoteConfigurationRegistryConfig config,
+ Map<String, String> expected) throws Exception {
+ assertEquals(expected.get(RemoteRegistryConfigTestUtils.PROPERTY_TYPE), config.getRegistryType());
+ assertEquals(expected.get(RemoteRegistryConfigTestUtils.PROPERTY_ADDRESS), config.getConnectionString());
+ assertEquals(expected.get(RemoteRegistryConfigTestUtils.PROPERTY_NAME), config.getName());
+ assertEquals(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_NAMESAPCE), config.getNamespace());
+ assertEquals(Boolean.valueOf(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_SECURE)), config.isSecureRegistry());
+ assertEquals(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_AUTH_TYPE), config.getAuthType());
+ assertEquals(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_PRINCIPAL), config.getPrincipal());
+ assertEquals(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_CRED_ALIAS), config.getCredentialAlias());
+ assertEquals(expected.get(RemoteRegistryConfigTestUtils.PROPERTY_KEYTAB), config.getKeytab());
+ assertEquals(Boolean.valueOf(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_USE_KEYTAB)), config.isUseKeyTab());
+ assertEquals(Boolean.valueOf(expected.get(
+ RemoteRegistryConfigTestUtils.PROPERTY_USE_TICKET_CACHE)), config.isUseTicketCache());
+ }
+
+}