New Optimization Policy
[policy/engine.git] / PolicyEngineUtils / src / main / java / org / onap / policy / utils / PolicyUtils.java
index c058a79..0626385 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * PolicyEngineUtils
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.xml.XMLConstants;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
@@ -156,6 +157,21 @@ public class PolicyUtils {
         return SUCCESS;   
     } 
     
+    /**
+     * Validate a field (accepts Dash) if it contains unacceptable policy input and return "success" if good. 
+     * 
+     * @param field
+     * @return
+     */
+    public static String  policySpecialCharWithDashValidator(String field){
+        String error;
+        if ("".equals(field) || !field.matches("^[a-zA-Z0-9_-]*$")) {
+            error = "The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}, _, -' following set of Combinations";
+            return error;
+        }
+        return SUCCESS;   
+    } 
+    
     /**
      * Validate the XACML description tag and return "success" if good. 
      * 
@@ -194,7 +210,9 @@ public class PolicyUtils {
             return false;
         }
         for (char c : number.toCharArray()){
-            if (!Character.isDigit(c)) return false;
+            if (!Character.isDigit(c)) {
+               return false;
+            }
         }
         return true;
     }
@@ -282,7 +300,9 @@ public class PolicyUtils {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setValidating(false);
         factory.setNamespaceAware(true);
-        try {
+        
+        try {    
+                       factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);               
             SAXParser parser = factory.newSAXParser();
             XMLReader reader = parser.getXMLReader();
             reader.setErrorHandler(new XMLErrorHandler());