Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / restAuth / CheckPDP.java
index ce35a70..c1a1907 100644 (file)
@@ -20,9 +20,6 @@
 
 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;
@@ -39,15 +36,13 @@ import java.util.HashMap;
 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;
@@ -62,8 +57,6 @@ public class CheckPDP {
                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;
                }
@@ -77,24 +70,18 @@ public class CheckPDP {
        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");
                        }
@@ -109,6 +96,7 @@ public class CheckPDP {
                }
        }
 
+       @SuppressWarnings({ "rawtypes", "unchecked" })
        private static void readProps() throws Exception {
                InputStream in;
                pdpProp = new Properties();
@@ -117,13 +105,11 @@ public class CheckPDP {
                        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);
@@ -135,7 +121,7 @@ public class CheckPDP {
                                        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);
@@ -155,7 +141,7 @@ public class CheckPDP {
 
        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);
@@ -164,14 +150,10 @@ public class CheckPDP {
                                // 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.");
                }
@@ -181,8 +163,6 @@ public class CheckPDP {
                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;
@@ -190,8 +170,6 @@ public class CheckPDP {
                        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;