summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-04-17 12:25:54 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-04-17 12:25:54 +0200
commitb196f93758edabf10174da160e8b74e7eec8ef72 (patch)
treef1b7dba8b49d4ea15f07eeb577545ace76a4e7fb /prh-app-server/src/main
parent58a67d37441b8af808b792418e07448e30556bbd (diff)
Fixed the rest of the Security Issues
*Introduce Gson Against Jackson library *Delete posix library with strong copyleft licenses Change-Id: I37ec6a359912481d1546293a8a8aeeedd6c907e2 Issue-ID: DCAEGEN2-426 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java3
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java78
2 files changed, 45 insertions, 36 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
index 2671669a..fd864483 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/MainApp.java
@@ -20,7 +20,9 @@
package org.onap.dcaegen2.services.prh;
import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -35,6 +37,7 @@ import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
@Configuration
@ComponentScan
@EnableScheduling
+@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class})
public class MainApp {
public static void main(String[] args) {
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
index 37b17f61..6f077a36 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
@@ -19,28 +19,29 @@
*/
package org.onap.dcaegen2.services.prh.configuration;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.NullNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import static org.apache.tomcat.util.file.ConfigFileLoader.getInputStream;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapterFactory;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import java.util.Optional;
+import java.util.ServiceLoader;
import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration;
import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.config.ImmutableDmaapPublisherConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -76,49 +77,54 @@ public class PrhAppConfig implements AppConfig {
public void initFileStreamReader() {
- ObjectMapper jsonObjectMapper = new ObjectMapper().registerModule(new Jdk8Module());
- JsonNode jsonNode;
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
+ JsonParser parser = new JsonParser();
+ JsonObject jsonObject;
try (InputStream inputStream = getInputStream(filepath)) {
- ObjectNode root = (ObjectNode) jsonObjectMapper.readTree(inputStream);
- jsonNode = Optional.ofNullable(root.get(CONFIG).get(AAI).get(AAI_CONFIG)).orElse(NullNode.getInstance());
- aaiHttpClientConfiguration = jsonObjectMapper
- .treeToValue(jsonNode, ImmutableAAIHttpClientConfiguration.class);
- jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_CONSUMER))
- .orElse(NullNode.getInstance());
- dmaapConsumerConfiguration = jsonObjectMapper
- .treeToValue(jsonNode, ImmutableDmaapConsumerConfiguration.class);
- jsonNode = Optional.ofNullable(root.get(CONFIG).get(DMAAP).get(DMAAP_PRODUCER))
- .orElse(NullNode.getInstance());
- dmaapPublisherConfiguration = jsonObjectMapper
- .treeToValue(jsonNode, ImmutableDmaapPublisherConfiguration.class);
+ JsonElement rootElement = parser.parse(new InputStreamReader(inputStream));
+ if (rootElement.isJsonObject()) {
+ jsonObject = rootElement.getAsJsonObject();
+ aaiHttpClientConfiguration = deserializeType(gsonBuilder,
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
+ AAIHttpClientConfiguration.class);
+
+ dmaapConsumerConfiguration = deserializeType(gsonBuilder,
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+ DmaapConsumerConfiguration.class);
+
+ dmaapPublisherConfiguration = deserializeType(gsonBuilder,
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+ DmaapPublisherConfiguration.class);
+ }
+
} catch (FileNotFoundException e) {
logger
.error(
"Configuration PrhAppConfig initFileStreamReader()::FileNotFoundException :: Execution Time - {}:{}",
dateTimeFormatter.format(
LocalDateTime.now()), e);
- } catch (JsonParseException e) {
- logger
- .error(
- "Configuration PrhAppConfig initFileStreamReader()::JsonParseException :: Execution Time - {}:{}",
- dateTimeFormatter.format(
- LocalDateTime.now()), e);
- } catch (JsonMappingException e) {
+ } catch (IOException e) {
logger
.error(
- "Configuration PrhAppConfig initFileStreamReader()::JsonMappingException :: Execution Time - {}:{}",
+ "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}",
dateTimeFormatter.format(
LocalDateTime.now()), e);
- } catch (IOException e) {
+ } catch (JsonSyntaxException e) {
logger
.error(
- "Configuration PrhAppConfig initFileStreamReader()::IOException :: Execution Time - {}:{}",
+ "Configuration PrhAppConfig initFileStreamReader()::JsonSyntaxException :: Execution Time - {}:{}",
dateTimeFormatter.format(
LocalDateTime.now()), e);
}
}
- InputStream getInputStream(String filepath) throws FileNotFoundException {
+ private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
+ @NotNull Class<T> type) {
+ return gsonBuilder.create().fromJson(jsonObject, type);
+ }
+
+ InputStream getInputStream(@NotNull String filepath) throws FileNotFoundException {
return new BufferedInputStream(new FileInputStream(filepath));
}