Search in sources :

Example 61 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 62 with AbstractConfiguration

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());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 63 with AbstractConfiguration

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());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 64 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) FileOutputStream(java.io.FileOutputStream) File(java.io.File) KeyStore(java.security.KeyStore) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 65 with AbstractConfiguration

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());
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) AggregatedConfiguration(com.netflix.config.AggregatedConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AggregatedConfiguration(com.netflix.config.AggregatedConfiguration) Map(java.util.Map)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2