- 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 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 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 PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file");
- }
- }
- // Check if File is updated recently
- else {
- newModified = pdpPath.toFile().lastModified();
- if (newModified != oldModified) {
- // File has been updated.
- readProps();
- }
- }
- }
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static void readProps() throws PAPException {
+ InputStream in;
+ pdpProp = new Properties();
+ try {
+ in = new FileInputStream(pdpPath.toFile());
+ oldModified = pdpPath.toFile().lastModified();
+ pdpProp.load(in);
+ } catch (IOException e) {
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Cannot load the Properties file");
+ throw new PAPException("Cannot Load the Properties file", e);
+ }
+ // 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) {
+ if (propKey.startsWith("PDP_URL")) {
+ String check_val = pdpProp.getProperty(propKey);
+ if (check_val == null) {
+ throw new PAPException("Properties file doesn't have the PDP_URL parameter");
+ }
+ if (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++;
+ }
+ } else {
+ readPDPParam(check_val);
+ }
+ }
+ }
+ if (pdpMap == null || pdpMap.isEmpty()) {
+ logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Proceed without PDP_URLs");
+ throw new PAPException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Proceed without PDP_URLs");
+ }
+ }