Skip to content
Snippets Groups Projects
Commit 017b6d86 authored by Morris Estepa's avatar Morris Estepa
Browse files

Throw an error if the partition in search request kind is not * and not equal...

Throw an error if the partition in search request kind is not * and not equal to the header partition id
parent 674d983c
No related branches found
No related tags found
Loading
package org.opengroup.osdu.search.provider.aws.util;
import org.opengroup.osdu.core.common.exception.BadRequestException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.search.util.CrossTenantUtils;
import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver;
......@@ -18,14 +19,22 @@ public class AwsCrossTenantUtils extends CrossTenantUtils {
@Inject
private ElasticIndexNameResolver elasticIndexNameResolver;
// This override method forces the kind used in the index search to use the same partition id as
// the request's partition id header. This is to prevent data from other tenants (aka. partition)
// to appear when searching data in a given tenant.
@Override
public String getIndexName(Query searchRequest) {
public String getIndexName(Query searchRequest) throws BadRequestException {
StringBuilder builder = new StringBuilder();
List<String> kinds = KindParser.parse(searchRequest.getKind());
for(String kind : kinds) {
String index = this.elasticIndexNameResolver.getIndexNameFromKind(kind);
String[] indexArr = index.split("-");
indexArr[0] = dpsHeaders.getPartitionId();
if (indexArr[0] == "*") {
indexArr[0] = dpsHeaders.getPartitionId();
}
else if (indexArr[0].equalsIgnoreCase(dpsHeaders.getPartitionId()) == false) {
throw new BadRequestException("Invalid kind in search request.");
}
builder.append(String.join("-", indexArr) + ",");
}
builder.append("-.*"); // Exclude Lucene/ElasticSearch internal indices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment