use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig in project knox by apache.
the class RemoteConfigurationRegistriesAccessor method getRemoteRegistryConfigurations.
public static List<RemoteConfigurationRegistryConfig> getRemoteRegistryConfigurations(GatewayConfig gatewayConfig) {
List<RemoteConfigurationRegistryConfig> result = new ArrayList<>();
boolean useReferencedFile = false;
// First check for the system property pointing to a valid XML config for the remote registries
String remoteConfigRegistryConfigFilename = System.getProperty(XML_CONFIG_REFERENCE_SYSTEM_PROPERTY_NAME);
if (remoteConfigRegistryConfigFilename != null) {
File remoteConfigRegistryConfigFile = new File(remoteConfigRegistryConfigFilename);
if (remoteConfigRegistryConfigFile.exists()) {
useReferencedFile = true;
// Parse the file, and build the registry config set
result.addAll(RemoteConfigurationRegistriesParser.getConfig(remoteConfigRegistryConfigFilename));
}
}
// registry configurations from the gateway config.
if (!useReferencedFile) {
RemoteConfigurationRegistries remoteConfigRegistries = new DefaultRemoteConfigurationRegistries(gatewayConfig);
result.addAll(remoteConfigRegistries.getRegistryConfigurations());
}
return result;
}
use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig in project knox by apache.
the class RemoteConfigurationRegistryConfigParserTest method testExternalXMLParsing.
@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();
}
}
use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig in project knox by apache.
the class RemoteConfigurationRegistryJAASConfigTest method testZooKeeperDigestContextEntryWithoutAliasService.
@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);
}
}
use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig in project knox by apache.
the class RemoteConfigurationRegistryJAASConfigTest method testKerberosContextEntry.
@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);
}
}
use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig in project knox by apache.
the class RemoteConfigurationRegistriesParser method getConfig.
static List<RemoteConfigurationRegistryConfig> getConfig(String configFilename) {
List<RemoteConfigurationRegistryConfig> result = new ArrayList<>();
File file = new File(configFilename);
try {
JAXBContext jaxbContext = JAXBContext.newInstance(RemoteConfigurationRegistries.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
RemoteConfigurationRegistries parsedContent = (RemoteConfigurationRegistries) jaxbUnmarshaller.unmarshal(file);
if (parsedContent != null) {
result.addAll(parsedContent.getRegistryConfigurations());
}
} catch (JAXBException e) {
e.printStackTrace();
}
return result;
}
Aggregations