Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / core / IpMappingProvider.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Map;
21 import org.springframework.beans.factory.InitializingBean;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.core.env.Environment;
24 import org.springframework.stereotype.Component;
25
26 import static com.google.common.base.Splitter.on;
27 import static com.google.common.collect.Lists.newArrayList;
28
29 /**
30  * Responsible for remapping IP/DNS names in URLs based on property file
31  */
32 @Component
33 public class IpMappingProvider implements InitializingBean {
34     public static final String IP_MAP = "ipMap";
35     private final Environment environment;
36     private final Map<String, String> ipMap = new HashMap<>();
37
38     @Autowired
39     IpMappingProvider(Environment environment) {
40         this.environment = environment;
41     }
42
43     /**
44      * After the Bean has been initialized the IP mapping and the VMFM cache is initialized
45      * It is done in this phase because it requires the environment to be initialized
46      */
47     @Override
48     public void afterPropertiesSet() throws Exception {
49         on(",").trimResults().omitEmptyStrings().split(environment.getProperty(IP_MAP, String.class, "")).forEach(item -> {
50             ArrayList<String> ip = newArrayList(on("->").trimResults().split(item));
51             ipMap.put(ip.get(0), ip.get(1));
52         });
53     }
54
55     /**
56      * Map IP addresses based on configuration parameter ipMap
57      *
58      * @param ip the original IP address
59      * @return the mapped IP address
60      */
61     public String mapPrivateIpToPublicIp(String ip) {
62         return ipMap.getOrDefault(ip, ip);
63     }
64 }