package org.openecomp.policy.pap.xacml.restAuth;
-import org.openecomp.policy.common.logging.eelf.MessageCodes;
-import org.openecomp.policy.common.logging.eelf.PolicyLogger;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.openecomp.policy.common.logging.eelf.MessageCodes;
+import org.openecomp.policy.common.logging.eelf.PolicyLogger;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet;
-
import org.openecomp.policy.xacml.api.XACMLErrorConstants;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-import org.openecomp.policy.common.logging.flexlogger.Logger;
-
public class CheckPDP {
private static Path pdpPath = null;
try {
readFile();
} catch (Exception e) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exception reading file");
return false;
}
private static void readFile() throws Exception {
String pdpFile = XACMLPapServlet.getPDPFile();
if (pdpFile == null) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PDP File name not Valid : " + pdpFile);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "PDP File name is undefined");
throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile);
}
if (pdpPath == null) {
pdpPath = Paths.get(pdpFile);
if (Files.notExists(pdpPath)) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + pdpPath.toString());
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path");
throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ pdpPath.toString());
}
if (pdpPath.toString().endsWith(".properties")) {
readProps();
} else {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + pdpFile);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "Not a .properties file");
throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file");
}
}
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private static void readProps() throws Exception {
InputStream in;
pdpProp = new Properties();
oldModified = pdpPath.toFile().lastModified();
pdpProp.load(in);
} catch (IOException e) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Cannot load the Properties file");
throw new Exception("Cannot Load the Properties file", e);
}
// Read the Properties and Load the PDPs and encoding.
- pdpMap = new HashMap<String, String>();
+ pdpMap = new HashMap<>();
// Check the Keys for PDP_URLs
Collection<Object> unsorted = pdpProp.keySet();
List<String> sorted = new ArrayList(unsorted);
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*")));
+ 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);
private static void readPDPParam(String pdpVal) throws Exception{
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);
// 0 - PDPURL
pdpMap.put(pdpValues.get(0), encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8)));
}else{
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpValues);
PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request");
throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues);
}
}else{
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal);
PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal);
throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request.");
}
try {
readFile();
} catch (Exception e) {
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exeption reading Properties file");
}
String encoding = null;
try{
encoding = pdpMap.get(pdpID);
} catch(Exception e){
- //TODO:EELF Cleanup - Remove logger
- //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exception encoding");
}
return encoding;