Skip to content

Commit

Permalink
added auditrepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mehtaanshul committed Nov 25, 2023
1 parent d0297c9 commit 65885c6
Showing 1 changed file with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.atlas.RequestContext;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.audit.AuditSearchParams;
import org.apache.atlas.model.audit.EntityAuditSearchResult;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.discovery.IndexSearchParams;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.plugin.model.RangerRole;
import org.apache.atlas.plugin.util.RangerRoles;
import org.apache.atlas.plugin.util.RangerUserStore;
import org.apache.atlas.repository.audit.ESBasedAuditRepository;
import org.apache.atlas.utils.AtlasPerfMetrics;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import static org.apache.atlas.repository.Constants.*;
Expand All @@ -27,6 +31,8 @@ public class AtlasAuthorization {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorization.class);

private EntityDiscoveryService discoveryService;
private ESBasedAuditRepository auditRepository;

private static AtlasAuthorization atlasAuthorization;
private static UsersGroupsRolesStore usersGroupsRolesStore;
private List<AtlasEntityHeader> allPolicies;
Expand All @@ -52,6 +58,8 @@ public static AtlasAuthorization getInstance() {
public AtlasAuthorization (EntityDiscoveryService discoveryService) {
try {
this.discoveryService = discoveryService;
auditRepository = null;

this.usersGroupsRolesStore = UsersGroupsRolesStore.getInstance();

serviceNames.add("atlas");
Expand Down Expand Up @@ -367,38 +375,6 @@ private List<AtlasEntityHeader> getPolicies(){
return ret;
}

// private boolean isPolicyUpdated() {
// List<String> entityUpdateToWatch = new ArrayList<>();
// entityUpdateToWatch.add(POLICY_ENTITY_TYPE);
// entityUpdateToWatch.add(PERSONA_ENTITY_TYPE);
// entityUpdateToWatch.add(PURPOSE_ENTITY_TYPE);
//
// AuditSearchParams parameters = new AuditSearchParams();
// Map<String, Object> dsl = getMap("size", 1);
//
// List<Map<String, Object>> mustClauseList = new ArrayList<>();
// mustClauseList.add(getMap("terms", getMap("typeName", entityUpdateToWatch)));
//
// lastUpdatedTime = lastUpdatedTime == -1 ? 0 : lastUpdatedTime;
// mustClauseList.add(getMap("range", getMap("timestamp", getMap("gte", lastUpdatedTime))));
//
// dsl.put("query", getMap("bool", getMap("must", mustClauseList)));
//
// parameters.setDsl(dsl);
//
// try {
// EntityAuditSearchResult result = auditRepository.searchEvents(parameters.getQueryString());
//
// if (result == null || CollectionUtils.isEmpty(result.getEntityAudits())) {
// return false;
// }
// } catch (AtlasBaseException e) {
// LOG.error("ERROR in getPoliciesIfUpdated while fetching entity audits {}: ", e.getMessage());
// return true;
// }
// return true;
// }

private List<String> getPolicyFilterCriteriaArray(List<AtlasEntityHeader> entityHeaders) {
AtlasPerfMetrics.MetricRecorder getPolicyFilterCriteriaArrayMetrics = RequestContext.get().startMetricRecord("getPolicyFilterCriteriaArray");
List<String> policyFilterCriteriaArray = new ArrayList<>();
Expand Down Expand Up @@ -432,6 +408,38 @@ private List<String> getPolicyDSLArray(List<String> policyFilterCriteriaArray) {
return policyDSLArray;
}

private boolean isPolicyUpdated() {
List<String> entityUpdateToWatch = new ArrayList<>();
entityUpdateToWatch.add(POLICY_ENTITY_TYPE);
entityUpdateToWatch.add(PERSONA_ENTITY_TYPE);
entityUpdateToWatch.add(PURPOSE_ENTITY_TYPE);

AuditSearchParams parameters = new AuditSearchParams();
Map<String, Object> dsl = getMap("size", 1);

List<Map<String, Object>> mustClauseList = new ArrayList<>();
mustClauseList.add(getMap("terms", getMap("typeName", entityUpdateToWatch)));

lastUpdatedTime = lastUpdatedTime == -1 ? 0 : lastUpdatedTime;
mustClauseList.add(getMap("range", getMap("timestamp", getMap("gte", lastUpdatedTime))));

dsl.put("query", getMap("bool", getMap("must", mustClauseList)));

parameters.setDsl(dsl);

try {
EntityAuditSearchResult result = auditRepository.searchEvents(parameters.getQueryString());

if (result == null || CollectionUtils.isEmpty(result.getEntityAudits())) {
return false;
}
} catch (AtlasBaseException e) {
LOG.error("ERROR in getPoliciesIfUpdated while fetching entity audits {}: ", e.getMessage());
return true;
}
return true;
}

// private List<AtlasEntityHeader> getRelevantPolicies(String user, String action) throws AtlasBaseException {
// AtlasPerfMetrics.MetricRecorder getRelevantPoliciesMetrics = RequestContext.get().startMetricRecord("getRelevantPolicies");
// List<AtlasEntityHeader> ret = new ArrayList<>();
Expand Down

0 comments on commit 65885c6

Please sign in to comment.