Policy Elastic Search Validation Enhancements
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / elk / client / ElkConnectorImpl.java
index 88f9e2c..9091d79 100644 (file)
@@ -101,6 +101,9 @@ public class ElkConnectorImpl implements ElkConnector{
                        throw e;
                }
        }
+       private boolean isAlphaNumeric(String query){
+               return query.matches("[a-zA-Z_0-9]+");
+       }
 
        @Override
        public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException {
@@ -112,6 +115,10 @@ public class ElkConnectorImpl implements ElkConnector{
                        throw new IllegalArgumentException("No search string provided");
                }
 
+               if(!isAlphaNumeric(text)){
+                       throw new IllegalArgumentException("Search must be alpha numeric");
+               }
+
                QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*"+text+"*");
                SearchSourceBuilder searchSourceBuilder = 
                                new SearchSourceBuilder().query(mQ);
@@ -198,6 +205,10 @@ public class ElkConnectorImpl implements ElkConnector{
                        return search(type, text);
                }
 
+               if(!isAlphaNumeric(text)){
+                       throw new IllegalArgumentException("Search must be alpha numeric");
+               }
+
                String matches_s = "";
                matches_s = "{\n" +
                                "    \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" +