2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.policy.xacml.std.pap;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.io.Serializable;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Enumeration;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Properties;
37 import java.util.TreeSet;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import org.openecomp.policy.common.logging.eelf.MessageCodes;
42 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
43 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
44 import org.openecomp.policy.xacml.api.pap.EcompPDP;
45 import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
46 import org.openecomp.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
48 import com.att.research.xacml.api.pap.PAPException;
49 import com.att.research.xacml.api.pap.PDP;
50 //import com.att.research.xacml.api.pap.PDPGroup;
51 import com.att.research.xacml.api.pap.PDPGroupStatus;
52 import com.att.research.xacml.api.pap.PDPGroupStatus.Status;
53 import com.att.research.xacml.api.pap.PDPPIPConfig;
54 import com.att.research.xacml.api.pap.PDPPolicy;
55 import com.att.research.xacml.util.XACMLProperties;
56 import com.fasterxml.jackson.annotation.JsonIgnore;
57 import com.google.common.base.Joiner;
58 import com.google.common.base.Splitter;
59 import com.google.common.io.ByteStreams;
61 public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements EcompPDPGroup, StdItemSetChangeListener, Comparable<Object>, Serializable {
62 private static final long serialVersionUID = 1L;
63 private static Log logger = LogFactory.getLog(StdPDPGroup.class);
67 private boolean isDefault = false;
71 private String description;
73 private StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN);
75 private Set<EcompPDP> pdps = new HashSet<EcompPDP>();
77 private Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
79 private Set<PDPPolicy> selectedPolicies = new HashSet<PDPPolicy>();
81 private Set<PDPPIPConfig> pipConfigs = new HashSet<PDPPIPConfig>();
83 private String operation;
86 private Path directory;
89 private Integer jmxport;
92 public StdPDPGroup(String id, Path directory) {
94 this.directory = directory;
97 public StdPDPGroup(String id, boolean isDefault, Path directory) {
99 this.isDefault = isDefault;
102 public StdPDPGroup(String id, boolean isDefault, String name, String description, Path directory) {
103 this(id, isDefault, directory);
105 // force all policies to have a name
109 this.description = description;
112 public StdPDPGroup(String id, String name, String description, Path directory) {
113 this(id, false, name, description, directory);
117 public StdPDPGroup(String id, boolean isDefault, Properties properties, Path directory) throws PAPException {
118 this(id, isDefault, directory);
119 this.initialize(properties, directory);
123 private void initialize(Properties properties, Path directory) throws PAPException {
124 if (this.id == null || this.id.length() == 0) {
125 logger.warn("Cannot initialize with a null or zero length id");
129 // Pull the group's properties
131 for (Object key : properties.keySet()) {
132 if (key.toString().startsWith(this.id + ".")) {
133 if (key.toString().endsWith(".name")) {
134 this.name = properties.getProperty(key.toString());
135 } else if (key.toString().endsWith(".description")) {
136 this.description = properties.getProperty(key.toString());
137 } else if (key.toString().endsWith(".pdps")) {
138 String pdpList = properties.getProperty(key.toString());
139 if (pdpList != null && pdpList.length() > 0) {
140 for (String id : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) {
141 StdPDP pdp = new StdPDP(id, properties);
142 pdp.addItemSetChangeListener(this);
148 // force all policies to have a name
149 if (this.name == null) {
154 // Validate our directory
156 if (Files.notExists(directory)) {
157 logger.warn("Group directory does NOT exist: " + directory.toString());
159 Files.createDirectory(directory);
160 this.status.addLoadWarning("Group directory does NOT exist");
161 } catch (IOException e) {
162 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group directory does NOT exist");
163 this.status.addLoadError("Group directory does NOT exist");
164 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
170 this.loadPolicies(Paths.get(directory.toString(), "xacml.policy.properties"));
174 this.loadPIPConfig(Paths.get(directory.toString(), "xacml.pip.properties"));
177 public void loadPolicies(Path file) throws PAPException {
179 // Read the Groups Policies
181 Properties policyProperties = new Properties();
182 if ( ! file.toFile().exists()) {
183 // need to create the properties file with default values
184 policyProperties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "");
185 policyProperties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
186 // save properties to file
187 try (OutputStream os = Files.newOutputStream(file)) {
188 policyProperties.store(os, "");
189 } catch (Exception e) {
190 throw new PAPException("Failed to create new default policy properties file '" + file +"'");
193 // load previously existing file
196 // Load the properties
198 try (InputStream is = Files.newInputStream(file)) {
199 policyProperties.load(is);
202 // Parse the policies
204 this.readPolicyProperties(directory, policyProperties);
205 } catch (IOException e) {
206 logger.warn("Failed to load group policy properties file: " + file, e);
207 this.status.addLoadError("Not policy properties defined");
208 this.status.setStatus(Status.LOAD_ERRORS);
209 throw new PAPException("Failed to load group policy properties file: " + file);
214 public void loadPIPConfig(Path file) throws PAPException {
216 // Read the Groups' PIP configuration
218 Properties pipProperties = new Properties();
219 if ( ! file.toFile().exists()) {
220 // need to create the properties file with no values
221 pipProperties = setPIPProperties(pipProperties);
222 // save properties to file
224 try (OutputStream os = Files.newOutputStream(file)) {
225 pipProperties.store(os, "");
227 } catch (Exception e) {
228 throw new PAPException("Failed to create new default pip properties file '" + file +"'");
230 //Even if we create a new pip file, we still need to parse and load the properties
232 this.readPIPProperties(directory, pipProperties);
234 throw new PAPException("Failed to load the new pip properties file");
239 // Load the properties
241 try (InputStream is = Files.newInputStream(file)) {
242 pipProperties.load(is);
244 // For all old PIP config's modify to the new PIP Configuration.
245 // If PIP is empty add the new values and save it.
246 if(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim().equals("")){
247 pipProperties = setPIPProperties(pipProperties);
248 try (OutputStream os = Files.newOutputStream(file)) {
249 pipProperties.store(os, "");
255 this.readPIPProperties(directory, pipProperties);
256 } catch (IOException e) {
257 logger.warn("Failed to open group PIP Config properties file: " + file, e);
258 this.status.addLoadError("Not PIP config properties defined");
259 this.status.setStatus(Status.LOAD_ERRORS);
260 throw new PAPException("Failed to load group policy properties file: " + file);
266 public void resetStatus() {
268 // // If we are updating, don't allow reset
270 // if (this.status.getStatus() == Status.UPDATING_CONFIGURATION) {
271 // logger.warn("We are updating, chill.");
275 // // Load errors take precedence
277 // if (this.status.getStatus() == Status.LOAD_ERRORS) {
278 // logger.warn("We had load errors.");
282 // Reset our status object
286 // Determine our status
288 for (PDP pdp : this.pdps) {
289 switch (pdp.getStatus().getStatus()) {
291 this.status.addOutOfSynchPDP(pdp);
293 case LAST_UPDATE_FAILED:
294 this.status.addLastUpdateFailedPDP(pdp);
297 this.status.addFailedPDP(pdp);
299 case UPDATING_CONFIGURATION:
300 this.status.addUpdatingPDP(pdp);
303 this.status.addInSynchPDP(pdp);
309 this.status.addUnknownPDP(pdp);
314 // priority is worst-cast to best case
315 if (this.status.getUnknownPDPs().size() > 0) {
316 this.status.setStatus(Status.UNKNOWN);
317 } else if (this.status.getFailedPDPs().size() > 0 || this.status.getLastUpdateFailedPDPs().size() > 0) {
318 this.status.setStatus(Status.LOAD_ERRORS);
319 } else if (this.status.getOutOfSynchPDPs().size() > 0) {
320 this.status.setStatus(Status.OUT_OF_SYNCH);
321 } else if (this.status.getUpdatingPDPs().size() > 0) {
322 this.status.setStatus(Status.UPDATING_CONFIGURATION);
324 this.status.setStatus(Status.OK);
329 public String getId() {
333 public void setId(String id) {
338 public boolean isDefaultGroup() {
339 return this.isDefault;
342 public void setDefaultGroup(boolean isDefault) {
343 this.isDefault = isDefault;
345 // Cannot fire this because 2 operations have
346 // to occur: 1) old default=false (don't want to fire) and
347 // then 2) new default=true (yes fire - but we'll have to do that
349 //this.firePDPGroupChanged(this);
353 public String getName() {
358 public void setName(String groupName) {
359 this.name = groupName;
360 this.firePDPGroupChanged(this);
364 public String getDescription() {
365 return this.description;
369 public void setDescription(String groupDescription) {
370 this.description = groupDescription;
371 this.firePDPGroupChanged(this);
374 public Path getDirectory() {
375 return this.directory;
378 public void setDirectory(Path groupDirectory) {
379 this.directory = groupDirectory;
380 // this is used only for transmission on the RESTful interface, so no need to fire group changed?
384 public PDPGroupStatus getStatus(){
389 public Set<PDPPolicy> getSelectedPolicies() {
390 return this.selectedPolicies;
394 public String getOperation() {
395 return this.operation;
399 public Set<PDP> getPdps() {
400 return Collections.unmodifiableSet(pdps);
403 public void setEcompPdps(Set<EcompPDP> pdps) {
407 public Set<EcompPDP> getEcompPdps(){
408 return Collections.unmodifiableSet(pdps);
411 public boolean addPDP(EcompPDP pdp) {
412 return this.pdps.add(pdp);
415 public boolean removePDP(PDP pdp) {
416 return this.pdps.remove(pdp);
420 public Set<PDPPolicy> getPolicies() {
421 return Collections.unmodifiableSet(this.policies);
425 public PDPPolicy getPolicy(String id) {
426 for (PDPPolicy policy : this.policies) {
427 if (policy.getId().equals(id)) {
434 public Properties getPolicyProperties()
436 Properties properties = new Properties(){
437 private static final long serialVersionUID = 1L;
438 // For Debugging it is helpful for the file to be in a sorted order,
439 // any by returning the keys in the natural Alpha order for strings we get close enough.
440 // TreeSet is sorted, and this just overrides the normal Properties method to get the keys.
442 public synchronized Enumeration<Object> keys() {
443 return Collections.enumeration(new TreeSet<Object>(super.keySet()));
446 List<String> roots = new ArrayList<String>();
447 List<String> refs = new ArrayList<String>();
449 for (PDPPolicy policy : this.policies) {
450 // for all policies need to tell PDP the "name", which is the base name for the file id
451 if (policy.getName() != null) {
452 properties.setProperty(policy.getId() + ".name", policy.getName());
454 // put the policy on the correct list
455 if (policy.isRoot()) {
456 roots.add(policy.getId());
458 refs.add(policy.getId());
462 properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, Joiner.on(',').join(roots));
463 properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, Joiner.on(',').join(refs));
468 public PDPPolicy publishPolicy(String id, String name, boolean isRoot, InputStream policy) throws PAPException {
470 // Does it exist already?
472 if (this.getPolicy(id) != null) {
473 throw new PAPException("Policy with id " + id + " already exists - unpublish it first.");
475 Path tempFile = null;
478 // Copy the policy over
480 tempFile = Files.createFile(Paths.get(this.directory.toAbsolutePath().toString(), id));
482 try (OutputStream os = Files.newOutputStream(tempFile)) {
483 num = ByteStreams.copy(policy, os);
485 logger.info("Copied " + num + " bytes for policy " + name);
487 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri());
488 if (tempRootPolicy.isValid() == false) {
490 Files.delete(tempFile);
491 } catch(Exception ee) {
492 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
494 throw new PAPException("Policy is invalid");
499 this.policies.add(tempRootPolicy);
503 this.firePDPGroupChanged(this);
505 // Return our new object.
507 return tempRootPolicy;
508 } catch (IOException e) {
509 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Failed to publishPolicy");
515 * Copy one policy file into the Group's directory but do not change the configuration.
516 * This is one part of a multi-step process of publishing policies.
517 * There may be multiple changes in the group (adding multiple policies, deleting policies, changine root<->referenced)
518 * that must be done all at once, so we just copy the file in preparation for a later "update whole group" operation.
525 * @throws PAPException
527 public void copyPolicyToFile(String id, InputStream policy) throws PAPException {
530 // Copy the policy over
533 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
536 if (Files.exists(policyFilePath)) {
537 policyFile = policyFilePath;
539 policyFile = Files.createFile(policyFilePath);
542 try (OutputStream os = Files.newOutputStream(policyFile)) {
543 num = ByteStreams.copy(policy, os);
546 logger.info("Copied " + num + " bytes for policy " + name);
548 for (PDPPolicy p : policies) {
549 if (p.getId().equals(id)) {
550 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
551 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
556 // policy is new to this group
557 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
558 if (tempRootPolicy.isValid() == false) {
560 Files.delete(policyFile);
561 } catch(Exception ee) {
562 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
564 throw new PAPException("Policy is invalid");
569 this.policies.add(tempRootPolicy);
573 this.firePDPGroupChanged(this);
574 } catch (IOException e) {
575 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
576 throw new PAPException("Failed to copy policy to file: " + e);
582 * Policy Engine API Copy one policy file into the Group's directory but do not change the configuration.
588 * @throws PAPException
590 public void copyPolicyToFile(String id, String name, InputStream policy) throws PAPException {
593 // Copy the policy over
596 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
599 if (Files.exists(policyFilePath)) {
600 policyFile = policyFilePath;
602 policyFile = Files.createFile(policyFilePath);
605 try (OutputStream os = Files.newOutputStream(policyFile)) {
606 num = ByteStreams.copy(policy, os);
609 logger.info("Copied " + num + " bytes for policy " + name);
610 for (PDPPolicy p : policies) {
611 if (p.getId().equals(id)) {
612 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
613 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
618 // policy is new to this group
619 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
620 if (tempRootPolicy.isValid() == false) {
622 Files.delete(policyFile);
623 } catch(Exception ee) {
624 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
626 throw new PAPException("Policy is invalid");
631 this.policies.add(tempRootPolicy);
635 this.firePDPGroupChanged(this);
637 } catch (IOException e) {
638 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
639 throw new PAPException("Failed to copy policy to file: " + e);
644 public boolean removePolicyFromGroup(PDPPolicy policy) {
645 StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId());
646 if (currentPolicy == null) {
647 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
652 // Remove it from our list
654 this.policies.remove(currentPolicy);
658 this.firePDPGroupChanged(this);
660 } catch (Exception e) {
661 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy");
666 public boolean removePolicy(PDPPolicy policy) {
667 StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId());
668 if (currentPolicy == null) {
669 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
676 Files.delete(Paths.get(currentPolicy.getLocation()));
678 // Remove it from our list
680 this.policies.remove(currentPolicy);
684 this.firePDPGroupChanged(this);
686 } catch (Exception e) {
687 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy " + policy);
693 public Set<PDPPIPConfig> getPipConfigs() {
694 return Collections.unmodifiableSet(this.pipConfigs);
698 public PDPPIPConfig getPipConfig(String id) {
699 for (PDPPIPConfig config : this.pipConfigs) {
700 if (config.getId().equals(id)) {
707 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
708 this.pipConfigs = pipConfigs;
709 this.firePDPGroupChanged(this);
712 public void removeAllPIPConfigs() {
713 this.pipConfigs.clear();
714 this.firePDPGroupChanged(this);
717 public Properties getPipConfigProperties() {
718 Properties properties = new Properties();
719 List<String> configs = new ArrayList<String>();
721 for (PDPPIPConfig config : this.pipConfigs) {
722 configs.add(config.getId());
723 properties.putAll(config.getConfiguration());
726 properties.setProperty(XACMLProperties.PROP_PIP_ENGINES, Joiner.on(',').join(configs));
732 public void repair() {
734 // Reset the status object
738 // Validate our directory
740 boolean fire = false;
741 if (Files.notExists(directory)) {
742 logger.warn("Group directory does NOT exist: " + directory.toString());
744 Files.createDirectory(directory);
746 this.status.addLoadWarning("Created missing group directory");
747 } catch (IOException e) {
748 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Group directory.");
749 this.status.addLoadError("Failed to create missing Group directory.");
750 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
754 // Validate our PIP config file
756 Path pipPropertiesFile = Paths.get(directory.toString(), "xacml.pip.properties");
757 if (Files.notExists(pipPropertiesFile)) {
759 Files.createFile(pipPropertiesFile);
761 this.status.addLoadWarning("Created missing PIP properties file");
762 } catch (IOException e) {
763 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing PIP properties file");
764 this.status.addLoadError("Failed to create missing PIP properties file");
765 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
769 // Valid our policy properties file
771 Path policyPropertiesFile = Paths.get(directory.toString(), "xacml.policy.properties");
772 if (Files.notExists(policyPropertiesFile)) {
774 Files.createFile(policyPropertiesFile);
776 this.status.addLoadWarning("Created missing Policy properties file");
777 } catch (IOException e) {
778 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Policy properties file");
779 this.status.addLoadError("Failed to create missing Policy properties file");
780 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
789 private void readPolicyProperties(Path directory, Properties properties) {
791 // There are 2 property values that hold policies, root and referenced
793 String[] lists = new String[2];
794 lists[0] = properties.getProperty(XACMLProperties.PROP_ROOTPOLICIES);
795 lists[1] = properties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
797 // Iterate each policy list
799 boolean isRoot = true;
800 for (String list : lists) {
802 // Was there actually a property?
804 if (list == null || list.length() == 0) {
811 Iterable<String> policyList = Splitter.on(',').trimResults().omitEmptyStrings().split(list);
813 // Was there actually a list
815 if (policyList == null) {
819 for (String id : policyList) {
821 // Construct the policy filename
823 Path policyPath = Paths.get(directory.toString(), id );
825 // Create the Policy Object
829 policy = new StdPDPPolicy(id, isRoot, policyPath.toUri(), properties);
830 } catch (IOException e) {
831 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create policy object");
837 if (policy != null && policy.isValid()) {
838 this.policies.add(policy);
839 this.status.addLoadedPolicy(policy);
841 this.status.addFailedPolicy(policy);
842 this.status.setStatus(Status.LOAD_ERRORS);
844 // force all policies to have a name
845 if (policy!=null && policy.getName() == null) {
846 policy.setName(policy.getId());
853 private void readPIPProperties(Path directory, Properties properties) {
854 String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES);
855 if (list == null || list.length() == 0) {
858 for (String id : list.split("[,]")) {
859 StdPDPPIPConfig config = new StdPDPPIPConfig(id, properties);
860 if (config.isConfigured()) {
861 this.pipConfigs.add(config);
862 this.status.addLoadedPipConfig(config);
864 this.status.addFailedPipConfig(config);
865 this.status.setStatus(Status.LOAD_ERRORS);
871 public int hashCode() {
872 final int prime = 31;
874 result = prime * result + ((id == null) ? 0 : id.hashCode());
879 public boolean equals(Object obj) {
884 if (getClass() != obj.getClass())
886 StdPDPGroup other = (StdPDPGroup) obj;
888 if (other.id != null)
890 } else if (!id.equals(other.id))
896 public String toString() {
897 return "StdPDPGroup [id=" + id + ", isDefault=" + isDefault + ", name="
898 + name + ", description=" + description + ", status=" + status
899 + ", pdps=" + pdps + ", policies=" + policies + ", pipConfigs="
900 + pipConfigs + ", directory=" + directory + ",selectedPolicies="
901 + selectedPolicies + ",operation=" + operation + "]";
905 public void changed() {
907 // save the (changed) properties
909 saveGroupConfiguration();
910 } catch (PAPException | IOException e) {
911 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Unable to save group configuration change");
912 // don't notify other things of change if we cannot save it???
916 this.firePDPGroupChanged(this);
921 public void groupChanged(EcompPDPGroup group) {
926 public void pdpChanged(EcompPDP pdp) {
928 // If one of the group's PDP's changed, then the group changed
935 // Methods needed for JSON deserialization
937 public StdPDPGroup() {
941 public StdPDPGroup(EcompPDPGroup group) {
942 this.id = group.getId();
943 this.name = group.getName();
944 this.description = group.getDescription();
945 this.isDefault = group.isDefaultGroup();
946 this.pdps = group.getEcompPdps();
947 this.policies = group.getPolicies();
948 this.pipConfigs = group.getPipConfigs();
951 public boolean isDefault() {
954 public void setDefault(boolean isDefault) {
955 this.isDefault = isDefault;
957 public void setStatus(PDPGroupStatus status) {
958 this.status = new StdPDPGroupStatus(status);
960 public void setPolicies(Set<PDPPolicy> policies) {
961 this.policies = policies;
963 public void setSelectedPolicies(Set<PDPPolicy> selectedPolicies) {
964 this.selectedPolicies = selectedPolicies;
966 public void setOperation(String operation) {
967 this.operation = operation;
970 public void saveGroupConfiguration() throws PAPException, IOException {
972 // First save the Policy properties
974 // save the lists of policies
975 Properties policyProperties = this.getPolicyProperties();
977 // save info about each policy
978 for (PDPPolicy policy : this.policies){
979 policyProperties.put(policy.getId() + ".name", policy.getName());
983 // Now we can save the file
985 Path file = Paths.get(this.directory.toString(), "xacml.policy.properties");
986 try (OutputStream os = Files.newOutputStream(file)) {
987 policyProperties.store(os, "");
988 } catch (Exception e) {
989 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "STdPDPGroup", "Group Policies Config save failed");
990 throw new PAPException("Failed to save policy properties file '" + file +"'");
994 // Now save the PIP Config properties
995 Properties pipProperties = this.getPipConfigProperties();
998 // Now we can save the file
1000 file = Paths.get(this.directory.toString(), "xacml.pip.properties");
1001 try (OutputStream os = Files.newOutputStream(file)) {
1002 pipProperties.store(os, "");
1003 } catch (Exception e) {
1004 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group PIP Config save failed");
1005 throw new PAPException("Failed to save pip properties file '" + file +"'");
1010 // Comparable Interface
1013 public int compareTo(Object arg0) {
1017 if ( ! (arg0 instanceof StdPDPGroup)) {
1020 if (((StdPDPGroup)arg0).name == null) {
1027 return name.compareTo(((StdPDPGroup)arg0).name);
1030 //Adding Default PIP engine(s) while Loading initially. We don't want
1031 // Programmer intervention with the PIP engines.
1032 private Properties setPIPProperties(Properties props){
1033 props.setProperty("AAF.name", "AAFEngine");
1034 props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions");
1035 props.setProperty("AAF.classname","org.openecomp.policy.xacml.std.pip.engines.aaf.AAFEngine");
1036 props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF");
1037 // read from PIP properties file.
1038 Path file = Paths.get(StdEngine.pipPropertyFile);
1039 if (!Files.notExists(file)) {
1041 Properties prop = new Properties();
1043 in = new FileInputStream(file.toFile());
1045 } catch (IOException e) {
1046 PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e);