From 6f62763565574cabd0c12fd262e30c14b8192ff7 Mon Sep 17 00:00:00 2001 From: neojunjie Date: Tue, 28 Jun 2022 00:30:25 +0800 Subject: [PATCH 1/8] add audit actor --- metadata-service/openapi-servlet/build.gradle | 1 + .../openapi/util/MappingUtil.java | 11 ++++++++--- .../restli-servlet-impl/build.gradle | 1 + .../resources/entity/EntityResource.java | 18 ++++++++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/metadata-service/openapi-servlet/build.gradle b/metadata-service/openapi-servlet/build.gradle index f5cdfe42cbff6..08f019bed70fb 100644 --- a/metadata-service/openapi-servlet/build.gradle +++ b/metadata-service/openapi-servlet/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'java' dependencies { + compile project(':metadata-service:auth-api') compile project(':metadata-service:factories') compile externalDependency.reflections diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java index 8d07196535322..2db1a0e298b0f 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java @@ -2,6 +2,8 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -14,7 +16,6 @@ import com.linkedin.data.template.RecordTemplate; import com.linkedin.entity.Aspect; import com.linkedin.events.metadata.ChangeType; -import com.linkedin.metadata.Constants; import com.linkedin.metadata.entity.EntityService; import com.linkedin.metadata.entity.RollbackRunResult; import com.linkedin.metadata.entity.ValidationException; @@ -248,11 +249,15 @@ public static GenericAspect convertGenericAspect(@Nonnull io.datahubproject.open public static Pair ingestProposal(MetadataChangeProposal metadataChangeProposal, EntityService entityService, ObjectMapper objectMapper) { - // TODO: Use the actor present in the IC. + Timer.Context context = MetricUtils.timer("postEntity").time(); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + // Getting actor from AuthenticationContext + log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); final com.linkedin.common.AuditStamp auditStamp = new com.linkedin.common.AuditStamp().setTime(System.currentTimeMillis()) - .setActor(UrnUtils.getUrn(Constants.UNKNOWN_ACTOR)); + .setActor(UrnUtils.getUrn(actorUrnStr)); io.datahubproject.openapi.generated.KafkaAuditHeader auditHeader = metadataChangeProposal.getAuditHeader(); com.linkedin.mxe.MetadataChangeProposal serviceProposal = diff --git a/metadata-service/restli-servlet-impl/build.gradle b/metadata-service/restli-servlet-impl/build.gradle index eafe43f74e8e3..0d66373e8c127 100644 --- a/metadata-service/restli-servlet-impl/build.gradle +++ b/metadata-service/restli-servlet-impl/build.gradle @@ -33,6 +33,7 @@ dependencies { } compile project(':metadata-service:restli-api') + compile project(':metadata-service:auth-api') compile project(path: ':metadata-service:restli-api', configuration: 'dataTemplate') compile project(':li-utils') compile project(':metadata-models') diff --git a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java index 2c6489e322b3a..e1a43ff4ec338 100644 --- a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java +++ b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java @@ -1,13 +1,14 @@ package com.linkedin.metadata.resources.entity; import com.codahale.metrics.MetricRegistry; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.linkedin.common.AuditStamp; import com.linkedin.common.UrnArray; import com.linkedin.common.urn.Urn; import com.linkedin.data.template.LongMap; import com.linkedin.data.template.StringArray; import com.linkedin.entity.Entity; -import com.linkedin.metadata.Constants; import com.linkedin.metadata.browse.BrowseResult; import com.linkedin.metadata.entity.DeleteEntityService; import com.linkedin.metadata.entity.EntityService; @@ -193,9 +194,11 @@ public Task ingest(@ActionParam(PARAM_ENTITY) @Nonnull Entity entity, SystemMetadata systemMetadata = populateDefaultFieldsIfEmpty(providedSystemMetadata); - // TODO Correctly audit ingestions. - final AuditStamp auditStamp = - new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR)); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + // Getting actor from AuthenticationContext + log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); + final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr)); // variables referenced in lambdas are required to be final final SystemMetadata finalSystemMetadata = systemMetadata; @@ -219,8 +222,11 @@ public Task batchIngest(@ActionParam(PARAM_ENTITIES) @Nonnull Entity[] ent } } - final AuditStamp auditStamp = - new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR)); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + // Getting actor from AuthenticationContext + log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); + final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr)); if (systemMetadataList == null) { systemMetadataList = new SystemMetadata[entities.length]; From 0ae7249214c3708d1763c133eddd6df099889e04 Mon Sep 17 00:00:00 2001 From: neojunjie Date: Tue, 28 Jun 2022 02:04:24 +0800 Subject: [PATCH 2/8] revert openapi --- metadata-service/openapi-servlet/build.gradle | 1 - .../io/datahubproject/openapi/util/MappingUtil.java | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/metadata-service/openapi-servlet/build.gradle b/metadata-service/openapi-servlet/build.gradle index 08f019bed70fb..f5cdfe42cbff6 100644 --- a/metadata-service/openapi-servlet/build.gradle +++ b/metadata-service/openapi-servlet/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'java' dependencies { - compile project(':metadata-service:auth-api') compile project(':metadata-service:factories') compile externalDependency.reflections diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java index 2db1a0e298b0f..8d07196535322 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java @@ -2,8 +2,6 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; -import com.datahub.authentication.Authentication; -import com.datahub.authentication.AuthenticationContext; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -16,6 +14,7 @@ import com.linkedin.data.template.RecordTemplate; import com.linkedin.entity.Aspect; import com.linkedin.events.metadata.ChangeType; +import com.linkedin.metadata.Constants; import com.linkedin.metadata.entity.EntityService; import com.linkedin.metadata.entity.RollbackRunResult; import com.linkedin.metadata.entity.ValidationException; @@ -249,15 +248,11 @@ public static GenericAspect convertGenericAspect(@Nonnull io.datahubproject.open public static Pair ingestProposal(MetadataChangeProposal metadataChangeProposal, EntityService entityService, ObjectMapper objectMapper) { - + // TODO: Use the actor present in the IC. Timer.Context context = MetricUtils.timer("postEntity").time(); - Authentication authentication = AuthenticationContext.getAuthentication(); - String actorUrnStr = authentication.getActor().toUrnStr(); - // Getting actor from AuthenticationContext - log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); final com.linkedin.common.AuditStamp auditStamp = new com.linkedin.common.AuditStamp().setTime(System.currentTimeMillis()) - .setActor(UrnUtils.getUrn(actorUrnStr)); + .setActor(UrnUtils.getUrn(Constants.UNKNOWN_ACTOR)); io.datahubproject.openapi.generated.KafkaAuditHeader auditHeader = metadataChangeProposal.getAuditHeader(); com.linkedin.mxe.MetadataChangeProposal serviceProposal = From 5fa001c558a66e6159bf24aa2d960d783bac7411 Mon Sep 17 00:00:00 2001 From: neojunjie Date: Tue, 28 Jun 2022 07:30:12 +0800 Subject: [PATCH 3/8] added audit actor for AspectResource and removed debug --- .../metadata/resources/entity/AspectResource.java | 10 ++++++---- .../metadata/resources/entity/EntityResource.java | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/AspectResource.java b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/AspectResource.java index 3305f48b5c044..e65269d244eb2 100644 --- a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/AspectResource.java +++ b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/AspectResource.java @@ -1,10 +1,11 @@ package com.linkedin.metadata.resources.entity; import com.codahale.metrics.MetricRegistry; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.linkedin.aspect.GetTimeseriesAspectValuesResponse; import com.linkedin.common.AuditStamp; import com.linkedin.common.urn.Urn; -import com.linkedin.metadata.Constants; import com.linkedin.metadata.aspect.EnvelopedAspectArray; import com.linkedin.metadata.aspect.VersionedAspect; import com.linkedin.metadata.entity.EntityService; @@ -124,9 +125,10 @@ public Task ingestProposal( @ActionParam(PARAM_PROPOSAL) @Nonnull MetadataChangeProposal metadataChangeProposal) throws URISyntaxException { log.info("INGEST PROPOSAL proposal: {}", metadataChangeProposal); - // TODO: Use the actor present in the IC. - final AuditStamp auditStamp = - new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR)); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr)); + final List additionalChanges = AspectUtils.getAdditionalChanges(metadataChangeProposal, _entityService); diff --git a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java index e1a43ff4ec338..b7400d99eb5fc 100644 --- a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java +++ b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java @@ -196,8 +196,6 @@ public Task ingest(@ActionParam(PARAM_ENTITY) @Nonnull Entity entity, Authentication authentication = AuthenticationContext.getAuthentication(); String actorUrnStr = authentication.getActor().toUrnStr(); - // Getting actor from AuthenticationContext - log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr)); // variables referenced in lambdas are required to be final From 37a4639489f3668b5fa8a51aaee3d3358710364a Mon Sep 17 00:00:00 2001 From: John Joyce Date: Mon, 27 Jun 2022 18:27:48 -0700 Subject: [PATCH 4/8] Update EntityResource.java --- .../com/linkedin/metadata/resources/entity/EntityResource.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java index aa8161c3c59d3..714092bd40152 100644 --- a/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java +++ b/metadata-service/restli-servlet-impl/src/main/java/com/linkedin/metadata/resources/entity/EntityResource.java @@ -222,8 +222,6 @@ public Task batchIngest(@ActionParam(PARAM_ENTITIES) @Nonnull Entity[] ent Authentication authentication = AuthenticationContext.getAuthentication(); String actorUrnStr = authentication.getActor().toUrnStr(); - // Getting actor from AuthenticationContext - log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr)); final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr)); if (systemMetadataList == null) { From 5d99c173c13c33dc6cd11a855aa58f43b281ffd8 Mon Sep 17 00:00:00 2001 From: neojunjie Date: Tue, 28 Jun 2022 17:33:46 +0800 Subject: [PATCH 5/8] audit trail for open api --- metadata-service/openapi-servlet/build.gradle | 1 + .../openapi/entities/EntitiesController.java | 13 +++++++++++-- .../entities/PlatformEntitiesController.java | 7 ++++++- .../io/datahubproject/openapi/util/MappingUtil.java | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/metadata-service/openapi-servlet/build.gradle b/metadata-service/openapi-servlet/build.gradle index f5cdfe42cbff6..1b4621bf63949 100644 --- a/metadata-service/openapi-servlet/build.gradle +++ b/metadata-service/openapi-servlet/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'java' dependencies { compile project(':metadata-service:factories') + compile project(':metadata-service:auth-api') compile externalDependency.reflections compile externalDependency.springBoot diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/entities/EntitiesController.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/entities/EntitiesController.java index fd73553e0e58c..2209180bb47e6 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/entities/EntitiesController.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/entities/EntitiesController.java @@ -2,6 +2,8 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.fasterxml.jackson.databind.ObjectMapper; import com.linkedin.common.urn.Urn; import com.linkedin.common.urn.UrnUtils; @@ -104,9 +106,12 @@ public ResponseEntity> postEntities( @RequestBody @Nonnull List aspectRequests) { log.info("INGEST PROPOSAL proposal: {}", aspectRequests); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + List> responses = aspectRequests.stream() .map(MappingUtil::mapToProposal) - .map(proposal -> MappingUtil.ingestProposal(proposal, _entityService, _objectMapper)) + .map(proposal -> MappingUtil.ingestProposal(proposal, actorUrnStr, _entityService, _objectMapper)) .collect(Collectors.toList()); if (responses.stream().anyMatch(Pair::getSecond)) { return ResponseEntity.status(HttpStatus.CREATED) @@ -140,10 +145,14 @@ public ResponseEntity> deleteEntities( List deleteRequests = entityUrns.stream() .map(entityUrn -> MappingUtil.createStatusRemoval(entityUrn, _entityService)) .collect(Collectors.toList()); + + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + return ResponseEntity.ok(Collections.singletonList(RollbackRunResultDto.builder() .rowsRolledBack(deleteRequests.stream() .map(MappingUtil::mapToProposal) - .map(proposal -> MappingUtil.ingestProposal(proposal, _entityService, _objectMapper)) + .map(proposal -> MappingUtil.ingestProposal(proposal, actorUrnStr, _entityService, _objectMapper)) .filter(Pair::getSecond) .map(Pair::getFirst) .map(urnString -> new AspectRowSummary().urn(urnString)) diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/platform/entities/PlatformEntitiesController.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/platform/entities/PlatformEntitiesController.java index 0d7ed888c8f8b..5f968a56ee215 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/platform/entities/PlatformEntitiesController.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/platform/entities/PlatformEntitiesController.java @@ -1,5 +1,7 @@ package io.datahubproject.openapi.platform.entities; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.fasterxml.jackson.databind.ObjectMapper; import com.linkedin.metadata.entity.EntityService; import com.linkedin.util.Pair; @@ -44,8 +46,11 @@ public ResponseEntity> postEntities( @RequestBody @Nonnull List metadataChangeProposals) { log.info("INGEST PROPOSAL proposal: {}", metadataChangeProposals); + Authentication authentication = AuthenticationContext.getAuthentication(); + String actorUrnStr = authentication.getActor().toUrnStr(); + List> responses = metadataChangeProposals.stream() - .map(proposal -> MappingUtil.ingestProposal(proposal, _entityService, _objectMapper)) + .map(proposal -> MappingUtil.ingestProposal(proposal, actorUrnStr, _entityService, _objectMapper)) .collect(Collectors.toList()); if (responses.stream().anyMatch(Pair::getSecond)) { return ResponseEntity.status(HttpStatus.CREATED) diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java index 8d07196535322..e0ba52b5a76ea 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java @@ -246,13 +246,13 @@ public static GenericAspect convertGenericAspect(@Nonnull io.datahubproject.open } } - public static Pair ingestProposal(MetadataChangeProposal metadataChangeProposal, EntityService entityService, + public static Pair ingestProposal(MetadataChangeProposal metadataChangeProposal, String actorUrn, EntityService entityService, ObjectMapper objectMapper) { // TODO: Use the actor present in the IC. Timer.Context context = MetricUtils.timer("postEntity").time(); final com.linkedin.common.AuditStamp auditStamp = new com.linkedin.common.AuditStamp().setTime(System.currentTimeMillis()) - .setActor(UrnUtils.getUrn(Constants.UNKNOWN_ACTOR)); + .setActor(UrnUtils.getUrn(actorUrn)); io.datahubproject.openapi.generated.KafkaAuditHeader auditHeader = metadataChangeProposal.getAuditHeader(); com.linkedin.mxe.MetadataChangeProposal serviceProposal = From a45cdb92e68f5d4be34a0e7cd2ac30af529c9451 Mon Sep 17 00:00:00 2001 From: neojunjie Date: Tue, 28 Jun 2022 17:35:09 +0800 Subject: [PATCH 6/8] audit trail for open api --- metadata-service/openapi-servlet/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata-service/openapi-servlet/build.gradle b/metadata-service/openapi-servlet/build.gradle index 1b4621bf63949..08f019bed70fb 100644 --- a/metadata-service/openapi-servlet/build.gradle +++ b/metadata-service/openapi-servlet/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'java' dependencies { - compile project(':metadata-service:factories') compile project(':metadata-service:auth-api') + compile project(':metadata-service:factories') compile externalDependency.reflections compile externalDependency.springBoot From 04f739deb7f17d19921cc23b37a0b9dc06500dea Mon Sep 17 00:00:00 2001 From: junjie Date: Mon, 4 Jul 2022 08:20:03 +0700 Subject: [PATCH 7/8] removed unused import --- .../main/java/io/datahubproject/openapi/util/MappingUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java index e0ba52b5a76ea..15a90afa3612b 100644 --- a/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java +++ b/metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/util/MappingUtil.java @@ -14,7 +14,6 @@ import com.linkedin.data.template.RecordTemplate; import com.linkedin.entity.Aspect; import com.linkedin.events.metadata.ChangeType; -import com.linkedin.metadata.Constants; import com.linkedin.metadata.entity.EntityService; import com.linkedin.metadata.entity.RollbackRunResult; import com.linkedin.metadata.entity.ValidationException; From 412c22ec63410c6ddc71f30508a67ea4d440d2cc Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 7 Jul 2022 08:39:39 +0700 Subject: [PATCH 8/8] add mock authentication --- .../src/test/java/entities/EntitiesControllerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/metadata-service/openapi-servlet/src/test/java/entities/EntitiesControllerTest.java b/metadata-service/openapi-servlet/src/test/java/entities/EntitiesControllerTest.java index d81069f07efd6..b158c4ca6ad00 100644 --- a/metadata-service/openapi-servlet/src/test/java/entities/EntitiesControllerTest.java +++ b/metadata-service/openapi-servlet/src/test/java/entities/EntitiesControllerTest.java @@ -1,5 +1,9 @@ package entities; +import com.datahub.authentication.Actor; +import com.datahub.authentication.ActorType; +import com.datahub.authentication.Authentication; +import com.datahub.authentication.AuthenticationContext; import com.fasterxml.jackson.databind.ObjectMapper; import com.linkedin.metadata.entity.AspectDao; import com.linkedin.metadata.event.EventProducer; @@ -34,6 +38,7 @@ import org.testng.annotations.Test; import static com.linkedin.metadata.Constants.*; +import static org.mockito.Mockito.when; public class EntitiesControllerTest { @@ -53,6 +58,9 @@ public void setup() EventProducer mockEntityEventProducer = Mockito.mock(EventProducer.class); MockEntityService mockEntityService = new MockEntityService(aspectDao, mockEntityEventProducer, mockEntityRegistry); _entitiesController = new EntitiesController(mockEntityService, new ObjectMapper()); + Authentication authentication = Mockito.mock(Authentication.class); + when(authentication.getActor()).thenReturn(new Actor(ActorType.USER, "datahub")); + AuthenticationContext.setAuthentication(authentication); } EntitiesController _entitiesController;