2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.features.rest.adaptor.service;
\r
20 import java.util.Map;
\r
21 import java.util.UUID;
\r
23 import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants;
\r
24 import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException;
\r
25 import org.onap.ccsdk.features.rest.adaptor.data.RestResponse;
\r
26 import org.springframework.http.HttpHeaders;
\r
27 import org.springframework.http.MediaType;
\r
28 import com.att.eelf.configuration.EELFLogger;
\r
29 import com.att.eelf.configuration.EELFManager;
\r
31 public class SSLRestClientAdapterImpl extends AbstractConfigRestClientAdapter {
\r
33 private static EELFLogger logger = EELFManager.getInstance().getLogger(SSLRestClientAdapterImpl.class);
\r
34 private String baseUrl = "";
\r
35 private String application = "";
\r
37 public SSLRestClientAdapterImpl(Map<String, String> properties, String serviceSelector)
\r
38 throws ConfigRestAdaptorException {
\r
39 super(properties, serviceSelector);
\r
40 init(serviceSelector);
\r
43 private void init(String serviceSelector) throws ConfigRestAdaptorException {
\r
45 if (isSSLServiceAdapaterEnabled) {
\r
47 logger.info("Initializing SSL client for selector ({}), properties ({})", serviceSelector, properties);
\r
49 String baseUrlProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
50 + ConfigRestAdaptorConstants.SSL_SERVICE_BASEURL;
\r
51 String applicationProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
52 + ConfigRestAdaptorConstants.SSL_SERVICE_APP;
\r
53 String keyStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
54 + ConfigRestAdaptorConstants.SSL_SERVICE_KEY;
\r
55 String keyStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
56 + ConfigRestAdaptorConstants.SSL_SERVICE_KEY_PSSWD;
\r
57 String trustStorePathProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
58 + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST;
\r
59 String trustStorePassProp = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
\r
60 + ConfigRestAdaptorConstants.SSL_SERVICE_TRUST_PSSWD;
\r
62 baseUrl = properties.get(baseUrlProp);
\r
63 application = properties.get(applicationProp);
\r
65 String keyStorePath = properties.get(keyStorePathProp);
\r
66 String trustStorePath = properties.get(trustStorePathProp);
\r
67 String keyStorePass = properties.get(keyStorePassProp);
\r
68 String trustStorePass = properties.get(trustStorePassProp);
\r
70 initialiseSSL(keyStorePath, trustStorePath, keyStorePass, trustStorePass);
\r
71 logger.info("Initialised SSL Client Service adaptor service for selector ({})", serviceSelector);
\r
72 if (restTemplate == null) {
\r
73 throw new ConfigRestAdaptorException(
\r
74 "couldn't initialise SSL Client selector (" + serviceSelector + ")");
\r
77 throw new ConfigRestAdaptorException("SSL Client selector (" + serviceSelector + ") is not enabled");
\r
80 } catch (Exception e) {
\r
81 throw new ConfigRestAdaptorException("SSLRestClientAdapterImpl : " + e.getMessage(), e);
\r
86 public <T> T getResource(String path, Class<T> responseType) throws ConfigRestAdaptorException {
\r
87 return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType);
\r
91 public <T> T postResource(String path, Object request, Class<T> responseType) throws ConfigRestAdaptorException {
\r
92 return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType);
\r
96 public <T> T exchangeResource(String path, Object request, Class<T> responseType, String method)
\r
97 throws ConfigRestAdaptorException {
\r
98 return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method);
\r
102 public RestResponse getResource(String path) throws ConfigRestAdaptorException {
\r
103 return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path));
\r
107 public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException {
\r
108 return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request);
\r
112 public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException {
\r
113 return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method);
\r
116 private HttpHeaders formHttpHeaders() {
\r
118 HttpHeaders headers = new HttpHeaders();
\r
120 headers.setContentType(MediaType.APPLICATION_JSON);
\r
121 headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
\r
122 headers.add("X-FromAppId", application);
\r
123 headers.add("X-TransactionId", generateUUID());
\r
128 private synchronized String generateUUID() {
\r
129 return UUID.randomUUID().toString();
\r