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.onap.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.onap.policy.common.logging.eelf.MessageCodes;
42 import org.onap.policy.common.logging.eelf.PolicyLogger;
43 import org.onap.policy.xacml.api.XACMLErrorConstants;
44 import org.onap.policy.xacml.api.pap.OnapPDP;
45 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
46 import org.onap.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 OnapPDPGroup, StdItemSetChangeListener, Comparable<Object>, Serializable {
63 private static final long serialVersionUID = 1L;
64 private static final String groupNotExist= "Group directory does NOT exist";
65 private static Log logger = LogFactory.getLog(StdPDPGroup.class);
69 private boolean isDefault = false;
73 private String description;
75 private transient StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN);
77 private transient Set<OnapPDP> pdps = new HashSet<>();
79 private transient Set<PDPPolicy> policies = new HashSet<>();
81 private transient Set<PDPPolicy> selectedPolicies = new HashSet<>();
83 private transient Set<PDPPIPConfig> pipConfigs = new HashSet<>();
85 private String operation;
88 private transient Path directory;
91 private Integer jmxport;
94 public StdPDPGroup(String id, Path directory) {
96 this.directory = directory;
99 public StdPDPGroup(String id, boolean isDefault, Path directory) {
101 this.isDefault = isDefault;
104 public StdPDPGroup(String id, boolean isDefault, String name, String description, Path directory) {
105 this(id, isDefault, directory);
107 // force all policies to have a name
111 this.description = description;
114 public StdPDPGroup(String id, String name, String description, Path directory) {
115 this(id, false, name, description, directory);
119 public StdPDPGroup(String id, boolean isDefault, Properties properties, Path directory) throws PAPException {
120 this(id, isDefault, directory);
121 this.initialize(properties, directory);
125 private void initialize(Properties properties, Path directory) throws PAPException {
126 if (this.id == null || this.id.length() == 0) {
127 logger.warn("Cannot initialize with a null or zero length id");
131 // Pull the group's properties
133 for (Object key : properties.keySet()) {
134 if (key.toString().startsWith(this.id + ".")) {
135 if (key.toString().endsWith(".name")) {
136 this.name = properties.getProperty(key.toString());
137 } else if (key.toString().endsWith(".description")) {
138 this.description = properties.getProperty(key.toString());
139 } else if (key.toString().endsWith(".pdps")) {
140 String pdpList = properties.getProperty(key.toString());
141 if (pdpList != null && pdpList.length() > 0) {
142 for (String pdpId : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) {
143 StdPDP pdp = new StdPDP(pdpId, properties);
144 pdp.addItemSetChangeListener(this);
150 // force all policies to have a name
151 if (this.name == null) {
156 // Validate our directory
158 if (Files.notExists(directory)) {
159 logger.warn("Group directory does NOT exist: " + directory.toString());
161 Files.createDirectory(directory);
162 this.status.addLoadWarning(groupNotExist);
163 } catch (IOException e) {
164 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", groupNotExist);
165 this.status.addLoadError(groupNotExist);
166 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
172 this.loadPolicies(Paths.get(directory.toString(), "xacml.policy.properties"));
176 this.loadPIPConfig(Paths.get(directory.toString(), "xacml.pip.properties"));
179 public void loadPolicies(Path file) throws PAPException {
181 // Read the Groups Policies
183 Properties policyProperties = new Properties();
184 if ( ! file.toFile().exists()) {
185 // need to create the properties file with default values
186 policyProperties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "");
187 policyProperties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
188 // save properties to file
189 try (OutputStream os = Files.newOutputStream(file)) {
190 policyProperties.store(os, "");
191 } catch (Exception e) {
192 throw new PAPException("Failed to create new default policy properties file '" + file +"'", e);
195 // load previously existing file
198 // Load the properties
200 try (InputStream is = Files.newInputStream(file)) {
201 policyProperties.load(is);
204 // Parse the policies
206 this.readPolicyProperties(directory, policyProperties);
207 } catch (IOException e) {
208 logger.warn("Failed to load group policy properties file: " + file, e);
209 this.status.addLoadError("Not policy properties defined");
210 this.status.setStatus(Status.LOAD_ERRORS);
211 throw new PAPException("Failed to load group policy properties file: " + file);
216 public void loadPIPConfig(Path file) throws PAPException {
218 // Read the Groups' PIP configuration
220 Properties pipProperties = new Properties();
221 if ( ! file.toFile().exists()) {
222 // need to create the properties file with no values
223 pipProperties = setPIPProperties(pipProperties);
224 // save properties to file
226 try (OutputStream os = Files.newOutputStream(file)) {
227 pipProperties.store(os, "");
229 } catch (Exception e) {
230 throw new PAPException("Failed to create new default pip properties file '" + file +"'", e);
232 //Even if we create a new pip file, we still need to parse and load the properties
234 this.readPIPProperties(pipProperties);
236 throw new PAPException("Failed to load the new pip properties file", e);
241 // Load the properties
243 try (InputStream is = Files.newInputStream(file)) {
244 pipProperties.load(is);
246 // For all old PIP config's modify to the new PIP Configuration.
247 // If PIP is empty add the new values and save it.
248 if("".equals(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim())){
249 pipProperties = setPIPProperties(pipProperties);
250 try (OutputStream os = Files.newOutputStream(file)) {
251 pipProperties.store(os, "");
257 this.readPIPProperties(pipProperties);
258 } catch (IOException e) {
259 logger.warn("Failed to open group PIP Config properties file: " + file, e);
260 this.status.addLoadError("Not PIP config properties defined");
261 this.status.setStatus(Status.LOAD_ERRORS);
262 throw new PAPException("Failed to load group policy properties file: " + file);
268 public void resetStatus() {
270 // Reset our status object
274 // Determine our status
276 for (PDP pdp : this.pdps) {
277 switch (pdp.getStatus().getStatus()) {
279 this.status.addOutOfSynchPDP(pdp);
281 case LAST_UPDATE_FAILED:
282 this.status.addLastUpdateFailedPDP(pdp);
285 this.status.addFailedPDP(pdp);
287 case UPDATING_CONFIGURATION:
288 this.status.addUpdatingPDP(pdp);
291 this.status.addInSynchPDP(pdp);
297 this.status.addUnknownPDP(pdp);
302 // priority is worst-cast to best case
303 if (!this.status.getUnknownPDPs().isEmpty()) {
304 this.status.setStatus(Status.UNKNOWN);
305 } else if (!this.status.getFailedPDPs().isEmpty() || !this.status.getLastUpdateFailedPDPs().isEmpty()) {
306 this.status.setStatus(Status.LOAD_ERRORS);
307 } else if (!this.status.getOutOfSynchPDPs().isEmpty()) {
308 this.status.setStatus(Status.OUT_OF_SYNCH);
309 } else if (!this.status.getUpdatingPDPs().isEmpty()) {
310 this.status.setStatus(Status.UPDATING_CONFIGURATION);
312 this.status.setStatus(Status.OK);
317 public String getId() {
321 public void setId(String id) {
326 public boolean isDefaultGroup() {
327 return this.isDefault;
330 public void setDefaultGroup(boolean isDefault) {
331 this.isDefault = isDefault;
333 // Cannot fire this because 2 operations have
334 // to occur: 1) old default=false (don't want to fire) and
335 // then 2) new default=true (yes fire - but we'll have to do that
337 //this.firePDPGroupChanged(this);
341 public String getName() {
346 public void setName(String groupName) {
347 this.name = groupName;
348 this.firePDPGroupChanged(this);
352 public String getDescription() {
353 return this.description;
357 public void setDescription(String groupDescription) {
358 this.description = groupDescription;
359 this.firePDPGroupChanged(this);
362 public Path getDirectory() {
363 return this.directory;
366 public void setDirectory(Path groupDirectory) {
367 this.directory = groupDirectory;
368 // this is used only for transmission on the RESTful interface, so no need to fire group changed?
372 public PDPGroupStatus getStatus(){
377 public Set<PDPPolicy> getSelectedPolicies() {
378 return this.selectedPolicies;
382 public String getOperation() {
383 return this.operation;
387 public Set<PDP> getPdps() {
388 return Collections.unmodifiableSet(pdps);
391 public void setOnapPdps(Set<OnapPDP> pdps) {
396 public Set<OnapPDP> getOnapPdps(){
397 return Collections.unmodifiableSet(pdps);
400 public boolean addPDP(OnapPDP pdp) {
401 return this.pdps.add(pdp);
404 public boolean removePDP(PDP pdp) {
405 return this.pdps.remove(pdp);
409 public Set<PDPPolicy> getPolicies() {
410 return Collections.unmodifiableSet(this.policies);
414 public PDPPolicy getPolicy(String id) {
415 for (PDPPolicy policy : this.policies) {
416 if (policy.getId().equals(id)) {
424 public Properties getPolicyProperties()
426 Properties properties = new Properties(){
427 private static final long serialVersionUID = 1L;
428 // For Debugging it is helpful for the file to be in a sorted order,
429 // any by returning the keys in the natural Alpha order for strings we get close enough.
430 // TreeSet is sorted, and this just overrides the normal Properties method to get the keys.
432 public synchronized Enumeration<Object> keys() {
433 return Collections.enumeration(new TreeSet<Object>(super.keySet()));
436 List<String> roots = new ArrayList<>();
437 List<String> refs = new ArrayList<>();
439 for (PDPPolicy policy : this.policies) {
440 // for all policies need to tell PDP the "name", which is the base name for the file id
441 if (policy.getName() != null) {
442 properties.setProperty(policy.getId() + ".name", policy.getName());
444 // put the policy on the correct list
445 if (policy.isRoot()) {
446 roots.add(policy.getId());
448 refs.add(policy.getId());
452 properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, Joiner.on(',').join(roots));
453 properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, Joiner.on(',').join(refs));
458 public PDPPolicy publishPolicy(String id, String name, boolean isRoot, InputStream policy) throws PAPException {
460 // Does it exist already?
462 if (this.getPolicy(id) != null) {
463 throw new PAPException("Policy with id " + id + " already exists - unpublish it first.");
465 Path tempFile = null;
468 // Copy the policy over
470 tempFile = Files.createFile(Paths.get(this.directory.toAbsolutePath().toString(), id));
472 try (OutputStream os = Files.newOutputStream(tempFile)) {
473 num = ByteStreams.copy(policy, os);
475 logger.info("Copied " + num + " bytes for policy " + name);
477 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri());
478 if (tempRootPolicy.isValid() == false) {
480 Files.delete(tempFile);
481 } catch(Exception ee) {
482 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
484 throw new PAPException("Policy is invalid");
489 this.policies.add(tempRootPolicy);
493 this.firePDPGroupChanged(this);
495 // Return our new object.
497 return tempRootPolicy;
498 } catch (IOException e) {
499 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Failed to publishPolicy");
505 * Copy one policy file into the Group's directory but do not change the configuration.
506 * This is one part of a multi-step process of publishing policies.
507 * There may be multiple changes in the group (adding multiple policies, deleting policies, changine root<->referenced)
508 * that must be done all at once, so we just copy the file in preparation for a later "update whole group" operation.
515 * @throws PAPException
517 public void copyPolicyToFile(String id, InputStream policy) throws PAPException {
520 // Copy the policy over
523 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
526 if (Files.exists(policyFilePath)) {
527 policyFile = policyFilePath;
529 policyFile = Files.createFile(policyFilePath);
532 try (OutputStream os = Files.newOutputStream(policyFile)) {
533 num = ByteStreams.copy(policy, os);
536 logger.info("Copied " + num + " bytes for policy " + name);
538 for (PDPPolicy p : policies) {
539 if (p.getId().equals(id)) {
540 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
541 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
546 // policy is new to this group
547 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
548 if (tempRootPolicy.isValid() == false) {
550 Files.delete(policyFile);
551 } catch(Exception ee) {
552 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
554 throw new PAPException("Policy is invalid");
559 this.policies.add(tempRootPolicy);
563 this.firePDPGroupChanged(this);
564 } catch (IOException e) {
565 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
566 throw new PAPException("Failed to copy policy to file: " + e);
572 * Policy Engine API Copy one policy file into the Group's directory but do not change the configuration.
578 * @throws PAPException
580 public void copyPolicyToFile(String id, String name, InputStream policy) throws PAPException {
583 // Copy the policy over
586 Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id);
589 if (Files.exists(policyFilePath)) {
590 policyFile = policyFilePath;
592 policyFile = Files.createFile(policyFilePath);
595 try (OutputStream os = Files.newOutputStream(policyFile)) {
596 num = ByteStreams.copy(policy, os);
599 logger.info("Copied " + num + " bytes for policy " + name);
600 for (PDPPolicy p : policies) {
601 if (p.getId().equals(id)) {
602 // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group
603 logger.info("Policy '" + id + "' already exists in group '" + getId() + "'");
608 // policy is new to this group
609 StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri());
610 if (tempRootPolicy.isValid() == false) {
612 Files.delete(policyFile);
613 } catch(Exception ee) {
614 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it.");
616 throw new PAPException("Policy is invalid");
621 this.policies.add(tempRootPolicy);
625 this.firePDPGroupChanged(this);
627 } catch (IOException e) {
628 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile");
629 throw new PAPException("Failed to copy policy to file: " + e);
634 public boolean removePolicyFromGroup(PDPPolicy policy) {
635 PolicyLogger.info("policy: " + policy.getId());
636 PolicyLogger.info("Policy ID:" + policy.getPolicyId());
637 PolicyLogger.info("Policy Version: " + policy.getVersion());
638 PolicyLogger.info("StdPDPPolicy Class cast: " + this.getPolicy(policy.getId()).toString());
639 StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId());
640 if (currentPolicy == null) {
641 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
646 // Remove it from our list
648 this.policies.remove(currentPolicy);
652 this.firePDPGroupChanged(this);
654 } catch (Exception e) {
655 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy");
660 public boolean removePolicy(PDPPolicy policy) {
661 PDPPolicy currentPolicy = this.getPolicy(policy.getId());
662 if (currentPolicy == null) {
663 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist.");
670 Files.delete(Paths.get(currentPolicy.getLocation()));
672 // Remove it from our list
674 this.policies.remove(currentPolicy);
678 this.firePDPGroupChanged(this);
680 } catch (Exception e) {
681 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy " + policy);
687 public Set<PDPPIPConfig> getPipConfigs() {
688 return Collections.unmodifiableSet(this.pipConfigs);
692 public PDPPIPConfig getPipConfig(String id) {
693 for (PDPPIPConfig config : this.pipConfigs) {
694 if (config.getId().equals(id)) {
701 public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) {
702 this.pipConfigs = pipConfigs;
703 this.firePDPGroupChanged(this);
706 public void removeAllPIPConfigs() {
707 this.pipConfigs.clear();
708 this.firePDPGroupChanged(this);
712 public Properties getPipConfigProperties() {
713 Properties properties = new Properties();
714 List<String> configs = new ArrayList<>();
716 for (PDPPIPConfig config : this.pipConfigs) {
717 configs.add(config.getId());
718 properties.putAll(config.getConfiguration());
721 properties.setProperty(XACMLProperties.PROP_PIP_ENGINES, Joiner.on(',').join(configs));
727 public void repair() {
729 // Reset the status object
733 // Validate our directory
735 boolean fire = false;
736 if (Files.notExists(directory)) {
737 logger.warn("Group directory does NOT exist: " + directory.toString());
739 Files.createDirectory(directory);
741 this.status.addLoadWarning("Created missing group directory");
742 } catch (IOException e) {
743 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Group directory.");
744 this.status.addLoadError("Failed to create missing Group directory.");
745 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
749 // Validate our PIP config file
751 Path pipPropertiesFile = Paths.get(directory.toString(), "xacml.pip.properties");
752 if (Files.notExists(pipPropertiesFile)) {
754 Files.createFile(pipPropertiesFile);
756 this.status.addLoadWarning("Created missing PIP properties file");
757 } catch (IOException e) {
758 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing PIP properties file");
759 this.status.addLoadError("Failed to create missing PIP properties file");
760 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
764 // Valid our policy properties file
766 Path policyPropertiesFile = Paths.get(directory.toString(), "xacml.policy.properties");
767 if (Files.notExists(policyPropertiesFile)) {
769 Files.createFile(policyPropertiesFile);
771 this.status.addLoadWarning("Created missing Policy properties file");
772 } catch (IOException e) {
773 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Policy properties file");
774 this.status.addLoadError("Failed to create missing Policy properties file");
775 this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS);
784 private void readPolicyProperties(Path directory, Properties properties) {
786 // There are 2 property values that hold policies, root and referenced
788 String[] lists = new String[2];
789 lists[0] = properties.getProperty(XACMLProperties.PROP_ROOTPOLICIES);
790 lists[1] = properties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
792 // Iterate each policy list
794 boolean isRoot = true;
795 for (String list : lists) {
797 // Was there actually a property?
799 if (list == null || list.length() == 0) {
806 Iterable<String> policyList = Splitter.on(',').trimResults().omitEmptyStrings().split(list);
808 // Was there actually a list
810 if (policyList == null) {
814 for (String policyId : policyList) {
816 // Construct the policy filename
818 Path policyPath = Paths.get(directory.toString(), policyId );
820 // Create the Policy Object
824 policy = new StdPDPPolicy(id, isRoot, policyPath.toUri(), properties);
825 } catch (IOException e) {
826 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create policy object");
832 if (policy != null && policy.isValid()) {
833 this.policies.add(policy);
834 this.status.addLoadedPolicy(policy);
836 this.status.addFailedPolicy(policy);
837 this.status.setStatus(Status.LOAD_ERRORS);
839 // force all policies to have a name
840 if (policy!=null && policy.getName() == null) {
841 policy.setName(policy.getId());
848 private void readPIPProperties(Properties properties) {
849 String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES);
850 if (list == null || list.length() == 0) {
853 for (String pipId : list.split("[,]")) {
854 StdPDPPIPConfig config = new StdPDPPIPConfig(pipId, properties);
855 if (config.isConfigured()) {
856 this.pipConfigs.add(config);
857 this.status.addLoadedPipConfig(config);
859 this.status.addFailedPipConfig(config);
860 this.status.setStatus(Status.LOAD_ERRORS);
866 public int hashCode() {
867 final int prime = 31;
869 result = prime * result + ((id == null) ? 0 : id.hashCode());
874 public boolean equals(Object obj) {
879 if (getClass() != obj.getClass())
881 StdPDPGroup other = (StdPDPGroup) obj;
883 if (other.id != null)
885 } else if (!id.equals(other.id))
891 public String toString() {
892 return "StdPDPGroup [id=" + id + ", isDefault=" + isDefault + ", name="
893 + name + ", description=" + description + ", status=" + status
894 + ", pdps=" + pdps + ", policies=" + policies + ", pipConfigs="
895 + pipConfigs + ", directory=" + directory + ",selectedPolicies="
896 + selectedPolicies + ",operation=" + operation + "]";
900 public void changed() {
902 // save the (changed) properties
904 saveGroupConfiguration();
905 } catch (PAPException | IOException e) {
906 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Unable to save group configuration change");
907 // don't notify other things of change if we cannot save it???
911 this.firePDPGroupChanged(this);
916 public void groupChanged(OnapPDPGroup group) {
921 public void pdpChanged(OnapPDP pdp) {
923 // If one of the group's PDP's changed, then the group changed
929 public StdPDPGroup() {
931 // Methods needed for JSON deserialization
935 public StdPDPGroup(OnapPDPGroup group) {
936 this.id = group.getId();
937 this.name = group.getName();
938 this.description = group.getDescription();
939 this.isDefault = group.isDefaultGroup();
940 this.pdps = group.getOnapPdps();
941 this.policies = group.getPolicies();
942 this.pipConfigs = group.getPipConfigs();
945 public boolean isDefault() {
948 public void setDefault(boolean isDefault) {
949 this.isDefault = isDefault;
951 public void setStatus(PDPGroupStatus status) {
952 this.status = new StdPDPGroupStatus(status);
954 public void setPolicies(Set<PDPPolicy> policies) {
955 this.policies = policies;
957 public void setSelectedPolicies(Set<PDPPolicy> selectedPolicies) {
958 this.selectedPolicies = selectedPolicies;
960 public void setOperation(String operation) {
961 this.operation = operation;
964 public void saveGroupConfiguration() throws PAPException, IOException {
966 // First save the Policy properties
968 // save the lists of policies
969 Properties policyProperties = this.getPolicyProperties();
971 // save info about each policy
972 for (PDPPolicy policy : this.policies){
973 policyProperties.put(policy.getId() + ".name", policy.getName());
977 // Now we can save the file
979 Path file = Paths.get(this.directory.toString(), "xacml.policy.properties");
980 try (OutputStream os = Files.newOutputStream(file)) {
981 policyProperties.store(os, "");
982 } catch (Exception e) {
983 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "STdPDPGroup", "Group Policies Config save failed");
984 throw new PAPException("Failed to save policy properties file '" + file +"'");
988 // Now save the PIP Config properties
989 Properties pipProperties = this.getPipConfigProperties();
992 // Now we can save the file
994 file = Paths.get(this.directory.toString(), "xacml.pip.properties");
995 try (OutputStream os = Files.newOutputStream(file)) {
996 pipProperties.store(os, "");
997 } catch (Exception e) {
998 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group PIP Config save failed");
999 throw new PAPException("Failed to save pip properties file '" + file +"'");
1004 // Comparable Interface
1007 public int compareTo(Object arg0) {
1011 if ( ! (arg0 instanceof StdPDPGroup)) {
1014 if (((StdPDPGroup)arg0).name == null) {
1021 return name.compareTo(((StdPDPGroup)arg0).name);
1024 //Adding Default PIP engine(s) while Loading initially. We don't want
1025 // Programmer intervention with the PIP engines.
1026 private Properties setPIPProperties(Properties props){
1027 props.setProperty("AAF.name", "AAFEngine");
1028 props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions");
1029 props.setProperty("AAF.classname","org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine");
1030 props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF");
1031 // read from PIP properties file.
1032 Path file = Paths.get(StdEngine.pipPropertyFile);
1033 if (!Files.notExists(file)) {
1035 Properties prop = new Properties();
1037 in = new FileInputStream(file.toFile());
1039 } catch (IOException e) {
1040 PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e);