From 5e126dcdad725c6082f9244727a282d9b925d111 Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 19 Jun 2017 18:51:16 +0300 Subject: [SDC-34] DMAAP support both http and https Change-Id: I2b9ce002ea1f02d170b71a594857da407f432078 Signed-off-by: Pavel Aharoni --- pom.xml | 2 +- sdc-distribution-ci/pom.xml | 2 +- .../org/openecomp/test/SimpleConfiguration.java | 5 ++++ sdc-distribution-client/pom.xml | 2 +- .../openecomp/sdc/api/consumer/IConfiguration.java | 8 ++++++ .../java/org/openecomp/sdc/impl/Configuration.java | 33 ++++++++++++++-------- .../openecomp/sdc/impl/DistributionClientImpl.java | 18 +++++++++--- .../org/openecomp/sdc/utils/TestConfiguration.java | 6 ++++ 8 files changed, 58 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 0e7019a..24f4e87 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.31-SNAPSHOT + 1.1.32-SNAPSHOT pom diff --git a/sdc-distribution-ci/pom.xml b/sdc-distribution-ci/pom.xml index 74c4b9a..e4c2152 100644 --- a/sdc-distribution-ci/pom.xml +++ b/sdc-distribution-ci/pom.xml @@ -6,7 +6,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.31-SNAPSHOT + 1.1.32-SNAPSHOT sdc-distribution-ci diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java index 115bfab..60bb7d4 100644 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java +++ b/sdc-distribution-ci/src/main/java/org/openecomp/test/SimpleConfiguration.java @@ -184,4 +184,9 @@ public class SimpleConfiguration implements IConfiguration{ return false; } + @Override + public Boolean isUseHttpsWithDmaap() { + return true; + } + } diff --git a/sdc-distribution-client/pom.xml b/sdc-distribution-client/pom.xml index 958e9a6..39dbbfc 100644 --- a/sdc-distribution-client/pom.xml +++ b/sdc-distribution-client/pom.xml @@ -6,7 +6,7 @@ org.openecomp.sdc.sdc-distribution-client sdc-main-distribution-client - 1.1.31-SNAPSHOT + 1.1.32-SNAPSHOT sdc-distribution-client diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/api/consumer/IConfiguration.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/api/consumer/IConfiguration.java index 77f09e6..19f94df 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/api/consumer/IConfiguration.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/api/consumer/IConfiguration.java @@ -108,6 +108,14 @@ public interface IConfiguration { * @return */ boolean isFilterInEmptyResources(); + + /** + * By default, Distribution Client will use HTTPS (TLS 1.2) when connecting to DMAAP. + * This param can be null, then default (HTTPS) behavior will be applied. + * If set to false, distribution client will use HTTP when connecting to DMAAP. + * @return + */ + Boolean isUseHttpsWithDmaap(); } diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/Configuration.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/Configuration.java index fde5c57..dff8a3b 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/Configuration.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/Configuration.java @@ -41,6 +41,7 @@ public class Configuration implements IConfiguration{ private String keyStorePassword; private boolean activateServerTLSAuth; private boolean filterInEmptyResources; + private Boolean useHttpsWithDmaap; public Configuration(IConfiguration other) { this.asdcAddress = other.getAsdcAddress(); @@ -56,6 +57,7 @@ public class Configuration implements IConfiguration{ this.keyStorePassword = other.getKeyStorePassword(); this.activateServerTLSAuth = other.activateServerTLSAuth(); this.filterInEmptyResources = other.isFilterInEmptyResources(); + this.useHttpsWithDmaap = other.isUseHttpsWithDmaap(); } @Override @@ -161,17 +163,7 @@ public class Configuration implements IConfiguration{ this.keyStorePassword = keyStorePassword; } - @Override - public String toString() { - return "Configuration [asdcAddress=" + asdcAddress + ", user=" + user - + ", password=" + password + ", pollingInterval=" - + pollingInterval + ", pollingTimeout=" + pollingTimeout - + ", relevantArtifactTypes=" + relevantArtifactTypes - + ", consumerGroup=" + consumerGroup + ", environmentName=" - + environmentName + ", comsumerID=" + comsumerID + "]"; - } - - + public void setactivateServerTLSAuth(boolean activateServerTLSAuth) { this.activateServerTLSAuth = activateServerTLSAuth; } @@ -186,4 +178,23 @@ public class Configuration implements IConfiguration{ return this.filterInEmptyResources; } + @Override + public Boolean isUseHttpsWithDmaap() { + return this.useHttpsWithDmaap; + } + + public void setUseHttpsWithDmaap(boolean useHttpsWithDmaap){ + this.useHttpsWithDmaap = useHttpsWithDmaap; + } + + @Override + public String toString() { + return "Configuration [asdcAddress=" + asdcAddress + ", user=" + user + ", password=" + password + + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + + ", relevantArtifactTypes=" + relevantArtifactTypes + ", consumerGroup=" + consumerGroup + + ", environmentName=" + environmentName + ", comsumerID=" + comsumerID + ", keyStorePath=" + + keyStorePath + ", keyStorePassword=" + keyStorePassword + ", activateServerTLSAuth=" + + activateServerTLSAuth + ", filterInEmptyResources=" + filterInEmptyResources + ", useHttpsWithDmaap=" + + useHttpsWithDmaap + "]"; + } } diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/DistributionClientImpl.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/DistributionClientImpl.java index d051458..1543256 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/DistributionClientImpl.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/impl/DistributionClientImpl.java @@ -54,9 +54,10 @@ import com.att.nsa.apiClient.credentials.ApiCredential; import com.att.nsa.apiClient.http.HttpException; import com.att.nsa.cambria.client.CambriaBatchingPublisher; import com.att.nsa.cambria.client.CambriaClient.CambriaApiException; -import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; +import com.att.nsa.cambria.client.CambriaClientBuilders.AbstractAuthenticatedManagerBuilder; import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder; import com.att.nsa.cambria.client.CambriaClientBuilders.IdentityManagerBuilder; +import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; import com.att.nsa.cambria.client.CambriaConsumer; import com.att.nsa.cambria.client.CambriaIdentityManager; import com.att.nsa.cambria.client.CambriaPublisher.message; @@ -146,7 +147,7 @@ public class DistributionClientImpl implements IDistributionClient { } if (errorWrapper.isEmpty()) { try { - cambriaConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(notificationTopic).usingHttps().usingHosts(brokerServers) + cambriaConsumer = new ConsumerBuilder().authenticatedBy(credential.getApiKey(), credential.getApiSecret()).knownAs(configuration.getConsumerGroup(), configuration.getConsumerID()).onTopic(notificationTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers) .withSocketTimeout(configuration.getPollingTimeout() * 1000).build(); } catch (MalformedURLException | GeneralSecurityException e) { handleCambriaInitFailure(errorWrapper, e); @@ -393,7 +394,7 @@ public class DistributionClientImpl implements IDistributionClient { private Either getCambriaPublisher() { CambriaBatchingPublisher cambriaPublisher = null; try { - cambriaPublisher = new PublisherBuilder().onTopic(statusTopic).usingHttps().usingHosts(brokerServers).build(); + cambriaPublisher = new PublisherBuilder().onTopic(statusTopic).usingHttps(configuration.isUseHttpsWithDmaap()).usingHosts(brokerServers).build(); cambriaPublisher.setApiCredentials(credential.getApiKey(), credential.getApiSecret()); } catch (MalformedURLException | GeneralSecurityException e) { Wrapper errorWrapper = new Wrapper<>(); @@ -477,6 +478,11 @@ public class DistributionClientImpl implements IDistributionClient { if (conf.getConsumerGroup() == null) { generateConsumerGroup(); } + + //Default use HTTPS with DMAAP + if (conf.isUseHttpsWithDmaap() == null){ + configuration.setUseHttpsWithDmaap(true); + } } if (result != DistributionActionResultEnum.SUCCESS) { @@ -582,7 +588,11 @@ public class DistributionClientImpl implements IDistributionClient { private synchronized void initCambriaClient(Wrapper errorWrapper) { if (cambriaIdentityManager == null) { try { - cambriaIdentityManager = new IdentityManagerBuilder().usingHttps().usingHosts(brokerServers).build(); + AbstractAuthenticatedManagerBuilder managerBuilder = new IdentityManagerBuilder().usingHosts(brokerServers); + if (configuration.isUseHttpsWithDmaap()){ + managerBuilder = managerBuilder.usingHttps(); + } + cambriaIdentityManager = managerBuilder.build(); } catch (MalformedURLException | GeneralSecurityException e) { handleCambriaInitFailure(errorWrapper, e); } diff --git a/sdc-distribution-client/src/test/java/org/openecomp/sdc/utils/TestConfiguration.java b/sdc-distribution-client/src/test/java/org/openecomp/sdc/utils/TestConfiguration.java index d6b17e1..727f9a6 100644 --- a/sdc-distribution-client/src/test/java/org/openecomp/sdc/utils/TestConfiguration.java +++ b/sdc-distribution-client/src/test/java/org/openecomp/sdc/utils/TestConfiguration.java @@ -42,6 +42,7 @@ public class TestConfiguration implements IConfiguration { private String keyStorePassword; private boolean activateServerTLSAuth; private boolean isFilterInEmptyResources; + private boolean useHttpsWithDmaap; public TestConfiguration(IConfiguration other) { this.asdcAddress = other.getAsdcAddress(); @@ -282,4 +283,9 @@ public class TestConfiguration implements IConfiguration { public void setFilterInEmptyResources(boolean isFilterInEmptyResources) { this.isFilterInEmptyResources = isFilterInEmptyResources; } + + @Override + public Boolean isUseHttpsWithDmaap() { + return this.useHttpsWithDmaap; + } } -- cgit 1.2.3-korg