diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java index 960ec3808e..912799cdd6 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java @@ -25,7 +25,6 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.instance.AtlasEntityHeader; -import org.apache.atlas.model.instance.AtlasEntityHeaders; import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasHasLineageRequests; import org.apache.atlas.model.instance.EntityMutationResponse; @@ -364,4 +363,6 @@ EntityMutationResponse deleteByUniqueAttributes(List objectIds) void repairMeaningAttributeForTerms(List termGuids) throws AtlasBaseException; + void repairAccesscontrolAlias(String guid) throws AtlasBaseException; + } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 2d6d28c0a7..83df0fe2ef 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -49,6 +49,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.patches.PatchContext; import org.apache.atlas.repository.patches.ReIndexPatch; +import org.apache.atlas.repository.store.aliasstore.ESAliasStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.AtlasRelationshipStore; import org.apache.atlas.repository.store.graph.EntityGraphDiscovery; @@ -115,6 +116,7 @@ import static org.apache.atlas.repository.graph.GraphHelper.getStatus; import static org.apache.atlas.repository.store.graph.v2.EntityGraphMapper.validateLabels; import static org.apache.atlas.repository.store.graph.v2.tasks.MeaningsTaskFactory.*; +import static org.apache.atlas.repository.util.AccessControlUtils.REL_ATTR_POLICIES; import static org.apache.atlas.type.Constants.HAS_LINEAGE; import static org.apache.atlas.type.Constants.HAS_LINEAGE_VALID; import static org.apache.atlas.type.Constants.MEANINGS_TEXT_PROPERTY_KEY; @@ -147,6 +149,8 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { private final AtlasRelationshipStore atlasRelationshipStore; private final FeatureFlagStore featureFlagStore; + private final ESAliasStore esAliasStore; + @Inject public AtlasEntityStoreV2(AtlasGraph graph, DeleteHandlerDelegate deleteDelegate, RestoreHandlerV1 restoreHandlerV1, AtlasTypeRegistry typeRegistry, IAtlasEntityChangeNotifier entityChangeNotifier, EntityGraphMapper entityGraphMapper, TaskManagement taskManagement, @@ -163,6 +167,7 @@ public AtlasEntityStoreV2(AtlasGraph graph, DeleteHandlerDelegate deleteDelegate this.taskManagement = taskManagement; this.atlasRelationshipStore = atlasRelationshipStore; this.featureFlagStore = featureFlagStore; + this.esAliasStore = new ESAliasStore(graph, entityRetriever); try { this.discovery = new EntityDiscoveryService(typeRegistry, graph, null, null, null, null); @@ -2703,6 +2708,35 @@ private void repairMeanings(AtlasVertex assetVertex) { } } + @Override + public void repairAccesscontrolAlias(String guid) throws AtlasBaseException { + AtlasPerfMetrics.MetricRecorder metric = RequestContext.get().startMetricRecord("repairAlias"); + // Fetch accesscontrolEntity with extInfo + AtlasEntity.AtlasEntityWithExtInfo accesscontrolEntity = entityRetriever.toAtlasEntityWithExtInfo(guid); + + AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(accesscontrolEntity.getEntity()))); + + // Validate accesscontrolEntity status + if (accesscontrolEntity.getEntity().getStatus() != ACTIVE) { + throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, guid); + } + + // Validate accesscontrolEntity type + String entityType = accesscontrolEntity.getEntity().getTypeName(); + if (!PERSONA_ENTITY_TYPE.equals(entityType)) { + throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, entityType); + } + + List policies = (List) accesscontrolEntity.getEntity().getRelationshipAttribute(REL_ATTR_POLICIES); + for (AtlasObjectId policy : policies) { + accesscontrolEntity.addReferredEntity(entityRetriever.toAtlasEntity(policy)); + } + + // Rebuild alias + this.esAliasStore.updateAlias(accesscontrolEntity, null); + + RequestContext.get().endMetricRecord(metric); + } } diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java index 0ebb48b16c..3aadc06ad2 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java @@ -1930,4 +1930,29 @@ public void repairIndexByTypeName(@PathParam("typename") String typename, @Query AtlasPerfTracer.log(perf); } } + + @POST + @Path("/repair/accesscontrolAlias/{guid}") + @Timed + public void repairAccessControlAlias(@PathParam("guid") String guid) throws AtlasBaseException { + Servlets.validateQueryParamLength("guid", guid); + + AtlasPerfTracer perf = null; + + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.repairAccessControlAlias"); + } + + entitiesStore.repairAccesscontrolAlias(guid); + + LOG.info("Repaired access control alias for entity with guid {}", guid); + + } finally { + AtlasPerfTracer.log(perf); + } + + + } }