use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureAcceptAllGetTest method testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore.
@Test
public void testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore() throws Exception {
// test config exception happens before we even try to connect to anything
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest." + testName.getMethodName();
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, TEST_FILE_TS.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD);
boolean foundCause = false;
try {
ClientFactory.getNamedClient(name);
} catch (Throwable t) {
while (t != null && !foundCause) {
if (t instanceof IllegalArgumentException && t.getMessage().startsWith("Invalid value for property:CustomSSLSocketFactoryClassName")) {
foundCause = true;
break;
}
t = t.getCause();
}
}
assertTrue(foundCause);
}
use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureGetTest method testSunnyDay.
@Test
public void testSunnyDay() throws Exception {
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testSunnyDay";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(testServer1.getPort()));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD);
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer1.accept();
URI getUri = new URI(SERVICE_URI1 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureGetTest method testSunnyDayNoClientAuth.
@Test
public void testSunnyDayNoClientAuth() throws Exception {
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testSunnyDayNoClientAuth";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(testServer2.getPort()));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS2.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer2.accept();
URI getUri = new URI(SERVICE_URI2 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureRestClientKeystoreTest method testGetKeystoreWithClientAuth.
@Test
public void testGetKeystoreWithClientAuth() throws Exception {
// jks format
byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);
File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
try {
keystoreFileOut.write(dummyKeystore);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
try {
truststoreFileOut.write(dummyTruststore);
} finally {
truststoreFileOut.close();
}
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = this.getClass().getName() + ".test1";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, tempTruststore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, "changeit");
RestClient client = (RestClient) ClientFactory.getNamedClient(name);
KeyStore keyStore = client.getKeyStore();
Certificate cert = keyStore.getCertificate("ribbon_key");
assertNotNull(cert);
}
use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class ClientPropertiesProcessor method exportPropertiesToArchaius.
private void exportPropertiesToArchaius(String groupName, IClientConfig config, String configName) {
Map<String, Object> map = config.getProperties();
Configuration configuration = ConfigurationManager.getConfigInstance();
if (configuration instanceof AggregatedConfiguration) {
AggregatedConfiguration ac = (AggregatedConfiguration) configuration;
configuration = ac.getConfiguration(configName);
if (configuration == null) {
configuration = new ConcurrentMapConfiguration();
ac.addConfiguration((AbstractConfiguration) configuration, configName);
}
}
for (Map.Entry<String, Object> entry : map.entrySet()) {
configuration.setProperty(groupName + "." + config.getNameSpace() + "." + entry.getKey(), entry.getValue());
}
}
Aggregations