Commit 16ced369 by sidmishra Committed by Madhan Neethiraj

ATLAS-3877: fix for error in retrieving audit for purged entity

parent d604085e
......@@ -108,7 +108,13 @@ public abstract class DeleteHandlerV1 {
// Record all deletion candidate entities in RequestContext
// and gather deletion candidate vertices.
for (GraphHelper.VertexInfo vertexInfo : getOwnedVertices(instanceVertex)) {
requestContext.recordEntityDelete(vertexInfo.getEntity());
AtlasEntityHeader entityHeader = vertexInfo.getEntity();
if (requestContext.isPurgeRequested()) {
entityHeader.setClassifications(entityRetriever.getAllClassifications(vertexInfo.getVertex()));
}
requestContext.recordEntityDelete(entityHeader);
deletionCandidateVertices.add(vertexInfo.getVertex());
}
}
......
......@@ -177,7 +177,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
EntityGraphRetriever entityRetriever = new EntityGraphRetriever(graph, typeRegistry);
AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeader(guid);
AtlasEntityHeader ret = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
......
......@@ -21,6 +21,9 @@ import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
import org.apache.atlas.authorize.AtlasEntityAccessRequest;
import org.apache.atlas.authorize.AtlasPrivilege;
import org.apache.atlas.bulkimport.BulkImportResponse;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
......@@ -806,8 +809,18 @@ public class EntityREST {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")");
}
// following call enforces authorization for entity-read
entitiesStore.getHeaderById(guid);
// Enforces authorization for entity-read
try {
entitiesStore.getHeaderById(guid);
} catch (AtlasBaseException e) {
if (e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND) {
AtlasEntityHeader entityHeader = getEntityHeaderFromPurgedAudit(guid);
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, entityHeader), "read entity audit: guid=", guid);
} else {
throw e;
}
}
List<EntityAuditEventV2> ret = new ArrayList<>();
......@@ -1232,4 +1245,15 @@ public class EntityREST {
return entitiesStore.bulkCreateOrUpdateBusinessAttributes(uploadedInputStream, fileDetail.getFileName());
}
private AtlasEntityHeader getEntityHeaderFromPurgedAudit(String guid) throws AtlasBaseException {
List<EntityAuditEventV2> auditEvents = auditRepository.listEventsV2(guid, EntityAuditActionV2.ENTITY_PURGE, null, (short)1);
AtlasEntityHeader ret = CollectionUtils.isNotEmpty(auditEvents) ? auditEvents.get(0).getEntityHeader() : null;
if (ret == null) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
}
return ret;
}
}
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