*
*/
public class XACMLPdpLoader {
- private static final Logger logger = FlexLogger.getLogger(XACMLPdpLoader.class);
+ private static final Logger LOGGER = FlexLogger.getLogger(XACMLPdpLoader.class);
private static NotificationController notificationController = new NotificationController();
private static final Long notifyDelay = (long) XACMLPdpServlet.getNotificationDelay();
public static synchronized PDPEngine loadEngine(StdPDPStatus status,
Properties policyProperties, Properties pipProperties) {
- logger.info("loadEngine: " + policyProperties + " " + pipProperties);
+ LOGGER.info("loadEngine: " + policyProperties + " " + pipProperties);
//
// First load our policies
//
// Validate the policies
//
XACMLPdpLoader.validatePolicies(policyProperties, status);
- if (logger.isDebugEnabled()) {
- logger.debug("Status: " + status);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Status: " + status);
}
} catch (ConcurrentModificationException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e.getMessage());
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "");
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e.getMessage());
} catch (Exception e) {
String error = "Failed to load Policy Cache properties file: "
+ e.getMessage();
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error, e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, error);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error, e);
status.addLoadError(error);
status.setStatus(PDPStatus.Status.LOAD_ERRORS);
}
// Validate our PIP configurations
//
XACMLPdpLoader.validatePipConfiguration(pipProperties, status);
- if (logger.isDebugEnabled()) {
- logger.debug("Status: " + status);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Status: " + status);
}
} catch (Exception e) {
String error = "Failed to load/validate Pip Config properties file: "
+ e.getMessage();
- logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + error, e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, error);
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + error, e);
status.addLoadError(XACMLErrorConstants.ERROR_PROCESS_FLOW + error);
status.setStatus(PDPStatus.Status.LOAD_ERRORS);
}
// Were they validated?
//
if (status.getStatus() == Status.LOAD_ERRORS) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"there were load errors");
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"there were load errors");
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"there were load errors");
return null;
}
//
// Dump ALL our properties that we are trying to load
//
try {
- logger.info(XACMLProperties.getProperties().toString());
+ LOGGER.info(XACMLProperties.getProperties().toString());
} catch (IOException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to get XACML Properties", e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to get XACML Properties");
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to get XACML Properties", e);
}
//
// Now load the PDP engine
try {
factory = PDPEngineFactory.newInstance();
engine = factory.newEngine();
- logger.info("Loaded new PDP engine.");
+ LOGGER.info("Loaded new PDP engine.");
status.setStatus(Status.UP_TO_DATE);
} catch (FactoryException e) {
String error = "Failed to create new PDP Engine";
- logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +error, e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, error);
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +error, e);
status.addLoadError(error);
}
// Notification will be Sent Here.
Thread.sleep(notifyDelay);
NotificationController.sendNotification();
}catch(Exception e){
- logger.error(XACMLErrorConstants.ERROR_UNKNOWN + e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "");
+ LOGGER.error(XACMLErrorConstants.ERROR_UNKNOWN + e);
}
}
};
for (String id : refPolicies) {
loadPolicy(properties, status, id, false);
}
- logger.info("Loaded " + status.getLoadedPolicies().size()
+ LOGGER.info("Loaded " + status.getLoadedPolicies().size()
+ " policies, failed to load "
+ status.getFailedPolicies().size() + " policies, "
+ status.getLoadedRootPolicies().size() + " root policies");
- // TODO Notification Controller is here..
notificationController.check(status, policyContainer);
if (status.getLoadedRootPolicies().size() == 0) {
- logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW +"NO ROOT POLICIES LOADED!!! Cannot serve PEP Requests.");
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW +"NO ROOT POLICIES LOADED!!! Cannot serve PEP Requests.");
status.addLoadWarning("NO ROOT POLICIES LOADED!!! Cannot serve PEP Requests.");
}
policyContainer.clear();
} catch (Exception e){
// This Happens if a any issue with the error policyFile. Lets remove it.
try {
- logger.error("Corrupted policy file, deleting: " + location);
+ LOGGER.error("Corrupted policy file, deleting: " + location);
Files.delete(Paths.get(location));
properties.remove(id + ".file");
rougeFile = true;
} catch (IOException e1) {
- logger.error(e1);
+ LOGGER.error(e1);
}
}
}
String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8));
locationURI = URI.create(papUrls.getUrl(PapUrlResolver.extractIdFromUrl(location)));
URL url = locationURI.toURL();
- //FIXME: modify me
URLConnection urlConnection = null;
try{
urlConnection = url.openConnection();
policy = DOMPolicyDef.load(fis);
}catch(Exception e){
try {
- logger.error("Corrupted policy file, deleting: " + location);
+ LOGGER.error("Corrupted policy file, deleting: " + location);
Files.delete(outFile);
error = true;
errorCount++;
break;
} catch (IOException e1) {
- logger.error(e1);
+ LOGGER.error(e1);
}
}
//
if (policy != null) {
status.addLoadedPolicy(new StdPDPPolicy(id, isRoot,
locationURI, properties));
- logger.info("Loaded policy: " + policy.getIdentifier()
+ LOGGER.info("Loaded policy: " + policy.getIdentifier()
+ " version: " + policy.getVersion().stringValue());
// Sending the policy objects to the Notification Controller.
policyContainer.put(id, policy);
} else {
String error = "Failed to load policy " + location;
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, error);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error);
status.setStatus(PDPStatus.Status.LOAD_ERRORS);
status.addLoadError(error);
status.addFailedPolicy(new StdPDPPolicy(id, isRoot));
}
} catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"Failed to load policy '" + id + "' from location '"
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"Failed to load policy '" + id + "' from location '"
+ location + "'", e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to load policy '" + id + "' from location '"
- // + location + "'");
status.setStatus(PDPStatus.Status.LOAD_ERRORS);
status.addFailedPolicy(new StdPDPPolicy(id, isRoot));
//
// Let's remove it
//
try {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Corrupted policy file, deleting: " + location);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Corrupted policy file, deleting: " + location);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Corrupted policy file, deleting: " + location);
Files.delete(Paths.get(location));
} catch (IOException e1) {
- logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e1);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e1, "");
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e1);
}
}
- //throw new PAPException("Failed to load policy '" + id + "' from location '" + location + "'");
}
}
// Check for this, although it should always return something
//
if (finder == null) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "pip finder factory returned a null engine.");
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "pip finder factory returned a null engine.");
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "pip finder factory returned a null engine.");
throw new PIPException("Could not create PIP Finder");
} else {
- logger.info("Loaded PIP finder");
+ LOGGER.info("Loaded PIP finder");
}
for (PIPEngine engine : finder.getPIPEngines()) {
- logger.info("Configured PIP Engine: " + engine.getName());
+ LOGGER.info("Configured PIP Engine: " + engine.getName());
StdPDPPIPConfig config = new StdPDPPIPConfig();
config.setName(engine.getName());
status.addLoadedPipConfig(config);
}
} catch (FactoryException | PIPException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "validate PIP configuration failed: "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "validate PIP configuration failed: "
+ e.getLocalizedMessage());
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e.getLocalizedMessage(), "validate PIP configuration failed");
status.addLoadError(e.getLocalizedMessage());
status.setStatus(Status.LOAD_ERRORS);
throw new PAPException(e);
//
policyExists = Files.exists(Paths.get(propLocation));
if (policyExists == false) {
- logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy file " + policy + " expected at "
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy file " + policy + " expected at "
+ propLocation + " does NOT exist.");
}
}
// Set the property so the PDP engine doesn't have
// to pull it from the URL but rather the FILE.
//
- logger.info("Policy does exist: "
+ LOGGER.info("Policy does exist: "
+ outFile.toAbsolutePath().toString());
props.setProperty(policy
+ StdPolicyFinderFactory.PROP_FILE, outFile
// Create the URL
//
url = new URL(papUrls.getUrl(PapUrlResolver.extractIdFromUrl(propLocation)));
- logger.info("Pulling " + url.toString());
+ LOGGER.info("Pulling " + url.toString());
//
// Open the connection
//
//
// Now save it in the properties as a .file
//
- logger.info("Pulled policy: "
+ LOGGER.info("Pulled policy: "
+ outFile.toAbsolutePath().toString());
props.setProperty(policy
+ StdPolicyFinderFactory.PROP_FILE,
} catch (Exception e) {
papUrls.failed();
if (e instanceof MalformedURLException) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '"
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '"
+ policy
+ "' had bad URL in new configuration, URL='"
+ propLocation + "'");
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Policy '"
- // + policy
- // + "' had bad URL in new configuration, URL='"
- // + propLocation + "'");
} else {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy "
+ policy
+ " from URL "
+ url.toString() + ", e=" + e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Error while retrieving policy "
- // + policy
- // + " from URL "
- // + url.toString());
}
}
papUrls.getNext();
}
} else {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy " + policy
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy " + policy
+ " does NOT exist and does NOT have a URL");
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Policy " + policy
- // + " does NOT exist and does NOT have a URL");
}
}
}
Path policyProperties = Paths.get(config.toAbsolutePath().toString(),
"xacml.policy.properties");
if (Files.notExists(policyProperties)) {
- logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + policyProperties.toAbsolutePath().toString()
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + policyProperties.toAbsolutePath().toString()
+ " does NOT exist.");
//
// Try to create the file
try {
Files.createFile(policyProperties);
} catch (IOException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create policy properties file: "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create policy properties file: "
+ policyProperties.toAbsolutePath().toString());
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to create policy properties file: "
- // + policyProperties.toAbsolutePath().toString());
throw new PAPException(
"Failed to create policy properties file: "
+ policyProperties.toAbsolutePath().toString());
Path pipConfigProperties = Paths.get(
config.toAbsolutePath().toString(), "xacml.pip.properties");
if (Files.notExists(pipConfigProperties)) {
- logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + pipConfigProperties.toAbsolutePath().toString()
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + pipConfigProperties.toAbsolutePath().toString()
+ " does NOT exist.");
//
// Try to create the file
try {
Files.createFile(pipConfigProperties);
} catch (IOException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create pip properties file: "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create pip properties file: "
+ pipConfigProperties.toAbsolutePath().toString());
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to create pip properties file: "
- //+ pipConfigProperties.toAbsolutePath().toString());
throw new PAPException("Failed to create pip properties file: "
+ pipConfigProperties.toAbsolutePath().toString());
}
Path config = Paths.get(XACMLProperties
.getProperty(XACMLRestProperties.PROP_PDP_CONFIG));
if (Files.notExists(config)) {
- logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + config.toAbsolutePath().toString() + " does NOT exist.");
+ LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + config.toAbsolutePath().toString() + " does NOT exist.");
//
// Try to create the directory
//
try {
Files.createDirectories(config);
} catch (IOException e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
+ config.toAbsolutePath().toString(), e);
- // TODO:EELF Cleanup - Remove logger
- //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to create config directory: "
- //+ config.toAbsolutePath().toString());
throw new PAPException("Failed to create config directory: "
+ config.toAbsolutePath().toString());
}