X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-XACML%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fxacml%2Fstd%2Fpap%2FStdPDPPolicy.java;h=5288435aaa942a4e338bc634331cb0078f823b55;hp=2b198f5e7080dc35f9a0c0fcc903b72dc0c445eb;hb=refs%2Fchanges%2F29%2F98329%2F6;hpb=a2ab61f0ad39970ad35c3e47ff8429f59850c469 diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java index 2b198f5e7..5288435aa 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java @@ -2,15 +2,15 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,9 +18,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.xacml.std.pap; -import org.onap.policy.common.logging.eelf.PolicyLogger; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; import java.io.FileNotFoundException; import java.io.IOException; @@ -36,15 +41,9 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.onap.policy.common.logging.eelf.PolicyLogger; import org.onap.policy.xacml.util.XACMLPolicyScanner; -import com.att.research.xacml.api.pap.PAPException; -import com.att.research.xacml.api.pap.PDPPolicy; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.google.common.base.Splitter; -import com.google.common.collect.Lists; - - public class StdPDPPolicy implements PDPPolicy, Serializable { private static final long serialVersionUID = 1L; private static Log logger = LogFactory.getLog(StdPDPPolicy.class); @@ -57,7 +56,7 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { private String description = null; - private int[] version = null; + private int[] version = null; private boolean isRoot = false; @@ -81,7 +80,15 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { this.name = name; } - + /** + * StdPDPPolicy. + * + * @param id String + * @param isRoot boolean + * @param name String + * @param location URI + * @throws IOException IOException + */ public StdPDPPolicy(String id, boolean isRoot, String name, URI location) throws IOException { this(id, isRoot); this.name = name; @@ -97,11 +104,17 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { this.id = theID; } - logger.debug("The final outcome of the constructor returned the following: id = " + id + - ", location = " + location + ", name = " + name); + logger.debug("The final outcome of the constructor returned the following: id = " + id + ", location = " + + location + ", name = " + name); } + /** + * StdPDPPolicy constructor. + * + * @param stdPDPPolicyParams StdPDPPolicyParams + * @throws IOException IOException + */ public StdPDPPolicy(StdPDPPolicyParams stdPDPPolicyParams) throws IOException { this(stdPDPPolicyParams.getId(), stdPDPPolicyParams.isRoot()); this.name = stdPDPPolicyParams.getName(); @@ -111,23 +124,43 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { this.version = versionStringToArray(stdPDPPolicyParams.getVersion()); this.isValid = stdPDPPolicyParams.isValid(); - logger.debug("The final outcome of the constructor returned the following: id = " + stdPDPPolicyParams.getId() + - ", location = " + stdPDPPolicyParams.getLocation() + ", name = " + stdPDPPolicyParams.getName() + ", policyId = " + stdPDPPolicyParams.getPolicyId() + - ", description = " + stdPDPPolicyParams.getDescription() + ", Version = " + stdPDPPolicyParams.getVersion()); + logger.debug("The final outcome of the constructor returned the following: id = " + stdPDPPolicyParams.getId() + + ", location = " + stdPDPPolicyParams.getLocation() + ", name = " + stdPDPPolicyParams.getName() + + ", policyId = " + stdPDPPolicyParams.getPolicyId() + ", description = " + + stdPDPPolicyParams.getDescription() + ", Version = " + stdPDPPolicyParams.getVersion()); } + /** + * StdPDPPolicy. + * + * @param id String + * @param isRoot boolean + * @param name String + * @param location URI + * @param isFromAPI boolean + * @throws IOException IOException + */ public StdPDPPolicy(String id, boolean isRoot, String name, URI location, boolean isFromAPI) throws IOException { this(id, isRoot); this.name = name; this.location = location; this.isValid = isFromAPI; - logger.debug("The final outcome of the constructor returned the following: id = " + id + - ", location = " + location + ", name = " + name); + logger.debug("The final outcome of the constructor returned the following: id = " + id + ", location = " + + location + ", name = " + name); } + /** + * StdPDPPolicy. + * + * @param id String + * @param isRoot boolean + * @param location URI + * @param properties boolean + * @throws IOException IOException + */ public StdPDPPolicy(String id, boolean isRoot, URI location, Properties properties) throws IOException { this(id, isRoot); this.location = location; @@ -146,31 +179,26 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { } } - private String readPolicyData() throws IOException { // // Extract XACML policy information // URL url = this.location.toURL(); Object rootElement = XACMLPolicyScanner.readPolicy(url.openStream()); - if (rootElement == null || - ( - ! (rootElement instanceof PolicySetType) && - ! (rootElement instanceof PolicyType) - ) ) { + if (rootElement == null || (!(rootElement instanceof PolicySetType) && !(rootElement instanceof PolicyType))) { logger.warn("No root policy element in URI: " + this.location.toString() + " : " + rootElement); this.isValid = false; } else { this.version = versionStringToArray(XACMLPolicyScanner.getVersion(rootElement)); if (rootElement instanceof PolicySetType) { - this.policyId = ((PolicySetType)rootElement).getPolicySetId(); - this.description = ((PolicySetType)rootElement).getDescription(); + this.policyId = ((PolicySetType) rootElement).getPolicySetId(); + this.description = ((PolicySetType) rootElement).getDescription(); this.isValid = true; - this.version = versionStringToArray(((PolicySetType)rootElement).getVersion()); + this.version = versionStringToArray(((PolicySetType) rootElement).getVersion()); } else if (rootElement instanceof PolicyType) { - this.policyId = ((PolicyType)rootElement).getPolicyId(); - this.description = ((PolicyType)rootElement).getDescription(); - this.version = versionStringToArray(((PolicyType)rootElement).getVersion()); + this.policyId = ((PolicyType) rootElement).getPolicyId(); + this.description = ((PolicyType) rootElement).getDescription(); + this.version = versionStringToArray(((PolicyType) rootElement).getVersion()); this.isValid = true; } else { PolicyLogger.error("Unknown root element: " + rootElement.getClass().getCanonicalName()); @@ -230,8 +258,7 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { } @Override - public boolean isValid() - { + public boolean isValid() { return this.isValid; } @@ -259,8 +286,7 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((policyId == null) ? 0 : policyId.hashCode()); + result = prime * result + ((policyId == null) ? 0 : policyId.hashCode()); result = prime * result; if (version != null) { for (int i = 0; i < version.length; i++) { @@ -272,45 +298,50 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } StdPDPPolicy other = (StdPDPPolicy) obj; if (id == null) { - if (other.id != null) + if (other.id != null) { return false; - } else if (!id.equals(other.id)) + } + } else if (!id.equals(other.id)) { return false; + } if (policyId == null) { - if (other.policyId != null) + if (other.policyId != null) { return false; - } else if (!policyId.equals(other.policyId)) + } + } else if (!policyId.equals(other.policyId)) { return false; - if (version != other.version) + } + if (version != other.version) { return false; + } return true; } @Override public String toString() { - return "StdPDPPolicy [id=" + id + ", name=" + name + ", policyId=" - + policyId + ", description=" + description + ", version=" - + this.getVersion() + ", isRoot=" + isRoot + ", isValid=" + isValid - + ", location=" + location + "]"; + return "StdPDPPolicy [id=" + id + ", name=" + name + ", policyId=" + policyId + ", description=" + description + + ", version=" + this.getVersion() + ", isRoot=" + isRoot + ", isValid=" + isValid + ", location=" + + location + "]"; } - /** * Given a version string consisting of integers with dots between them, convert it into an array of ints. * - * @param version - * @return - * @throws NumberFormatException + * @param version String + * @return int array */ - public static int[] versionStringToArray(String version) throws NumberFormatException { + public static int[] versionStringToArray(String version) { if (version == null || version.length() == 0) { return new int[0]; } @@ -325,8 +356,8 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { /** * Given an array representing a version, create the corresponding dot-separated string. * - * @param array - * @return + * @param array int array + * @return String */ public static String versionArrayToString(int[] array) { if (array == null || array.length == 0) { @@ -345,18 +376,23 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { public void setPolicyId(String policyId) { this.policyId = policyId; } + public void setDescription(String description) { this.description = description; } + public void setVersion(String version) { this.version = versionStringToArray(version); } + public void setRoot(boolean isRoot) { this.isRoot = isRoot; } + public void setValid(boolean isValid) { this.isValid = isValid; } + public void setLocation(URI location) { this.location = location; }