X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2FrestAuth%2FCheckPDP.java;h=335b94f51334a336e25ebe1d04d7e76253418d89;hb=refs%2Fchanges%2F09%2F11009%2F1;hp=02ec467ed6f3cf407b7896d915fda96a247fd2ee;hpb=461b2b7eeca1586423349bc0c4c65f80f027292d;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/restAuth/CheckPDP.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/restAuth/CheckPDP.java index 02ec467ed..335b94f51 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/restAuth/CheckPDP.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/restAuth/CheckPDP.java @@ -43,6 +43,8 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.pap.xacml.rest.XACMLPapServlet; import org.onap.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PAPException; + public class CheckPDP { private static Path pdpPath = null; @@ -67,23 +69,23 @@ public class CheckPDP { return false; } - private static void readFile() throws Exception { + private static void readFile() throws PAPException { String pdpFile = XACMLPapServlet.getPDPFile(); if (pdpFile == null) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "PDP File name is undefined"); - throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile); + throw new PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile); } if (pdpPath == null) { pdpPath = Paths.get(pdpFile); if (Files.notExists(pdpPath)) { 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()); + throw new PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ pdpPath.toString()); } if (pdpPath.toString().endsWith(".properties")) { readProps(); } else { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "Not a .properties file"); - throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file"); + throw new PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file"); } } // Check if File is updated recently @@ -97,7 +99,7 @@ public class CheckPDP { } @SuppressWarnings({ "rawtypes", "unchecked" }) - private static void readProps() throws Exception { + private static void readProps() throws PAPException { InputStream in; pdpProp = new Properties(); try { @@ -106,7 +108,7 @@ public class CheckPDP { pdpProp.load(in); } catch (IOException e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Cannot load the Properties file"); - throw new Exception("Cannot Load the Properties file", e); + throw new PAPException("Cannot Load the Properties file", e); } // Read the Properties and Load the PDPs and encoding. pdpMap = new HashMap<>(); @@ -118,7 +120,7 @@ public class CheckPDP { 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"); + throw new PAPException("Properties file doesn't have the PDP_URL parameter"); } if (check_val.contains(";")) { List pdp_default = new ArrayList<>(Arrays.asList(check_val.split("\\s*;\\s*"))); @@ -135,11 +137,11 @@ public class CheckPDP { } 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"); + throw new PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Proceed without PDP_URLs"); } } - private static void readPDPParam(String pdpVal) throws Exception{ + private static void readPDPParam(String pdpVal) throws PAPException{ if(pdpVal.contains(",")){ List pdpValues = new ArrayList<>(Arrays.asList(pdpVal.split("\\s*,\\s*"))); if(pdpValues.size()==3){ @@ -151,11 +153,11 @@ public class CheckPDP { pdpMap.put(pdpValues.get(0), encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8))); }else{ PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request"); - throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues); + throw new PAPException(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues); } }else{ PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal); - throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request."); + throw new PAPException(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request."); } }