diff options
Diffstat (limited to 'vnfm-simulator/vnfm-service/src/main')
4 files changed, 69 insertions, 64 deletions
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/ApplicationConfig.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/ApplicationConfig.java index 32c05ebca8..a1abb05f07 100644 --- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/ApplicationConfig.java +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/ApplicationConfig.java @@ -1,6 +1,5 @@ package org.onap.svnfm.simulator.config; -import java.net.InetAddress; import java.util.Arrays; import org.onap.svnfm.simulator.constants.Constant; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +22,9 @@ public class ApplicationConfig implements ApplicationRunner { @Value("${server.dns.name:so-vnfm-simulator.onap}") private String serverDnsName; + @Value("${server.request.grant.auth:oauth}") + private String grantAuth; + @Autowired private Environment environment; @@ -37,6 +39,10 @@ public class ApplicationConfig implements ApplicationRunner { return baseUrl; } + public String getGrantAuth() { + return grantAuth; + } + @Bean public CacheManager cacheManager() { final Cache inlineResponse201 = new ConcurrentMapCache(Constant.IN_LINE_RESPONSE_201_CACHE); diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java index d3ff66aed0..2140b57488 100644 --- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java @@ -26,7 +26,6 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; import org.onap.svnfm.simulator.constants.Constant; import org.onap.svnfm.simulator.repository.VnfmCacheRepository; @@ -101,13 +100,12 @@ public class SvnfmController { * @throws InterruptedException */ @PostMapping(value = "/vnf_instances/{vnfInstanceId}/instantiate") - public ResponseEntity<Void> instantiateVnf(@PathVariable("vnfInstanceId") final String vnfId, - @RequestBody final InstantiateVnfRequest instantiateVNFRequest) { - LOGGER.info("Start instantiateVNFRequest {} ", instantiateVNFRequest); + public ResponseEntity<Void> instantiateVnf(@PathVariable("vnfInstanceId") final String vnfId) { + LOGGER.info("Start instantiateVNFRequest for vnf id {} ", vnfId); final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); - headers.add(HttpHeaders.LOCATION, svnfmService.instantiateVnf(vnfId, instantiateVNFRequest)); + headers.add(HttpHeaders.LOCATION, svnfmService.instantiateVnf(vnfId)); return new ResponseEntity<>(headers, HttpStatus.ACCEPTED); } diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java index eed62780c0..6e9478bdeb 100644 --- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java @@ -8,10 +8,17 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.List; import java.util.UUID; import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; import javax.ws.rs.core.MediaType; import org.apache.commons.codec.binary.Base64; import org.modelmapper.ModelMapper; @@ -44,12 +51,16 @@ import org.onap.svnfm.simulator.repository.VnfOperationRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; public abstract class OperationProgressor implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(OperationProgressor.class); private static final String CERTIFICATE_TO_TRUST = "so-vnfm-adapter.crt.pem"; + private Resource keyStoreResource = new ClassPathResource("so-vnfm-simulator.p12"); + private String keyStorePassword = "7Em3&j4.19xYiMelhD5?xbQ."; + protected final VnfOperation operation; protected final SvnfmService svnfmService; private final VnfOperationRepository vnfOperationRepository; @@ -73,12 +84,14 @@ public abstract class OperationProgressor implements Runnable { String callBackUrl = subscriptionService.getSubscriptions().iterator().next().getCallbackUri(); callBackUrl = callBackUrl.substring(0, callBackUrl.indexOf("/lcn/")); apiClient.setBasePath(callBackUrl); + apiClient.setKeyManagers(getKeyManagers()); apiClient.setSslCaCert(getCertificateToTrust()); notificationClient = new DefaultApi(apiClient); final org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.ApiClient grantApiClient = new org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.ApiClient(); grantApiClient.setBasePath(callBackUrl); + grantApiClient.setKeyManagers(getKeyManagers()); grantApiClient.setSslCaCert(getCertificateToTrust()); grantClient = new org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.api.DefaultApi(grantApiClient); } @@ -92,6 +105,22 @@ public abstract class OperationProgressor implements Runnable { } } + private KeyManager[] getKeyManagers() { + KeyStore keystore; + try { + keystore = KeyStore.getInstance("pkcs12"); + keystore.load(keyStoreResource.getInputStream(), keyStorePassword.toCharArray()); + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keystore, keyStorePassword.toCharArray()); + return keyManagerFactory.getKeyManagers(); + } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException + | UnrecoverableKeyException exception) { + LOGGER.error("Error reading certificate, https calls using two way TLS to VNFM adapter will fail", + exception); + return new KeyManager[0]; + } + } + @Override public void run() { try { @@ -247,8 +276,10 @@ public abstract class OperationProgressor implements Runnable { final SubscriptionsAuthenticationParamsOauth2ClientCredentials subscriptionAuthentication = subscriptionService.getSubscriptions().iterator().next().getAuthentication() .getParamsOauth2ClientCredentials(); - final String authHeader = - "Bearer " + getToken(notificationClient.getApiClient(), subscriptionAuthentication); + + final String authHeader = applicationConfig.getGrantAuth().equals("oauth") + ? "Bearer " + getToken(notificationClient.getApiClient(), subscriptionAuthentication) + : null; final ApiResponse<InlineResponse201> response = grantClient.grantsPostWithHttpInfo(grantRequest, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, authHeader); diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java index 21bb00dba7..95043d35ed 100644 --- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java @@ -32,7 +32,6 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest; import org.onap.svnfm.simulator.config.ApplicationConfig; import org.onap.svnfm.simulator.constants.Constant; @@ -60,36 +59,31 @@ import org.springframework.stereotype.Service; @Service public class SvnfmService { - @Autowired - VnfmRepository vnfmRepository; - - @Autowired - VnfOperationRepository vnfOperationRepository; - - @Autowired + private VnfmRepository vnfmRepository; + private VnfOperationRepository vnfOperationRepository; private VnfmHelper vnfmHelper; - - @Autowired - ApplicationConfig applicationConfig; - - @Autowired - CacheManager cacheManager; - - @Autowired - Vnfds vnfds; - - @Autowired - SubscriptionService subscriptionService; + private ApplicationConfig applicationConfig; + private CacheManager cacheManager; + private Vnfds vnfds; + private SubscriptionService subscriptionService; private final ExecutorService executor = Executors.newCachedThreadPool(); private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmService.class); - /** - * - * @param createVNFRequest - * @return inlineResponse201 - */ + @Autowired + public SvnfmService(VnfmRepository vnfmRepository, VnfOperationRepository vnfOperationRepository, + VnfmHelper vnfmHelper, ApplicationConfig applicationConfig, CacheManager cacheManager, Vnfds vnfds, + SubscriptionService subscriptionService) { + this.vnfmRepository = vnfmRepository; + this.vnfOperationRepository = vnfOperationRepository; + this.vnfmHelper = vnfmHelper; + this.applicationConfig = applicationConfig; + this.cacheManager = cacheManager; + this.vnfds = vnfds; + this.subscriptionService = subscriptionService; + } + public InlineResponse201 createVnf(final CreateVnfRequest createVNFRequest, final String id) { InlineResponse201 inlineResponse201 = null; try { @@ -106,24 +100,16 @@ public class SvnfmService { } @CachePut(value = Constant.IN_LINE_RESPONSE_201_CACHE, key = "#id") - public InlineResponse201 updateVnf(final InstantiationStateEnum instantiationState, + public void updateVnf(final InstantiationStateEnum instantiationState, final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo, final String id, final List<InlineResponse201VimConnectionInfo> vimConnectionInfo) { final InlineResponse201 vnf = getVnf(id); vnf.setInstantiatedVnfInfo(instantiatedVnfInfo); vnf.setInstantiationState(instantiationState); vnf.setVimConnectionInfo(vimConnectionInfo); - return vnf; } - /** - * - * @param vnfId - * @param instantiateVNFRequest - * @param operationId - * @throws InterruptedException - */ - public String instantiateVnf(final String vnfId, final InstantiateVnfRequest instantiateVNFRequest) { + public String instantiateVnf(final String vnfId) { final VnfOperation vnfOperation = buildVnfOperation(InlineResponse200.OperationEnum.INSTANTIATE, vnfId); vnfOperationRepository.save(vnfOperation); executor.submit(new InstantiateOperationProgressor(vnfOperation, this, vnfOperationRepository, @@ -131,13 +117,7 @@ public class SvnfmService { return vnfOperation.getId(); } - /** - * vnfOperationRepository - * - * @param vnfId - * @param instantiateOperationId - */ - public VnfOperation buildVnfOperation(final InlineResponse200.OperationEnum operation, final String vnfId) { + private VnfOperation buildVnfOperation(final InlineResponse200.OperationEnum operation, final String vnfId) { final VnfOperation vnfOperation = new VnfOperation(); vnfOperation.setId(UUID.randomUUID().toString()); vnfOperation.setOperation(operation); @@ -146,11 +126,6 @@ public class SvnfmService { return vnfOperation; } - /** - * - * @param operationId - * @throws InterruptedException - */ public InlineResponse200 getOperationStatus(final String operationId) { LOGGER.info("Getting operation status with id: {}", operationId); final Thread instantiationNotification = new Thread(new VnfInstantiationNotification()); @@ -165,14 +140,13 @@ public class SvnfmService { return null; } - /** - * - * @param vnfId - * @return inlineResponse201 - */ public InlineResponse201 getVnf(final String vnfId) { final Cache ca = cacheManager.getCache(Constant.IN_LINE_RESPONSE_201_CACHE); + if (ca == null) + return null; final SimpleValueWrapper wrapper = (SimpleValueWrapper) ca.get(vnfId); + if (wrapper == null) + return null; final InlineResponse201 inlineResponse201 = (InlineResponse201) wrapper.get(); if (inlineResponse201 != null) { LOGGER.info("Cache Read Successful"); @@ -181,10 +155,6 @@ public class SvnfmService { return null; } - /** - * @param vnfId - * @return - */ public String terminateVnf(final String vnfId) { final VnfOperation vnfOperation = buildVnfOperation(InlineResponse200.OperationEnum.TERMINATE, vnfId); vnfOperationRepository.save(vnfOperation); |