Skip to content

Commit

Permalink
DG-1533 check create/update sub-domain/products permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbonte21 committed Jun 11, 2024
1 parent c8caf98 commit 5d9fdd7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)){
Expand Down

0 comments on commit 5d9fdd7

Please sign in to comment.