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