2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.controllers;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.onap.vid.aai.*;
26 import org.onap.vid.aai.model.PortDetailsTranslator;
27 import org.onap.vid.aai.util.*;
28 import org.onap.vid.asdc.AsdcClient;
29 import org.onap.vid.asdc.parser.ToscaParserImpl2;
30 import org.onap.vid.asdc.rest.RestfulAsdcClient;
31 import org.onap.vid.exceptions.GenericUncheckedException;
32 import org.onap.vid.properties.AsdcClientConfiguration;
33 import org.onap.vid.services.*;
34 import org.springframework.beans.factory.annotation.Qualifier;
35 import org.springframework.context.annotation.Bean;
36 import org.springframework.context.annotation.Configuration;
37 import org.togglz.core.manager.FeatureManager;
39 import javax.net.ssl.SSLContext;
40 import javax.servlet.ServletContext;
41 import javax.ws.rs.client.Client;
42 import javax.ws.rs.client.ClientBuilder;
45 import java.net.URISyntaxException;
46 import java.security.KeyManagementException;
47 import java.security.NoSuchAlgorithmException;
50 public class WebConfig {
53 * Gets the object mapper.
55 * @return the object mapper
58 public ObjectMapper getObjectMapper() {
59 return new ObjectMapper();
64 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
65 return new VidServiceImpl(asdcClient, featureManager);
69 public AaiService getAaiService() {
70 return new AaiServiceImpl();
74 public AaiResponseTranslator aaiResponseTranslator() {
75 return new AaiResponseTranslator();
79 public PortDetailsTranslator portDetailsTranslator() {
80 return new PortDetailsTranslator();
84 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator) {
85 return new AaiClient(restController, portsDetailsTranslator);
88 @Bean(name = "aaiRestInterface")
89 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
90 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
94 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
95 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
99 public SSLContextProvider sslContextProvider() {
100 return new SSLContextProvider();
104 public SystemPropertyHelper systemPropertyHelper() {
105 return new SystemPropertyHelper();
109 public ServletRequestHelper servletRequestHelper() {
110 return new ServletRequestHelper();
114 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) {
115 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
116 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider);
120 public AsdcClient asdcClient(AsdcClientConfiguration asdcClientConfig) {
122 final String protocol = asdcClientConfig.getAsdcClientProtocol();
123 final String host = asdcClientConfig.getAsdcClientHost();
124 final int port = asdcClientConfig.getAsdcClientPort();
125 final String auth = asdcClientConfig.getAsdcClientAuth();
127 if (protocol.equalsIgnoreCase("https")) {
129 SSLContext ctx = SSLContext.getInstance("TLSv1.2");
130 ctx.init(null, null, null);
131 cl = ClientBuilder.newBuilder().sslContext(ctx).build();
132 } catch (NoSuchAlgorithmException n) {
133 throw new GenericUncheckedException("SDC Client could not be instantiated due to unsupported protocol TLSv1.2", n);
134 } catch (KeyManagementException k) {
135 throw new GenericUncheckedException("SDC Client could not be instantiated due to a key management exception", k);
138 cl = ClientBuilder.newBuilder().build();
142 final URI uri = new URI(protocol + "://" + host + ":" + port + "/");
143 return new RestfulAsdcClient.Builder(cl, uri)
146 } catch (URISyntaxException e) {
147 throw new GenericUncheckedException("SDC Client could not be instantiated due to a syntax error in the URI", e);
152 public ToscaParserImpl2 getToscaParser() {
153 return new ToscaParserImpl2();
157 public PombaService getVerifyServiceInstanceService() {
158 return new PombaServiceImpl();
162 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
163 return new PombaClientImpl();