Merge "Adding PolicyType to getConfig Response"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / elk / client / ElkConnectorImpl.java
index 8868db3..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" +
@@ -322,6 +333,7 @@ public class ElkConnectorImpl implements ElkConnector{
                        String[] splitPolicyName = policyName.split(":");
                        indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]);
                } catch (IllegalArgumentException e) {
+                       LOGGER.error(e);
                        throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage());                    
                }
                PolicyElasticData elasticData = new PolicyElasticData(policyData);