Security Fix 55/38955/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 27 Mar 2018 08:25:41 +0000 (10:25 +0200)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 27 Mar 2018 08:25:41 +0000 (10:25 +0200)
Introduce a centralized ObjectMapper for Resteasy and Clamp code
so that the automatic Ser/deserialization of all classes is disabled.

Issue-ID: CLAMP-135
Change-Id: I1fb11c8fc8e7a53ef832774fa8c06af1c70d3dad
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
19 files changed:
pom.xml
src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java
src/main/java/org/onap/clamp/clds/client/req/sdc/SdcRequests.java
src/main/java/org/onap/clamp/clds/config/ClampProperties.java
src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
src/main/java/org/onap/clamp/clds/config/sdc/BlueprintParserMappingConfiguration.java
src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java
src/main/java/org/onap/clamp/clds/model/CldsModel.java
src/main/java/org/onap/clamp/clds/model/properties/ModelBpmn.java
src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java
src/main/java/org/onap/clamp/clds/service/CldsService.java
src/main/java/org/onap/clamp/clds/service/JacksonObjectMapperProvider.java [new file with mode: 0644]
src/main/java/org/onap/clamp/clds/service/JaxrsApplication.java
src/main/java/org/onap/clamp/clds/util/JacksonUtils.java [new file with mode: 0644]
src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java [new file with mode: 0644]
src/test/java/org/onap/clamp/clds/util/TestObject.java [new file with mode: 0644]
src/test/java/org/onap/clamp/clds/util/TestObject2.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 86461c5..4b19b80 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,7 @@
            By Default "mvn clean install" command will execute also the unit tests
            and the integration tests. The integration tests require a docker engine running.
 
-           If you want to skip the intergation test you can by doing:
+           If you want to skip the integration test you can by doing:
            "mvn clean install -DskipITs=true"
 
            For Spring it's possible to specify the application.properties location
                                        <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
                                        <version>1.0.1.Final</version>
                                </dependency>
-                               <dependency>
-                                               <artifactId>jackson-databind</artifactId>
-                                               <groupId>com.fasterxml.jackson.core</groupId>
-                                               <version>2.9.4</version>
-                               </dependency>
-                               <dependency>
-                                               <groupId>com.fasterxml.jackson.core</groupId>
-                                               <artifactId>jackson-annotations</artifactId>
-                                               <version>2.9.4</version>
-                               </dependency>
-                               <dependency>
-                                               <groupId>com.fasterxml.jackson.core</groupId>
-                                               <artifactId>jackson-core</artifactId>
-                                               <version>2.9.4</version>
-                               </dependency>
-                               <dependency>
-                                               <groupId>com.fasterxml.jackson.dataformat</groupId>
-                                               <artifactId>jackson-dataformat-yaml</artifactId>
-                                               <version>2.9.4</version>
-                               </dependency>
                                <!-- Remove the MYSQL connector and replace it by Mariadb -->
                                <dependency>
                                                <groupId>org.mariadb.jdbc</groupId>
index 9226604..f20668e 100644 (file)
@@ -152,6 +152,8 @@ public class DcaeDispatcherServices {
      *            The deployment ID\r
      * @param serviceTypeId\r
      *            Service type ID\r
+     * @param blueprintInput\r
+     *            The value for each blueprint parameters in a flat JSON\r
      * @return The status URL\r
      */\r
     public String createNewDeployment(String deploymentId, String serviceTypeId) {\r
index d501504..ffc9b8e 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.client;
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
 import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
 import com.fasterxml.jackson.databind.node.ObjectNode;\r
 \r
 import java.io.IOException;\r
@@ -47,6 +46,7 @@ import org.onap.clamp.clds.model.DcaeEvent;
 import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;\r
 import org.onap.clamp.clds.model.properties.Global;\r
 import org.onap.clamp.clds.model.properties.ModelProperties;\r
+import org.onap.clamp.clds.util.JacksonUtils;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.stereotype.Component;\r
@@ -182,7 +182,7 @@ public class DcaeInventoryServices {
         LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());\r
         LoggingUtils.setTimeContext(startTime, new Date());\r
         metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);\r
-        return new ObjectMapper().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);\r
+        return JacksonUtils.getObjectMapperInstance().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);\r
     }\r
 \r
     /**\r
@@ -210,8 +210,7 @@ public class DcaeInventoryServices {
         LoggingUtils.setTargetContext("DCAE", "createDCAEServiceType");\r
         String typeId = null;\r
         try {\r
-            ObjectMapper mapper = new ObjectMapper();\r
-            ObjectNode dcaeServiceTypeRequest = mapper.createObjectNode();\r
+            ObjectNode dcaeServiceTypeRequest = JacksonUtils.getObjectMapperInstance().createObjectNode();\r
             dcaeServiceTypeRequest.put("blueprintTemplate", blueprintTemplate);\r
             dcaeServiceTypeRequest.put("owner", owner);\r
             dcaeServiceTypeRequest.put("typeName", typeName);\r
index fd7d096..ce3c8ba 100644 (file)
@@ -74,6 +74,7 @@ import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;\r
 import org.onap.clamp.clds.service.CldsService;\r
 import org.onap.clamp.clds.util.CryptoUtils;\r
+import org.onap.clamp.clds.util.JacksonUtils;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.stereotype.Component;\r
@@ -284,13 +285,12 @@ public class SdcCatalogServices {
      *         an empty list\r
      */\r
     private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
         if (StringUtils.isBlank(jsonStr)) {\r
             return new ArrayList<>();\r
         }\r
         try {\r
-            return objectMapper.readValue(jsonStr,\r
-                    objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
+            return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+                    .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
         } catch (IOException e) {\r
             logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
             return new ArrayList<>();\r
@@ -306,13 +306,12 @@ public class SdcCatalogServices {
      *         issues\r
      */\r
     private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
         if (StringUtils.isBlank(jsonStr)) {\r
             return new ArrayList<>();\r
         }\r
         try {\r
-            return objectMapper.readValue(jsonStr,\r
-                    objectMapper.getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
+            return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+                    .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
         } catch (IOException e) {\r
             logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
             return new ArrayList<>();\r
@@ -326,9 +325,8 @@ public class SdcCatalogServices {
      * @return\r
      */\r
     public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
         try {\r
-            return objectMapper.readValue(jsonStr, SdcServiceDetail.class);\r
+            return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, SdcServiceDetail.class);\r
         } catch (IOException e) {\r
             logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
             return null;\r
@@ -470,12 +468,12 @@ public class SdcCatalogServices {
         String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
         String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;\r
         String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
         CldsServiceData cldsServiceData = new CldsServiceData();\r
         if (responseStr != null) {\r
             SdcServiceDetail cldsSdcServiceDetail;\r
             try {\r
-                cldsSdcServiceDetail = objectMapper.readValue(responseStr, SdcServiceDetail.class);\r
+                cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr,\r
+                        SdcServiceDetail.class);\r
             } catch (IOException e) {\r
                 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
                 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
@@ -568,11 +566,10 @@ public class SdcCatalogServices {
         }\r
     }\r
 \r
-    private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException {\r
-        ObjectMapper mapper = new ObjectMapper();\r
+    private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
         ObjectNode vfResponseNode;\r
         try {\r
-            vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+            vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
         } catch (IOException e) {\r
             logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
             return new ArrayList<>();\r
@@ -614,8 +611,7 @@ public class SdcCatalogServices {
             String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;\r
             try {\r
                 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);\r
-                ObjectMapper mapper = new ObjectMapper();\r
-                ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+                ObjectNode vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
                 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
                 if (vfcArrayNode != null) {\r
                     for (JsonNode vfcjsonNode : vfcArrayNode) {\r
@@ -639,10 +635,9 @@ public class SdcCatalogServices {
 \r
     private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {\r
         List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
-        ObjectMapper mapper = new ObjectMapper();\r
         ObjectNode vfcResponseNode;\r
         try {\r
-            vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+            vfcResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
         } catch (IOException e) {\r
             logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
             return cldsAlarmConditionList;\r
@@ -684,10 +679,9 @@ public class SdcCatalogServices {
     // Method to get the artifact for any particular VF\r
     private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {\r
         List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
-        ObjectMapper mapper = new ObjectMapper();\r
         ObjectNode vfResponseNode;\r
         try {\r
-            vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+            vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
         } catch (IOException e) {\r
             logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
             return cldsVfKPIDataList;\r
@@ -846,24 +840,23 @@ public class SdcCatalogServices {
      */\r
     public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {\r
         String totalPropsStr;\r
-        ObjectMapper mapper = new ObjectMapper();\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY);\r
         if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
             // Objectnode to save all byservice, byvf , byvfc and byalarm nodes\r
             ObjectNode byIdObjectNode = mapper.createObjectNode();\r
             // To create vf ResourceUUID node with serviceInvariantUUID\r
-            ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,\r
-                    cldsServiceData);\r
+            ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData);\r
             byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);\r
             // To create byVf and vfcResourceNode with vfResourceUUID\r
-            ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());\r
+            ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs());\r
             byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);\r
             // To create byKpi\r
             ObjectNode kpiObjectNode = mapper.createObjectNode();\r
             if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
                     if (currCldsVfData != null) {\r
-                        createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());\r
+                        createKpiObjectNodeByVfUuid(kpiObjectNode, currCldsVfData.getCldsKPIList());\r
                     }\r
                 }\r
             }\r
@@ -873,8 +866,7 @@ public class SdcCatalogServices {
             if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
                     if (currCldsVfData != null) {\r
-                        createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
-                                currCldsVfData.getCldsVfcs());\r
+                        createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs());\r
                     }\r
                 }\r
             }\r
@@ -882,12 +874,12 @@ public class SdcCatalogServices {
             // To create byAlarmCondition with alarmConditionKey\r
             List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
                     "alarmCondition");\r
-            ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);\r
+            ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);\r
             byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
             // To create byAlertDescription with AlertDescription\r
             List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
                     "alertDescription");\r
-            ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);\r
+            ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);\r
             byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
             globalPropsJson.putPOJO("shared", byIdObjectNode);\r
             logger.info("Global properties JSON created with SDC info:" + globalPropsJson);\r
@@ -963,8 +955,8 @@ public class SdcCatalogServices {
         return alarmCondList;\r
     }\r
 \r
-    private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,\r
-            List<CldsAlarmCondition> cldsAlarmCondList) {\r
+    private ObjectNode createAlarmCondObjectNodeByAlarmKey(List<CldsAlarmCondition> cldsAlarmCondList) {\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
         if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
             for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
@@ -984,7 +976,8 @@ public class SdcCatalogServices {
         return alarmCondKeyNode;\r
     }\r
 \r
-    private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {\r
+    private ObjectNode createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) {\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         ObjectNode invariantUuidObjectNode = mapper.createObjectNode();\r
         ObjectNode vfObjectNode = mapper.createObjectNode();\r
         ObjectNode vfUuidNode = mapper.createObjectNode();\r
@@ -1003,8 +996,9 @@ public class SdcCatalogServices {
         return invariantUuidObjectNode;\r
     }\r
 \r
-    private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
+    private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode,\r
             List<CldsVfKPIData> cldsVfKpiDataList) {\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
             for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
                 if (currCldsVfKpiData != null) {\r
@@ -1022,8 +1016,9 @@ public class SdcCatalogServices {
         }\r
     }\r
 \r
-    private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,\r
+    private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode,\r
             List<CldsVfcData> cldsVfcDataList) {\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         ObjectNode vfcObjectNode = mapper.createObjectNode();\r
         ObjectNode alarmCondNode = mapper.createObjectNode();\r
         ObjectNode alertDescNode = mapper.createObjectNode();\r
@@ -1063,7 +1058,8 @@ public class SdcCatalogServices {
      * @param cldsVfDataList\r
      * @return\r
      */\r
-    private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
+    private ObjectNode createVfcObjectNodeByVfUuid(List<CldsVfData> cldsVfDataList) {\r
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
         ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
         if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
             for (CldsVfData currCldsVfData : cldsVfDataList) {\r
index e34b7e9..c76607a 100644 (file)
@@ -47,6 +47,7 @@ import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.model.properties.Tca;
 import org.onap.clamp.clds.model.sdc.SdcResource;
 import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
+import org.onap.clamp.clds.util.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -95,7 +96,7 @@ public class SdcRequests {
      * @return SDC Locations request in the JSON Format
      */
     public String formatSdcLocationsReq(ModelProperties prop, String artifactName) {
-        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectMapper objectMapper = JacksonUtils.getObjectMapperInstance();
         Global global = prop.getGlobal();
         List<String> locationsList = global.getLocation();
         ArrayNode locationsArrayNode = objectMapper.createArrayNode();
@@ -203,9 +204,8 @@ public class SdcRequests {
      *             In case of issues with the Json parser
      */
     protected String getYamlvalue(String jsonGlobal) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
         String yamlFileValue = "";
-        ObjectNode root = objectMapper.readValue(jsonGlobal, ObjectNode.class);
+        ObjectNode root = JacksonUtils.getObjectMapperInstance().readValue(jsonGlobal, ObjectNode.class);
         Iterator<Entry<String, JsonNode>> entryItr = root.fields();
         while (entryItr.hasNext()) {
             Entry<String, JsonNode> entry = entryItr.next();
index 66f35ac..1c1bd7f 100644 (file)
 package org.onap.clamp.clds.config;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.io.IOUtils;
+import org.onap.clamp.clds.util.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.core.env.Environment;
@@ -88,9 +88,10 @@ public class ClampProperties {
      *             In case of issues with the JSON parser
      */
     public JsonNode getJsonTemplate(String key) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
         String fileReference = getStringValue(key);
-        return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class)
+        return (fileReference != null)
+                ? JacksonUtils.getObjectMapperInstance().readValue(getFileContentFromPath(fileReference),
+                        JsonNode.class)
                 : null;
     }
 
@@ -108,9 +109,10 @@ public class ClampProperties {
      *             In case of issues with the JSON parser
      */
     public JsonNode getJsonTemplate(String key1, String key2) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
         String fileReference = getStringValue(key1, key2);
-        return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class)
+        return (fileReference != null)
+                ? JacksonUtils.getObjectMapperInstance().readValue(getFileContentFromPath(fileReference),
+                        JsonNode.class)
                 : null;
     }
 
index bb1b9d1..28f9e94 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP CLAMP
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -23,8 +23,6 @@
 
 package org.onap.clamp.clds.config;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
@@ -32,6 +30,7 @@ import java.nio.charset.StandardCharsets;
 import org.apache.commons.io.IOUtils;
 import org.onap.clamp.clds.exception.CldsUsersException;
 import org.onap.clamp.clds.service.CldsUser;
+import org.onap.clamp.clds.util.JacksonUtils;
 
 public class CldsUserJsonDecoder {
 
@@ -56,7 +55,7 @@ public class CldsUserJsonDecoder {
         try {
             // the ObjectMapper readValue method closes the stream no need to do
             // it
-            return new ObjectMapper().readValue(cldsUsersString, CldsUser[].class);
+            return JacksonUtils.getObjectMapperInstance().readValue(cldsUsersString, CldsUser[].class);
         } catch (IOException e) {
             throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e);
         }
index a78e895..9274f82 100644 (file)
 package org.onap.clamp.clds.config.sdc;
 
 import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
+import org.onap.clamp.clds.util.JacksonUtils;
+
 /**
  * This class is used to decode the configuration found in
  * application.properties, this is related to the blueprint mapping
@@ -65,6 +66,6 @@ public class BlueprintParserMappingConfiguration {
     public static List<BlueprintParserMappingConfiguration> createFromJson(InputStream json) throws IOException {
         TypeReference<List<BlueprintParserMappingConfiguration>> mapType = new TypeReference<List<BlueprintParserMappingConfiguration>>() {
         };
-        return new ObjectMapper().readValue(json, mapType);
+        return JacksonUtils.getObjectMapperInstance().readValue(json, mapType);
     }
 }
index f5c658c..fdc0074 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.config.sdc;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -35,6 +34,7 @@ import java.util.Map;
 import javax.annotation.PostConstruct;
 
 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
+import org.onap.clamp.clds.util.JacksonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
@@ -65,7 +65,7 @@ public class SdcControllersConfiguration {
     public void loadConfiguration() throws IOException {
         Resource resource = appContext.getResource(sdcControllerFile);
         // Try to load json tree
-        jsonRootNode = new ObjectMapper().readValue(resource.getInputStream(), JsonNode.class);
+        jsonRootNode = JacksonUtils.getObjectMapperInstance().readValue(resource.getInputStream(), JsonNode.class);
     }
 
     public SdcSingleControllerConfiguration getSdcSingleControllerConfiguration(String controllerName) {
index 34876bb..a2c8f72 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.model;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -37,6 +36,7 @@ import javax.ws.rs.BadRequestException;
 import javax.ws.rs.NotFoundException;
 
 import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.util.JacksonUtils;
 
 /**
  * Represent a CLDS Model.
@@ -239,7 +239,7 @@ public class CldsModel {
         boolean result = false;
         try {
             if (propText != null) {
-                JsonNode modelJson = new ObjectMapper().readTree(propText);
+                JsonNode modelJson = JacksonUtils.getObjectMapperInstance().readTree(propText);
                 JsonNode simpleModelJson = modelJson.get("simpleModel");
                 if (simpleModelJson != null && simpleModelJson.asBoolean()) {
                     result = true;
index 2b86b3f..89883c4 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.model.properties;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
@@ -40,6 +39,7 @@ import java.util.Map.Entry;
 
 import org.onap.clamp.clds.exception.ModelBpmnException;
 import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.util.JacksonUtils;
 
 /**
  * Parse Model BPMN properties.
@@ -47,15 +47,15 @@ import org.onap.clamp.clds.service.CldsService;
  * Example json: {"policy" :[{"id":"Policy_0oxeocn", "from":"StartEvent_1"}]}
  */
 public class ModelBpmn {
-    protected static final EELFLogger               logger        = EELFManager.getInstance()
-            .getLogger(CldsService.class);
-    protected static final EELFLogger               auditLogger   = EELFManager.getInstance().getAuditLogger();
+
+    protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
+    protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
     // for each type, an array of entries
     private final Map<String, List<ModelBpmnEntry>> entriesByType = new HashMap<>();
     // for each id, an array of entries
-    private final Map<String, List<ModelBpmnEntry>> entriesById   = new HashMap<>();
+    private final Map<String, List<ModelBpmnEntry>> entriesById = new HashMap<>();
     // List of all elementIds
-    private List<String>                            bpmnElementIds;
+    private List<String> bpmnElementIds;
 
     /**
      * Create ModelBpmn and populate maps from json
@@ -66,8 +66,7 @@ public class ModelBpmn {
     public static ModelBpmn create(String modelBpmnPropText) {
         try {
             ModelBpmn modelBpmn = new ModelBpmn();
-            ObjectMapper objectMapper = new ObjectMapper();
-            ObjectNode root = objectMapper.readValue(modelBpmnPropText, ObjectNode.class);
+            ObjectNode root = JacksonUtils.getObjectMapperInstance().readValue(modelBpmnPropText, ObjectNode.class);
             // iterate over each entry like:
             // "Policy":[{"id":"Policy","from":"StartEvent_1"}]
             Iterator<Entry<String, JsonNode>> entryItr = root.fields();
index f9b1c25..cc6f02d 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.model.properties;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
@@ -41,6 +40,7 @@ import org.onap.clamp.clds.exception.ModelBpmnException;
 import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.CldsModel;
 import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.util.JacksonUtils;
 
 /**
  * Parse model properties.
@@ -96,7 +96,7 @@ public class ModelProperties {
             this.actionCd = actionCd;
             this.testOnly = isATest;
             modelBpmn = ModelBpmn.create(modelBpmnText);
-            modelJson = new ObjectMapper().readTree(modelPropText);
+            modelJson = JacksonUtils.getObjectMapperInstance().readTree(modelPropText);
             instantiateMissingModelElements();
         } catch (IOException e) {
             throw new ModelBpmnException("Exception occurred when trying to decode the BPMN Properties JSON", e);
@@ -141,8 +141,7 @@ public class ModelProperties {
     public static String getVf(CldsModel model) {
         List<String> vfs = null;
         try {
-            ObjectMapper mapper = new ObjectMapper();
-            JsonNode modelJson = mapper.readTree(model.getPropText());
+            JsonNode modelJson = JacksonUtils.getObjectMapperInstance().readTree(model.getPropText());
             Global global = new Global(modelJson);
             vfs = global.getResourceVf();
         } catch (IOException e) {
index c23d2ec..e828f84 100644 (file)
@@ -85,6 +85,7 @@ import org.onap.clamp.clds.model.sdc.SdcResource;
 import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
 import org.onap.clamp.clds.transform.XslTransformer;
+import org.onap.clamp.clds.util.JacksonUtils;
 import org.onap.clamp.clds.util.LoggingUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -426,7 +427,8 @@ public class CldsService extends SecureServiceBase {
                 if (template != null) {
                     model.setTemplateId(template.getId());
                     model.setDocText(template.getPropText());
-                    // This is to provide the Bpmn XML when Template part in UI is
+                    // This is to provide the Bpmn XML when Template part in UI
+                    // is
                     // disabled
                     model.setBpmnText(template.getBpmnText());
                 }
@@ -441,7 +443,8 @@ public class CldsService extends SecureServiceBase {
             String controlName = model.getControlName();
             String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn);
             logger.info("PUT bpmnJson={}", bpmnJson);
-            // Flag indicates whether it is triggered by Validation Test button from
+            // Flag indicates whether it is triggered by Validation Test button
+            // from
             // UI
             boolean isTest = false;
             if (test != null && test.equalsIgnoreCase("true")) {
@@ -466,8 +469,8 @@ public class CldsService extends SecureServiceBase {
             logger.info("modelProp - " + prop);
             logger.info("docText - " + docText);
             try {
-                String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, userId,
-                        isInsertTestEvent);
+                String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest,
+                        userId, isInsertTestEvent);
                 logger.info("Starting Camel flow on request, result is: ", result);
             } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) {
                 errorCase = true;
@@ -478,7 +481,8 @@ public class CldsService extends SecureServiceBase {
             if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
-                // To verify inventory status and modify model status to distribute
+                // To verify inventory status and modify model status to
+                // distribute
                 dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
                 retrievedModel.save(cldsDao, getUserId());
             }
@@ -490,7 +494,6 @@ public class CldsService extends SecureServiceBase {
             errorCase = true;
             logger.error("Exception occured during putModelAndProcessAction", e);
         }
-
         if (errorCase) {
             return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(retrievedModel).build();
         }
@@ -675,7 +678,7 @@ public class CldsService extends SecureServiceBase {
         if (StringUtils.isBlank(responseStr)) {
             return "";
         }
-        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectMapper objectMapper = JacksonUtils.getObjectMapperInstance();
         List<SdcServiceInfo> rawList = objectMapper.readValue(responseStr,
                 objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));
         ObjectNode invariantIdServiceNode = objectMapper.createObjectNode();
@@ -695,26 +698,26 @@ public class CldsService extends SecureServiceBase {
     }
 
     private String createPropertiesObjectByUUID(String cldsResponseStr) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
         SdcServiceDetail cldsSdcServiceDetail = mapper.readValue(cldsResponseStr, SdcServiceDetail.class);
         ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(GLOBAL_PROPERTIES_KEY);
         if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getUuid() != null) {
             /**
              * to create json with vf, alarm and locations
              */
-            ObjectNode serviceObjectNode = createEmptyVfAlarmObject(mapper);
+            ObjectNode serviceObjectNode = createEmptyVfAlarmObject();
             ObjectNode vfObjectNode = mapper.createObjectNode();
             /**
              * to create json with vf and vfresourceId
              */
-            createVfObjectNode(vfObjectNode, mapper, cldsSdcServiceDetail.getResources());
+            createVfObjectNode(vfObjectNode, cldsSdcServiceDetail.getResources());
             serviceObjectNode.putPOJO(cldsSdcServiceDetail.getInvariantUUID(), vfObjectNode);
             ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
             byServiceBasicObjetNode.putPOJO("byService", serviceObjectNode);
             /**
              * to create json with VFC Node
              */
-            ObjectNode emptyvfcobjectNode = createByVFCObjectNode(mapper, cldsSdcServiceDetail.getResources());
+            ObjectNode emptyvfcobjectNode = createByVFCObjectNode(cldsSdcServiceDetail.getResources());
             byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
             globalPropsJson.putPOJO("shared", byServiceBasicObjetNode);
             logger.info("valuie of objNode: {}", globalPropsJson);
@@ -722,7 +725,8 @@ public class CldsService extends SecureServiceBase {
         return globalPropsJson.toString();
     }
 
-    private ObjectNode createEmptyVfAlarmObject(ObjectMapper mapper) {
+    private ObjectNode createEmptyVfAlarmObject() {
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
         ObjectNode emptyObjectNode = mapper.createObjectNode();
         emptyObjectNode.put("", "");
         ObjectNode vfObjectNode = mapper.createObjectNode();
@@ -734,8 +738,8 @@ public class CldsService extends SecureServiceBase {
         return emptyServiceObjectNode;
     }
 
-    private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper,
-            List<SdcResource> rawCldsSdcResourceList) {
+    private void createVfObjectNode(ObjectNode vfObjectNode2, List<SdcResource> rawCldsSdcResourceList) {
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
         ObjectNode vfNode = mapper.createObjectNode();
         vfNode.put("", "");
         // To remove repeated resource instance name from
@@ -782,7 +786,8 @@ public class CldsService extends SecureServiceBase {
         vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
     }
 
-    private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<SdcResource> cldsSdcResourceList) {
+    private ObjectNode createByVFCObjectNode(List<SdcResource> cldsSdcResourceList) {
+        ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
         ObjectNode emptyObjectNode = mapper.createObjectNode();
         ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
         ObjectNode vfCObjectNode = mapper.createObjectNode();
@@ -804,8 +809,7 @@ public class CldsService extends SecureServiceBase {
     @Path("/deploy/{modelName}")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    public Response deployModel(@PathParam("modelName") String modelName,
-            CldsModel model) {
+    public Response deployModel(@PathParam("modelName") String modelName, CldsModel model) {
         Date startTime = new Date();
         LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName());
         Boolean errorCase = false;
@@ -861,7 +865,6 @@ public class CldsService extends SecureServiceBase {
             errorCase = true;
             logger.error("Exception occured during deployModel", e);
         }
-
         if (errorCase) {
             return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
         }
@@ -872,11 +875,9 @@ public class CldsService extends SecureServiceBase {
     @Path("/undeploy/{modelName}")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    public Response unDeployModel(@PathParam("modelName") String modelName,
-            CldsModel model) {
+    public Response unDeployModel(@PathParam("modelName") String modelName, CldsModel model) {
         Date startTime = new Date();
         LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
-
         Boolean errorCase = false;
         try {
             String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
@@ -916,7 +917,6 @@ public class CldsService extends SecureServiceBase {
             errorCase = true;
             logger.error("Exception occured during unDeployModel", e);
         }
-
         if (errorCase) {
             return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
         }
@@ -924,15 +924,13 @@ public class CldsService extends SecureServiceBase {
     }
 
     private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {
-        JsonNode modelJson = new ObjectMapper().readTree(modelPropText);
-        JsonNode globalNode = modelJson.get("global");
+        JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText).get("global");
         String service = AbstractModelElement.getValueByName(globalNode, "service");
         List<String> resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf");
         if (service != null && resourceVf != null && !resourceVf.isEmpty()) {
             List<CldsModelProp> cldsModelPropList = cldsDao.getDeployedModelProperties();
             for (CldsModelProp cldsModelProp : cldsModelPropList) {
-                JsonNode currentJson = new ObjectMapper().readTree(cldsModelProp.getPropText());
-                JsonNode currentNode = currentJson.get("global");
+                JsonNode currentNode = JacksonUtils.getObjectMapperInstance().readTree(cldsModelProp.getPropText()).get("global");
                 String currentService = AbstractModelElement.getValueByName(currentNode, "service");
                 List<String> currentVf = AbstractModelElement.getValuesByName(currentNode, "vf");
                 if (currentVf != null && !currentVf.isEmpty()) {
diff --git a/src/main/java/org/onap/clamp/clds/service/JacksonObjectMapperProvider.java b/src/main/java/org/onap/clamp/clds/service/JacksonObjectMapperProvider.java
new file mode 100644 (file)
index 0000000..87f8273
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ *                             reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import javax.ws.rs.ext.ContextResolver;
+
+import org.onap.clamp.clds.util.JacksonUtils;
+
+/**
+ * This class is to restrcit the class type that can be de-serialized.
+ */
+public class JacksonObjectMapperProvider implements ContextResolver<ObjectMapper> {
+
+    private final ObjectMapper defaultObjectMapper;
+
+    public JacksonObjectMapperProvider() {
+        defaultObjectMapper = createDefaultMapper();
+    }
+
+    @Override
+    public ObjectMapper getContext(Class<?> type) {
+        return defaultObjectMapper;
+    }
+
+    private static ObjectMapper createDefaultMapper() {
+        return JacksonUtils.getObjectMapperInstance();
+    }
+}
index 702e064..d3c212c 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
+
 import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.core.Application;
 
@@ -45,7 +46,6 @@ import org.springframework.stereotype.Component;
 public class JaxrsApplication extends Application {
 
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(JaxrsApplication.class);
-
     private Function<BeanDefinition, Optional<Class<?>>> beanDefinitionToClass = b -> {
         try {
             return Optional.of(Class.forName(b.getBeanClassName()));
@@ -58,6 +58,7 @@ public class JaxrsApplication extends Application {
     @Override
     public Set<Class<?>> getClasses() {
         Set<Class<?>> resources = new HashSet<>();
+        resources.add(JacksonObjectMapperProvider.class);
         resources.add(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.class);
         resources.addAll(scan());
         return resources;
@@ -66,11 +67,7 @@ public class JaxrsApplication extends Application {
     private List<Class<?>> scan() {
         ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
         scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));
-        return scanner.findCandidateComponents("org.onap.clamp.clds").stream()
-                .map(beanDefinitionToClass)
-                .filter(Optional::isPresent)
-                .map(Optional::get)
-                .collect(Collectors.toList());
+        return scanner.findCandidateComponents("org.onap.clamp.clds").stream().map(beanDefinitionToClass)
+                .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
     }
-
 }
\ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/util/JacksonUtils.java b/src/main/java/org/onap/clamp/clds/util/JacksonUtils.java
new file mode 100644 (file)
index 0000000..9d743f2
--- /dev/null
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ *                             reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * This class is used to access the jackson with restricted type access.
+ */
+public class JacksonUtils {
+
+    private static ObjectMapper objectMapper;
+
+    private JacksonUtils() {
+    }
+
+    /**
+     * Call this method to retrieve a secure ObjectMapper.
+     * 
+     * @return an ObjectMapper instance (same for clamp)
+     */
+    public static synchronized ObjectMapper getObjectMapperInstance() {
+        if (objectMapper == null) {
+            objectMapper = new ObjectMapper();
+            // This is to disable the security hole that could be opened for
+            // json deserialization, if needed do this
+            // objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL);
+            objectMapper.disableDefaultTyping();
+        }
+        return objectMapper;
+    }
+}
diff --git a/src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java
new file mode 100644 (file)
index 0000000..d8774af
--- /dev/null
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ *                             reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class JacksonUtilsTest {
+
+    public static class TestClass extends TestObject {
+
+        String test2;
+        TestObject2 object2;
+
+        public TestClass(String value1, String value2) {
+            super(value1);
+            test2 = value2;
+        }
+
+        public TestClass() {
+        }
+
+        public String getTest2() {
+            return test2;
+        }
+
+        public void setTest2(String test2) {
+            this.test2 = test2;
+        }
+
+        public TestObject2 getObject2() {
+            return object2;
+        }
+
+        public void setObject2(TestObject2 object2) {
+            this.object2 = object2;
+        }
+    }
+
+    @Test
+    public void testGetObjectMapperInstance() {
+        assertNotNull(JacksonUtils.getObjectMapperInstance());
+    }
+
+    /**
+     * This method test that the security hole in Jackson is not enabled in the
+     * default ObjectMapper.
+     * 
+     * @throws JsonParseException
+     *             In case of issues
+     * @throws JsonMappingException
+     *             In case of issues
+     * @throws IOException
+     *             In case of issues
+     */
+    @Test
+    public void testCreateBeanDeserializer() throws JsonParseException, JsonMappingException, IOException {
+        TestClass test = new TestClass("value1", "value2");
+        test.setObject2(new TestObject2("test3"));
+        Object testObject = JacksonUtils.getObjectMapperInstance().readValue(
+                "[\"org.onap.clamp.clds.util.JacksonUtilsTest$TestClass\",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\",{\"test3\":\"test3\"}]}]",
+                Object.class);
+        assertNotNull(testObject);
+        assertFalse(testObject instanceof TestObject);
+        assertFalse(testObject instanceof TestClass);
+    }
+}
diff --git a/src/test/java/org/onap/clamp/clds/util/TestObject.java b/src/test/java/org/onap/clamp/clds/util/TestObject.java
new file mode 100644 (file)
index 0000000..cf8d302
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ *                             reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+public class TestObject {
+
+    private String test;
+
+    public String getTest() {
+        return test;
+    }
+
+    public void setTest(String test) {
+        this.test = test;
+    }
+
+    // @JsonProperty("test"), @JsonCreator
+    public TestObject(String theString) {
+        this.setTest(theString);
+    }
+
+    public TestObject() {
+    }
+}
diff --git a/src/test/java/org/onap/clamp/clds/util/TestObject2.java b/src/test/java/org/onap/clamp/clds/util/TestObject2.java
new file mode 100644 (file)
index 0000000..d8d2d01
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ *                             reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+public class TestObject2 {
+
+    private String test3;
+
+    public String getTest3() {
+        return test3;
+    }
+
+    public void setTest3(String test) {
+        this.test3 = test;
+    }
+
+    public TestObject2(String theString) {
+        this.setTest3(theString);
+    }
+
+    public TestObject2() {
+    }
+}