Commit 6e561852 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-2028: invalid attributes in basic-search request should fail with status code 400

parent d1c585a2
......@@ -25,6 +25,7 @@ import org.apache.atlas.model.discovery.SearchParameters.FilterCriteria;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -67,6 +68,12 @@ public class SearchContext {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_CLASSIFICATION, searchParameters.getClassification());
}
// Invalid attributes will raise an exception with 400 error code
validateAttributes(entityType, searchParameters.getEntityFilters());
// Invalid attributes will raise an exception with 400 error code
validateAttributes(classificationType, searchParameters.getTagFilters());
if (needFullTextProcessor()) {
addProcessor(new FullTextSearchProcessor(this));
}
......@@ -131,6 +138,24 @@ public class SearchContext {
return entityType != null;
}
private void validateAttributes(final AtlasStructType structType, final FilterCriteria filterCriteria) throws AtlasBaseException {
if (filterCriteria != null) {
FilterCriteria.Condition condition = filterCriteria.getCondition();
if (condition != null && CollectionUtils.isNotEmpty(filterCriteria.getCriterion())) {
for (FilterCriteria criteria : filterCriteria.getCriterion()) {
validateAttributes(structType, criteria);
}
} else {
String attributeName = filterCriteria.getAttributeName();
if (StringUtils.isNotEmpty(attributeName) && structType.getAttributeType(attributeName) == null) {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attributeName, structType.getTypeName());
}
}
}
}
private boolean hasAttributeFilter(FilterCriteria filterCriteria) {
return filterCriteria != null &&
(CollectionUtils.isNotEmpty(filterCriteria.getCriterion()) || StringUtils.isNotEmpty(filterCriteria.getAttributeName()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment