diff options
author | Liard Samuel <samuel.liard@orange.com> | 2021-10-08 09:21:18 +0200 |
---|---|---|
committer | highstreetherbert <herbert.eiselt@highstreet-technologies.com> | 2021-11-19 11:25:38 +0100 |
commit | 6945b75aac0e6bc2bad6f824769b32842f06bc46 (patch) | |
tree | fb99e802250d9efd8ac5c75df85a76431bff3ba4 /sdnr | |
parent | 71031b0b238ee51affd8135fdd648d9a70a6970b (diff) |
Fix sonar Security Hotspots
Issue-ID: CCSDK-3491
Signed-off-by: sliard <samuel.liard@gmail.com>
Change-Id: I33787ccca2a8acd8085db6b2a915e8f2ac2511ec
Signed-off-by: Dan Timoney <dtimoney@att.com>
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr')
2 files changed, 9 insertions, 14 deletions
diff --git a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java b/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java index 1756615cb..0d9cc8f3f 100644 --- a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java +++ b/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java @@ -146,20 +146,16 @@ public class AddCMHandleProvider implements CMHandleAPIService, NetconfNodeState // GET configuration from properties file config = new HashMap<String, String>(); - try { - FileInputStream fileInput = new FileInputStream(propDir + PROPERTIES_FILE_NAME); + try (FileInputStream fileInput = new FileInputStream(propDir + PROPERTIES_FILE_NAME)) { Properties properties = new Properties(); properties.load(fileInput); - fileInput.close(); for (String param : new String[] {"url", "user", "password", "authentication, dmi-service-name"}) { config.put(param, properties.getProperty(param)); } - } catch (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { - e.printStackTrace(); + LOG.error("Error while reading properties file: ", e); } LOG.info("addCMHandle Session Initiated"); @@ -167,7 +163,7 @@ public class AddCMHandleProvider implements CMHandleAPIService, NetconfNodeState @Override public void onCreated(NodeId nNodeId, NetconfNode netconfNode) { - LOG.info("NetConf device connected ", nNodeId.getValue()); + LOG.info("NetConf device connected {}", nNodeId.getValue()); JSONObject obj = new JSONObject(); obj.put("cm-handle-id", nNodeId.getValue()); obj.put("dmi-service-name", config.get("dmi-service-name")); @@ -178,7 +174,7 @@ public class AddCMHandleProvider implements CMHandleAPIService, NetconfNodeState String authenticationMethod = config.get("authentication"); ClientResponse response = null; try { - if (authenticationMethod.equals("basic")) { + if ("basic".equals(authenticationMethod)) { LOG.debug("Sending message to dmaap-message-router: {}", obj.toString()); dmaapClient.addFilter(new HTTPBasicAuthFilter(config.get("user"), config.get("password"))); @@ -188,11 +184,11 @@ public class AddCMHandleProvider implements CMHandleAPIService, NetconfNodeState response = dmaapClient.resource(config.get("url")).type(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, obj); } + LOG.info("Received response from dmaap-message-router: \n {}", response.toString()); } catch (Exception e) { - LOG.error("Error while posting message to CM_HANDLE topic: {}", e); + LOG.error("Error while posting message to CM_HANDLE topic: ", e); } - LOG.info("Received response from dmaap-message-router: \n {}", response.toString()); } @Override diff --git a/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/energysavings/EnergysavingsProvider.java b/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/energysavings/EnergysavingsProvider.java index b580b53cf..afc22c9fb 100644 --- a/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/energysavings/EnergysavingsProvider.java +++ b/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/energysavings/EnergysavingsProvider.java @@ -112,8 +112,7 @@ public class EnergysavingsProvider implements EnergysavingsService { HashMap<String, String> dmaapPolicyHttpParams = new HashMap<String, String>(); HashMap<String, String> energySavingsServerHttpParams = new HashMap<String, String>(); - try { - FileInputStream fileInput = new FileInputStream(propDir + PROPERTIES_FILE_NAME); + try (FileInputStream fileInput = new FileInputStream(propDir + PROPERTIES_FILE_NAME)) { Properties properties = new Properties(); properties.load(fileInput); fileInput.close(); @@ -123,9 +122,9 @@ public class EnergysavingsProvider implements EnergysavingsService { energySavingsServerHttpParams.put(param, properties.getProperty("energySavingsServer." + param)); } } catch (FileNotFoundException e) { - e.printStackTrace(); + LOG.error("Unexpected value for energy savings server authentication: "); } catch (IOException e) { - e.printStackTrace(); + LOG.error("Unexpected value for energy savings server authentication: "); } // Create a web resource for the Energy Savings server |