diff options
author | 2019-04-09 10:05:57 +0000 | |
---|---|---|
committer | 2019-04-09 10:05:57 +0000 | |
commit | 76b8f35f81f389be5f4a404c994f7a02a1493973 (patch) | |
tree | 6f71bbd96cd16c897db1b0a9f60330bee93c8d24 /rest-services/dmaap-client/src/main/java | |
parent | f3f9ed25e905bb80761420ede7189a2245ffe168 (diff) | |
parent | 8daac07f7a45e38702901252972039cf8d46fe53 (diff) |
Merge "Get rid of deprecated SslFactory"
Diffstat (limited to 'rest-services/dmaap-client/src/main/java')
5 files changed, 79 insertions, 29 deletions
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactory.java index 7fd1021f..e92ad3f1 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactory.java @@ -30,12 +30,13 @@ public class ConsumerReactiveHttpClientFactory { private final DMaaPReactiveWebClientFactory reactiveWebClientFactory; - public ConsumerReactiveHttpClientFactory(DMaaPReactiveWebClientFactory reactiveWebClientFactory) { + public ConsumerReactiveHttpClientFactory( + DMaaPReactiveWebClientFactory reactiveWebClientFactory) { this.reactiveWebClientFactory = reactiveWebClientFactory; } - public DMaaPConsumerReactiveHttpClient create(DmaapConsumerConfiguration consumerConfiguration) - throws SSLException { + public DMaaPConsumerReactiveHttpClient create( + DmaapConsumerConfiguration consumerConfiguration) { return new DMaaPConsumerReactiveHttpClient(consumerConfiguration, reactiveWebClientFactory.build(consumerConfiguration)); } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactory.java index fba6f188..3d3c54af 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * DCAEGEN2-SERVICES-SDK * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer; import io.netty.handler.ssl.SslContext; -import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.utlis.SecurityKeysUtil; +import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 @@ -47,18 +48,16 @@ public class DMaaPReactiveWebClientFactory { * @return CloudHttpClient */ - public CloudHttpClient build(DmaapConsumerConfiguration consumerConfiguration) throws SSLException { + public CloudHttpClient build(DmaapConsumerConfiguration consumerConfiguration){ SslContext sslContext = createSslContext(consumerConfiguration); return new CloudHttpClient(sslContext); } - private SslContext createSslContext(DmaapConsumerConfiguration consumerConfiguration) throws SSLException { + private SslContext createSslContext(DmaapConsumerConfiguration consumerConfiguration){ if (consumerConfiguration.enableDmaapCertAuth()) { - return sslFactory.createSecureContext( - consumerConfiguration.keyStorePath(), consumerConfiguration.keyStorePasswordPath(), - consumerConfiguration.trustStorePath(), consumerConfiguration.trustStorePasswordPath() - ); + final SecurityKeys securityKeys = SecurityKeysUtil.fromDmappCustomConfig(consumerConfiguration); + return sslFactory.createSecureClientContext(securityKeys); } - return sslFactory.createInsecureContext(); + return sslFactory.createInsecureClientContext(); } } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java index 765c64b7..2d71760d 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * DCAEGEN2-SERVICES-SDK * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; import io.netty.handler.ssl.SslContext; -import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.utlis.SecurityKeysUtil; +import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory; public class DmaaPRestTemplateFactory { @@ -44,18 +45,17 @@ public class DmaaPRestTemplateFactory { * @param publisherConfiguration - DMaaP publisher configuration object * @return RestTemplate with correct ssl configuration */ - public CloudHttpClient build(DmaapPublisherConfiguration publisherConfiguration) throws SSLException { + public CloudHttpClient build(DmaapPublisherConfiguration publisherConfiguration){ SslContext sslContext = createSslContext(publisherConfiguration); return new CloudHttpClient(sslContext); } - private SslContext createSslContext(DmaapPublisherConfiguration consumerConfiguration) throws SSLException { + private SslContext createSslContext(DmaapPublisherConfiguration consumerConfiguration) { if (consumerConfiguration.enableDmaapCertAuth()) { - return sslFactory.createSecureContext( - consumerConfiguration.keyStorePath(), consumerConfiguration.keyStorePasswordPath(), - consumerConfiguration.trustStorePath(), consumerConfiguration.trustStorePasswordPath() - ); + final SecurityKeys securityKeys = SecurityKeysUtil + .fromDmappCustomConfig(consumerConfiguration); + return sslFactory.createSecureClientContext(securityKeys); } - return sslFactory.createInsecureContext(); + return sslFactory.createInsecureClientContext(); } } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java index 1cd3544e..953a3319 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * DCAEGEN2-SERVICES-SDK * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; -import javax.net.ssl.SSLException; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; @@ -31,14 +30,14 @@ public class PublisherReactiveHttpClientFactory { private final JsonBodyBuilder jsonBodyBuilder; public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory, - JsonBodyBuilder jsonBodyBuilder) { + JsonBodyBuilder jsonBodyBuilder) { this.restTemplateFactory = restTemplateFactory; this.jsonBodyBuilder = jsonBodyBuilder; } - public DMaaPPublisherReactiveHttpClient create(DmaapPublisherConfiguration publisherConfiguration) - throws SSLException { + public DMaaPPublisherReactiveHttpClient create( + DmaapPublisherConfiguration publisherConfiguration) { return new DMaaPPublisherReactiveHttpClient(publisherConfiguration, - restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder); + restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder); } } diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java new file mode 100644 index 00000000..7ee06e9c --- /dev/null +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.utlis; + +import io.vavr.control.Try; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.jetbrains.annotations.NotNull; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapCustomConfig; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys; +import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore; +import org.onap.dcaegen2.services.sdk.security.ssl.Passwords; +import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys; + +public final class SecurityKeysUtil { + + private SecurityKeysUtil(){ + + } + + @NotNull + public static SecurityKeys fromDmappCustomConfig(DmaapCustomConfig configuration){ + return ImmutableSecurityKeys.builder() + .keyStore(ImmutableSecurityKeysStore.of(resource(configuration.keyStorePath()).get())) + .keyStorePassword(Passwords.fromResource(configuration.keyStorePasswordPath())) + .trustStore(ImmutableSecurityKeysStore.of(resource(configuration.trustStorePath()).get())) + .trustStorePassword(Passwords.fromResource(configuration.trustStorePasswordPath())) + .build(); + } + + private static Try<Path> resource(String resource) { + return Try.of(() -> Paths.get(Passwords.class.getResource(resource).toURI())); + }} |