Commit 3b6bdb82 authored by Alok Joshi's avatar Alok Joshi
Browse files

minor changes acc to MR comments

parent 6d58808d
Pipeline #36034 failed with stages
in 28 minutes and 5 seconds
......@@ -128,31 +128,31 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled (QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -129,31 +129,31 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled (QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -107,33 +107,31 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled(QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if(groups != null){
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
}
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
AclRole.OWNERS.getPath(), groupArray));
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -133,16 +133,19 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled(QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder;
// apply authorization filters
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
......@@ -150,13 +153,11 @@ abstract class QueryBase {
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -119,16 +119,19 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled(QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder;
// apply authorization filters
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
......@@ -136,14 +139,11 @@ abstract class QueryBase {
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -145,16 +145,19 @@ abstract class QueryBase {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(spatialQueryBuilder) : boolQuery().must(spatialQueryBuilder);
}
return modifyQueryIfPolicyEnabled(queryBuilder, asOwner);
}
private QueryBuilder modifyQueryIfPolicyEnabled(QueryBuilder queryBuilder, boolean asOwner) {
if(this.iPolicyService != null && this.statusService.policyEnabled(this.dpsHeaders.getPartitionId())) {
return queryBuilder;
} else {
QueryBuilder authorizationQueryBuilder;
// apply authorization filters
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
return getQueryBuilderWithAuthorization(queryBuilder, asOwner);
}
}
private QueryBuilder getQueryBuilderWithAuthorization(QueryBuilder queryBuilder, boolean asOwner) {
QueryBuilder authorizationQueryBuilder = null;
// apply authorization filters
//bypass for BYOC implementation only.
String groups = dpsHeaders.getHeaders().get(providerHeaderService.getDataGroupsHeader());
if (groups != null) {
String[] groupArray = groups.trim().split("\\s*,\\s*");
if (asOwner) {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(
......@@ -162,12 +165,11 @@ abstract class QueryBase {
} else {
authorizationQueryBuilder = boolQuery().minimumShouldMatch("1").should(termsQuery(RecordMetaAttribute.X_ACL.getValue(), groupArray));
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
if (authorizationQueryBuilder != null) {
queryBuilder = queryBuilder != null ? boolQuery().must(queryBuilder).must(authorizationQueryBuilder) : boolQuery().must(authorizationQueryBuilder);
}
return queryBuilder;
}
private QueryBuilder getSimpleQuery(String searchQuery) {
......
......@@ -49,11 +49,10 @@ public class QueryResponseUtil {
public List<Map<String, Object>> getQueryResponseResults(List<Map<String, Object>> results) {
if(isPolicyEnabled()) {
if(requiredFieldsArePresent(results)) {
if(checkIfRequiredFieldsArePresent(results)) {
List<RecordMetadata> policyMetadataList = getRecordMetadataListForPolicyEvaluation(results);
List<String> policyEvaluatedRecords = iPolicyService.evaluateSearchDataAuthorizationPolicy(policyMetadataList, OperationType.view);
List<Map<String, Object>> authorizedResults = processAuthorizedResults(results, policyEvaluatedRecords);
return authorizedResults;
return processAuthorizedResults(results, policyEvaluatedRecords);
} else {
throw new AppException(HttpServletResponse.SC_BAD_REQUEST, "Bad Request", "Returned fields must have acl, kind, legal and id");
}
......@@ -62,7 +61,7 @@ public class QueryResponseUtil {
}
}
private boolean requiredFieldsArePresent(List<Map<String, Object>> results) {
private boolean checkIfRequiredFieldsArePresent(List<Map<String, Object>> results) {
for(Map<String, Object> result : results) {
if(!result.containsKey(RecordMetaAttribute.ACL.getValue())
|| !result.containsKey(RecordMetaAttribute.KIND.getValue())
......
Supports Markdown
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