- public synchronized void loadPolicies(Map<String, Object> toscaPolicies) {
- try {
- //
- // Convert the policies first
- //
- List<PolicyType> listPolicies = translator.scanAndConvertPolicies(toscaPolicies);
- if (listPolicies.isEmpty()) {
- throw new ToscaPolicyConversionException("Converted 0 policies");
- }
- //
- // Create a copy of the properties object
- //
- Properties newProperties = this.getProperties();
- //
- // Iterate through the policies
- //
- for (PolicyType newPolicy : listPolicies) {
- //
- // Construct the filename
- //
- Path refPath = XacmlPolicyUtils.constructUniquePolicyFilename(newPolicy, this.getDataPath());
- //
- // Write the policy to disk
- // Maybe check for an error
- //
- XACMLPolicyWriter.writePolicyFile(refPath, newPolicy);
- //
- // Add root policy to properties object
- //
- XacmlPolicyUtils.addRootPolicy(newProperties, refPath);
- }
- //
- // Write the properties to disk
- //
- XacmlPolicyUtils.storeXacmlProperties(newProperties,
- XacmlPolicyUtils.getPropertiesPath(this.getDataPath()));
- //
- // Reload the engine
- //
- this.createEngine(newProperties);
- } catch (IOException | ToscaPolicyConversionException e) {
- LOGGER.error("Failed to loadPolicies {}", e);
- }