From 5d9fdd7b8cbc8e72fb7c0b84644536abf9a6c78d Mon Sep 17 00:00:00 2001 From: Nikhil P Bonte Date: Mon, 10 Jun 2024 19:00:38 +0530 Subject: [PATCH] DG-1533 check create/update sub-domain/products permissions --- .../datamesh/AbstractDomainPreProcessor.java | 25 +++++++++++++------ .../datamesh/DataDomainPreProcessor.java | 2 +- .../datamesh/DataProductPreProcessor.java | 3 +-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/AbstractDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/AbstractDomainPreProcessor.java index 8fa6e234d9..368cfae4fe 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/AbstractDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/AbstractDomainPreProcessor.java @@ -90,16 +90,27 @@ public abstract class AbstractDomainPreProcessor implements PreProcessor { } } - protected void isAuthorized(AtlasEntityHeader sourceDomain, AtlasEntityHeader targetDomain) throws AtlasBaseException { + protected void isAuthorizedToMove(String typeName, AtlasEntityHeader sourceDomain, AtlasEntityHeader targetDomain) throws AtlasBaseException { - if(sourceDomain != null){ - AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, sourceDomain), - "update on source Domain: ", sourceDomain.getAttribute(NAME)); + String qualifiedNameToAuthSuffix = DATA_DOMAIN_ENTITY_TYPE.equals(typeName) ? "/*domain/*" : "/*product/*"; + AtlasEntityHeader headerToAuth = new AtlasEntityHeader(typeName); + + if (sourceDomain != null) { + //Update sub-domains/product on source parent + String qualifiedNameToAuth = sourceDomain.getAttribute(QUALIFIED_NAME) + qualifiedNameToAuthSuffix; + headerToAuth.setAttribute(QUALIFIED_NAME, qualifiedNameToAuth); + + AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, headerToAuth), + AtlasPrivilege.ENTITY_UPDATE.name(), " " , typeName, " : ", qualifiedNameToAuth); } - if(targetDomain != null){ - AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, targetDomain), - "update on target Domain: ", targetDomain.getAttribute(NAME)); + if (targetDomain != null) { + //Create sub-domains/product on target parent + String qualifiedNameToAuth = targetDomain.getAttribute(QUALIFIED_NAME) + qualifiedNameToAuthSuffix; + headerToAuth.setAttribute(QUALIFIED_NAME, qualifiedNameToAuth); + + AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, headerToAuth), + AtlasPrivilege.ENTITY_CREATE.name(), " " , typeName, " : ", qualifiedNameToAuth); } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index c056b2ad68..77157c99ef 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -163,7 +163,7 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws } //Auth check - isAuthorized(currentParentDomainHeader, newParentDomainHeader); + isAuthorizedToMove(DATA_DOMAIN_ENTITY_TYPE, currentParentDomainHeader, newParentDomainHeader); processMoveSubDomainToAnotherDomain(entity, vertex, currentParentDomainQualifiedName, newParentDomainQualifiedName, vertexQnName, newSuperDomainQualifiedName); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java index ea974535b6..be2c97ac95 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java @@ -18,7 +18,6 @@ import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.utils.AtlasPerfMetrics; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,7 +140,7 @@ private void processUpdateProduct(AtlasEntity entity, AtlasVertex vertex) throws } //Auth check - isAuthorized(currentParentDomainHeader, newParentDomainHeader); + isAuthorizedToMove(DATA_PRODUCT_ENTITY_TYPE, currentParentDomainHeader, newParentDomainHeader); String newSuperDomainQualifiedName = (String) newParentDomainHeader.getAttribute(SUPER_DOMAIN_QN_ATTR); if(StringUtils.isEmpty(newSuperDomainQualifiedName)){