import javax.json.Json;
import javax.json.JsonReader;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
import org.apache.commons.io.FilenameUtils;
import org.json.JSONObject;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.rest.XACMLRestProperties;
import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
import org.openecomp.policy.xacml.util.XACMLPolicyWriter;
import com.att.research.xacmlatt.pdp.policy.PolicyDef;
import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
+
public abstract class Policy {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(Policy.class);
+
/**
* Common Fields
public static final String FUNCTION_BOOLEAN_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only";
public static final String FUNCTION_STRING_EQUAL = "urn:oasis:names:tc:xacml:1.0:function:string-equal";
public static final String FUNCTION_STRING_REGEX_MATCH = "org.openecomp.function.regex-match";
+ public static final String FUNCTION_STRING_REGEXP_MATCH = "urn:oasis:names:tc:xacml:1.0:function:string-regexp-match";
public static final String FUNCTION_STRING_EQUAL_IGNORE = "urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case";
public static final String INTEGER_DATATYPE = "http://www.w3.org/2001/XMLSchema#integer";
public static final String BOOLEAN_DATATYPE = "http://www.w3.org/2001/XMLSchema#boolean";
public static String ACTION_HOME = null;
public static String CONFIG_URL = null;
- protected Map<String, String> performer = new HashMap<String, String>();
+ protected Map<String, String> performer = new HashMap<>();
private static String actionHome = null;
private static String configHome = null;
try {
uri = new URI(key);
} catch (URISyntaxException e) {
- e.printStackTrace();
+ LOGGER.error("Exception Occured"+e);
}
attributeDesignator.setCategory(CATEGORY_ACCESS_SUBJECT);
attributeDesignator.setDataType(STRING_DATATYPE);
try {
dynamicURI = new URI(key);
} catch (URISyntaxException e) {
- e.printStackTrace();// log msg
+ LOGGER.error("Exception Occured"+e);// log msg
}
dynamicAttributeDesignator.setCategory(CATEGORY_RESOURCE);
dynamicAttributeDesignator.setDataType(dataType);
// Validation for json.
protected static boolean isJSONValid(String data) {
+ JsonReader jsonReader = null;
try {
new JSONObject(data);
InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
- JsonReader jsonReader = Json.createReader(stream);
- System.out.println("Json Value is: " + jsonReader.read().toString() );
+ jsonReader = Json.createReader(stream);
+ LOGGER.info("Json Value is: " + jsonReader.read().toString() );
} catch (Exception e) {
+ LOGGER.error("Exception Occured while reading json"+e);
return false;
+ }finally{
+ if(jsonReader != null){
+ jsonReader.close();
+ }
}
return true;
}
//create policy once all the validations are completed
protected Map<String, String> createPolicy(final Path policyPath, final Object policyData) {
- Map<String, String> success = new HashMap<String, String>();
+ Map<String, String> success = new HashMap<>();
//
// Is the root a PolicySet or Policy?
//
//
//Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
//and this transaction is intercepted up stream.
- InputStream inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData);
+ InputStream inputStream = null;
try {
+ inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData);
PolicyDef policyDef = DOMPolicyDef.load(inputStream);
if (policyDef == null) {
success.put("validation", "PolicyDef Validation Failed");
success.put("success", "success");
}
} catch (Exception e) {
+ LOGGER.error("PolicyDef Validation failed"+e);
success.put("error", "Validation Failed");
+ }finally{
+ try {
+ if(inputStream != null)
+ inputStream.close();
+ } catch (IOException e) {
+ LOGGER.error("Exception Occured while closing the input stream"+e);
+ }
}
} else {
PolicyLogger.error("Unknown data type sent back.");
configHome = webappsPathConfig.toString();
}
}
-
- protected String getParentPathSubScopeDir() {
- final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString());
- String policyDir = policyAdapter.getParentPath().toString();
- int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1;
- policyDir = policyDir.substring(startIndex, policyDir.length());
- return policyDir;
- }
-
-
+
public boolean validateConfigForm() {
return true;
}