X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Felk%2Fclient%2FElasticSearchPolicyUpdate.java;h=5de09215cf9b1b65943dfa8e52659b2b23a924d9;hb=f0c563df34a999a1702d51cb6cb44fe10155b16b;hp=d064d052bbe5d76ed855694a51e80da5a63ecfe0;hpb=331e68e8699a4264022a2a073ebe8ed8a35322db;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java index d064d052b..5de09215c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java @@ -19,9 +19,10 @@ */ package org.onap.policy.pap.xacml.rest.elk.client; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.InputStream; -import java.nio.file.Files; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Connection; @@ -36,6 +37,8 @@ import java.util.Properties; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.utils.CryptoUtils; +import org.onap.policy.xacml.util.XACMLPolicyScanner; import com.google.gson.Gson; @@ -77,13 +80,13 @@ public class ElasticSearchPolicyUpdate { String elkURL = null; String databseUrl = null; String userName = null; - String password = null; + String txt = null; String databaseDriver = null; String propertyFile = System.getProperty("PROPERTY_FILE"); Properties config = new Properties(); Path file = Paths.get(propertyFile); - if(Files.notExists(file)){ + if(!file.toFile().exists()){ LOGGER.error("Config File doesn't Exist in the specified Path " + file.toString()); }else{ if(file.toString().endsWith(".properties")){ @@ -93,9 +96,9 @@ public class ElasticSearchPolicyUpdate { elkURL = config.getProperty("policy.elk.url"); databseUrl = config.getProperty("policy.database.url"); userName = config.getProperty("policy.database.username"); - password = config.getProperty("policy.database.password"); + txt = CryptoUtils.decryptTxtNoExStr(config.getProperty("policy.database.password")); databaseDriver = config.getProperty("policy.database.driver"); - if(elkURL == null || databseUrl == null || userName == null || password == null || databaseDriver == null){ + if(elkURL == null || databseUrl == null || userName == null || txt == null || databaseDriver == null){ LOGGER.error("please check the elk configuration"); } } catch (Exception e) { @@ -113,11 +116,11 @@ public class ElasticSearchPolicyUpdate { Connection conn = null; Statement stmt = null; - List listIndex = new ArrayList(); + List listIndex = new ArrayList<>(); try { Class.forName(databaseDriver); - conn = DriverManager.getConnection(databseUrl, userName, password); + conn = DriverManager.getConnection(databseUrl, userName, txt); stmt = conn.createStatement(); String policyEntityQuery = "Select * from PolicyEntity"; @@ -252,7 +255,9 @@ public class ElasticSearchPolicyUpdate { } } - private static String constructPolicyData(Object policyData, StringBuilder policyDataString){ + public static String constructPolicyData(Object policyContent, StringBuilder policyDataString){ + InputStream stream = new ByteArrayInputStream(policyContent.toString().getBytes(StandardCharsets.UTF_8)); + Object policyData = XACMLPolicyScanner.readPolicy(stream); if(policyData instanceof PolicyType){ PolicyType policy = (PolicyType) policyData; TargetType target = policy.getTarget();