aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java
diff options
context:
space:
mode:
authorRavindra Bakkamanthala <rb7147@att.com>2017-05-31 15:54:24 -0400
committerRavindra Bakkamanthala <rb7147@att.com>2017-05-31 15:57:02 -0400
commitd9007d680d19734d5dc106479784c420236cca4b (patch)
treeb3356847c3d6e1543098b447c1df7d49e7118652 /POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java
parent6a5e800771311208c66ad79ce1bdf76affd144b2 (diff)
[Policy-17] Removed the sql scripts from sdk app
Change-Id: I5b017aad569014c7f12eab35e1dbd1c215f90ebe Signed-off-by: Ravindra Bakkamanthala <rb7147@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java100
1 files changed, 47 insertions, 53 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java
index 4f026ff10..ca5aff193 100644
--- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java
+++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/admin/CheckPDP.java
@@ -25,7 +25,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -37,22 +36,22 @@ import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.rest.XACMLRestProperties;
-
import org.openecomp.policy.xacml.api.XACMLErrorConstants;
-import com.att.research.xacml.util.XACMLProperties;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-import org.openecomp.policy.common.logging.flexlogger.Logger;
+import com.att.research.xacml.util.XACMLProperties;
public class CheckPDP {
private static Path pdpPath = null;
- private static Properties pdpProp = null;
private static Long oldModified = null;
- private static Long newModified = null;
private static HashMap<String, String> pdpMap = null;
private static final Logger LOGGER = FlexLogger.getLogger(CheckPDP.class);
-
+
+ private CheckPDP(){
+ //default constructor
+ }
public static boolean validateID(String id) {
// ReadFile
try {
@@ -62,41 +61,37 @@ public class CheckPDP {
return false;
}
// Check ID
- if (pdpMap.containsKey(id)) {
- return true;
- }
- return false;
+ return (pdpMap.containsKey(id))? true: false;
}
- private static void readFile() throws Exception {
+ private static void readFile(){
String pdpFile = null;
+ Long newModified = null;
try{
pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE);
}catch (Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot read the PDP ID File");
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot read the PDP ID File" + e);
return;
}
if (pdpFile == null) {
LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PDP File name not Valid : " + pdpFile);
- throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile);
}
if (pdpPath == null) {
pdpPath = Paths.get(pdpFile);
- if (Files.notExists(pdpPath)) {
+ if (!pdpPath.toFile().exists()) {
LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + pdpPath.toString());
- throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ pdpPath.toString());
+
}
if (pdpPath.toString().endsWith(".properties")) {
readProps();
} else {
LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + pdpFile);
- throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file");
}
}
// Check if File is updated recently
else {
newModified = pdpPath.toFile().lastModified();
- if (newModified != oldModified) {
+ if (!newModified.equals(oldModified)) {
// File has been updated.
readProps();
}
@@ -104,51 +99,52 @@ public class CheckPDP {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- private static void readProps() throws Exception {
- InputStream in;
+ private static void readProps() {
+ Properties pdpProp = null;
pdpProp = new Properties();
try {
- in = new FileInputStream(pdpPath.toFile());
+ InputStream in = new FileInputStream(pdpPath.toFile());
oldModified = pdpPath.toFile().lastModified();
pdpProp.load(in);
+ // Read the Properties and Load the PDPs and encoding.
+ pdpMap = new HashMap<>();
+ // Check the Keys for PDP_URLs
+ Collection<Object> unsorted = pdpProp.keySet();
+ List<String> sorted = new ArrayList(unsorted);
+ Collections.sort(sorted);
+ for (String propKey : sorted) {
+ loadPDPProperties(propKey, pdpProp);
+ }
+ if (pdpMap == null || pdpMap.isEmpty()) {
+ LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Proceed without PDP_URLs");
+ }
+ in.close();
} catch (IOException e) {
LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
- throw new Exception("Cannot Load the Properties file", e);
}
- // Read the Properties and Load the PDPs and encoding.
- pdpMap = new HashMap<String, String>();
- // Check the Keys for PDP_URLs
- Collection<Object> unsorted = pdpProp.keySet();
- List<String> sorted = new ArrayList(unsorted);
- Collections.sort(sorted);
- for (String propKey : sorted) {
- if (propKey.startsWith("PDP_URL")) {
- String check_val = pdpProp.getProperty(propKey);
- if (check_val == null) {
- throw new Exception("Properties file doesn't have the PDP_URL parameter");
- }
- if (check_val.contains(";")) {
- List<String> pdp_default = new ArrayList<String>(Arrays.asList(check_val.split("\\s*;\\s*")));
- int pdpCount = 0;
- while (pdpCount < pdp_default.size()) {
- String pdpVal = pdp_default.get(pdpCount);
- readPDPParam(pdpVal);
- pdpCount++;
- }
- } else {
- readPDPParam(check_val);
+ }
+
+ private static void loadPDPProperties(String propKey, Properties pdpProp){
+ if (propKey.startsWith("PDP_URL")) {
+ String check_val = pdpProp.getProperty(propKey);
+ if (check_val == null) {
+ LOGGER.error("Properties file doesn't have the PDP_URL parameter");
+ }
+ if (check_val != null && check_val.contains(";")) {
+ List<String> pdp_default = new ArrayList<>(Arrays.asList(check_val.split("\\s*;\\s*")));
+ int pdpCount = 0;
+ while (pdpCount < pdp_default.size()) {
+ String pdpVal = pdp_default.get(pdpCount);
+ readPDPParam(pdpVal);
+ pdpCount++;
}
}
}
- if (pdpMap == null || pdpMap.isEmpty()) {
- LOGGER.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Proceed without PDP_URLs");
- throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Proceed without PDP_URLs");
- }
}
- private static void readPDPParam(String pdpVal) throws Exception{
+ private static void readPDPParam(String pdpVal){
if(pdpVal.contains(",")){
- List<String> pdpValues = new ArrayList<String>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
+ List<String> pdpValues = new ArrayList<>(Arrays.asList(pdpVal.split("\\s*,\\s*")));
if(pdpValues.size()==3){
// 1:2 will be UserID:Password
String userID = pdpValues.get(1);
@@ -158,11 +154,9 @@ public class CheckPDP {
pdpMap.put(pdpValues.get(0), encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8)));
}else{
LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpValues);
- throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues);
}
}else{
LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal);
- throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request.");
}
}