Commit d4a50aad by chaitali borole Committed by nixonrodrigues

ATLAS-3950 : Authorize for Read Type for Classification, Business metadata ,…

ATLAS-3950 : Authorize for Read Type for Classification, Business metadata , Entity typesdef attributes. Signed-off-by: 's avatarnixonrodrigues <nixon@apache.org>
parent 7ae0bea9
...@@ -20,16 +20,23 @@ package org.apache.atlas.repository.store.graph.v2; ...@@ -20,16 +20,23 @@ package org.apache.atlas.repository.store.graph.v2;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
import org.apache.atlas.authorize.AtlasPrivilege;
import org.apache.atlas.authorize.AtlasTypeAccessRequest;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.query.AtlasDSL; import org.apache.atlas.query.AtlasDSL;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasDefStore; import org.apache.atlas.repository.store.graph.AtlasDefStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -54,6 +61,48 @@ import java.util.regex.Pattern; ...@@ -54,6 +61,48 @@ import java.util.regex.Pattern;
this.typeRegistry = typeRegistry; this.typeRegistry = typeRegistry;
} }
public void verifyTypesReadAccess(Collection<? extends AtlasType> types) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(types)) {
for (AtlasType type : types) {
AtlasBaseTypeDef def = typeRegistry.getTypeDefByName(type.getTypeName());
if (def != null) {
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, def), "read type-def of category ", def.getCategory(), " ", def.getName());
}
}
}
}
public void verifyTypeReadAccess(Collection<String> types) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(types)) {
for (String type : types) {
AtlasBaseTypeDef def = typeRegistry.getTypeDefByName(type);
if (def != null) {
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, def), "read type-def of category ", def.getCategory(), " ", def.getName());
}
}
}
}
public void verifyTypeReadAccess(String type) throws AtlasBaseException {
if (StringUtils.isNotEmpty(type)) {
AtlasBaseTypeDef def = typeRegistry.getTypeDefByName(type);
if (def != null) {
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, def), "read type-def of category ", def.getCategory(), " ", def.getName());
}
}
}
public void verifyAttributeTypeReadAccess(Collection<AtlasStructDef.AtlasAttributeDef> types) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(types)) {
for (AtlasStructDef.AtlasAttributeDef attributeDef : types) {
AtlasBaseTypeDef def = typeRegistry.getTypeDefByName(attributeDef.getTypeName());
if (def != null) {
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, def), "read type-def of category ", def.getCategory(), " ", def.getName());
}
}
}
}
public void validateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException { public void validateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (!isValidName(typeDef.getName())) { if (!isValidName(typeDef.getName())) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeDef.getName(), typeDef.getCategory().name()); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeDef.getName(), typeDef.getCategory().name());
......
...@@ -29,6 +29,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef; ...@@ -29,6 +29,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasBusinessMetadataType; import org.apache.atlas.type.AtlasBusinessMetadataType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
...@@ -104,6 +105,16 @@ public class AtlasBusinessMetadataDefStoreV2 extends AtlasAbstractDefStoreV2<Atl ...@@ -104,6 +105,16 @@ public class AtlasBusinessMetadataDefStoreV2 extends AtlasAbstractDefStoreV2<Atl
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.create({}, {})", businessMetadataDef, preCreateResult); LOG.debug("==> AtlasBusinessMetadataDefStoreV2.create({}, {})", businessMetadataDef, preCreateResult);
} }
verifyAttributeTypeReadAccess(businessMetadataDef.getAttributeDefs());
if (CollectionUtils.isNotEmpty(businessMetadataDef.getAttributeDefs())) {
AtlasBusinessMetadataType businessMetadataType = typeRegistry.getBusinessMetadataTypeByName(businessMetadataDef.getName());
for (AtlasStructType.AtlasAttribute attribute : businessMetadataType.getAllAttributes().values()) {
AtlasBusinessMetadataType.AtlasBusinessAttribute bmAttribute = (AtlasBusinessMetadataType.AtlasBusinessAttribute) attribute;
verifyTypesReadAccess(bmAttribute.getApplicableEntityTypes());
}
}
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, businessMetadataDef), "create businessMetadata-def ", businessMetadataDef.getName()); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, businessMetadataDef), "create businessMetadata-def ", businessMetadataDef.getName());
AtlasVertex vertex = (preCreateResult == null) ? preCreate(businessMetadataDef) : preCreateResult; AtlasVertex vertex = (preCreateResult == null) ? preCreate(businessMetadataDef) : preCreateResult;
...@@ -186,6 +197,16 @@ public class AtlasBusinessMetadataDefStoreV2 extends AtlasAbstractDefStoreV2<Atl ...@@ -186,6 +197,16 @@ public class AtlasBusinessMetadataDefStoreV2 extends AtlasAbstractDefStoreV2<Atl
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.update({})", typeDef); LOG.debug("==> AtlasBusinessMetadataDefStoreV2.update({})", typeDef);
} }
verifyAttributeTypeReadAccess(typeDef.getAttributeDefs());
if (CollectionUtils.isNotEmpty(typeDef.getAttributeDefs())) {
AtlasBusinessMetadataType businessMetadataType = typeRegistry.getBusinessMetadataTypeByName(typeDef.getName());
for (AtlasStructType.AtlasAttribute attribute : businessMetadataType.getAllAttributes().values()) {
AtlasBusinessMetadataType.AtlasBusinessAttribute bmAttribute = (AtlasBusinessMetadataType.AtlasBusinessAttribute) attribute;
verifyTypesReadAccess(bmAttribute.getApplicableEntityTypes());
}
}
validateType(typeDef); validateType(typeDef);
AtlasBusinessMetadataDef ret = StringUtils.isNotBlank(typeDef.getGuid()) ? updateByGuid(typeDef.getGuid(), typeDef) AtlasBusinessMetadataDef ret = StringUtils.isNotBlank(typeDef.getGuid()) ? updateByGuid(typeDef.getGuid(), typeDef)
......
...@@ -23,16 +23,13 @@ import org.apache.atlas.authorize.AtlasPrivilege; ...@@ -23,16 +23,13 @@ import org.apache.atlas.authorize.AtlasPrivilege;
import org.apache.atlas.authorize.AtlasAuthorizationUtils; import org.apache.atlas.authorize.AtlasAuthorizationUtils;
import org.apache.atlas.authorize.AtlasTypeAccessRequest; import org.apache.atlas.authorize.AtlasTypeAccessRequest;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -181,6 +178,9 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif ...@@ -181,6 +178,9 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif
LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classifiDef); LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classifiDef);
} }
verifyTypeReadAccess(classifiDef.getSuperTypes());
verifyTypeReadAccess(classifiDef.getEntityTypes());
validateType(classifiDef); validateType(classifiDef);
AtlasClassificationDef ret = StringUtils.isNotBlank(classifiDef.getGuid()) AtlasClassificationDef ret = StringUtils.isNotBlank(classifiDef.getGuid())
...@@ -367,15 +367,4 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif ...@@ -367,15 +367,4 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif
return m.matches(); return m.matches();
} }
private void verifyTypeReadAccess(Set<String> types) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(types)) {
for (String type : types) {
AtlasBaseTypeDef def = typeRegistry.getTypeDefByName(type);
if (def != null) {
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, def), "read type-def of category", def.getCategory(), def.getName());
}
}
}
}
} }
...@@ -88,6 +88,8 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe ...@@ -88,6 +88,8 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe
LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult); LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult);
} }
verifyAttributeTypeReadAccess(entityDef.getAttributeDefs());
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, entityDef), "create entity-def ", entityDef.getName()); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, entityDef), "create entity-def ", entityDef.getName());
AtlasVertex vertex = (preCreateResult == null) ? preCreate(entityDef) : preCreateResult; AtlasVertex vertex = (preCreateResult == null) ? preCreate(entityDef) : preCreateResult;
...@@ -173,6 +175,8 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe ...@@ -173,6 +175,8 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe
LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDef); LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDef);
} }
verifyAttributeTypeReadAccess(entityDef.getAttributeDefs());
validateType(entityDef); validateType(entityDef);
AtlasEntityDef ret = StringUtils.isNotBlank(entityDef.getGuid()) ? updateByGuid(entityDef.getGuid(), entityDef) AtlasEntityDef ret = StringUtils.isNotBlank(entityDef.getGuid()) ? updateByGuid(entityDef.getGuid(), entityDef)
......
...@@ -133,6 +133,9 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe ...@@ -133,6 +133,9 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe
LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult); LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult);
} }
verifyTypeReadAccess(relationshipDef.getEndDef1().getType());
verifyTypeReadAccess(relationshipDef.getEndDef2().getType());
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, relationshipDef), "create relationship-def ", relationshipDef.getName()); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, relationshipDef), "create relationship-def ", relationshipDef.getName());
AtlasVertex vertex = (preCreateResult == null) ? preCreate(relationshipDef) : preCreateResult; AtlasVertex vertex = (preCreateResult == null) ? preCreate(relationshipDef) : preCreateResult;
...@@ -216,6 +219,9 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe ...@@ -216,6 +219,9 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe
LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef); LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef);
} }
verifyTypeReadAccess(relationshipDef.getEndDef1().getType());
verifyTypeReadAccess(relationshipDef.getEndDef2().getType());
validateType(relationshipDef); validateType(relationshipDef);
AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid()) AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid())
......
...@@ -98,6 +98,8 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe ...@@ -98,6 +98,8 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
LOG.debug("==> AtlasStructDefStoreV1.create({}, {})", structDef, preCreateResult); LOG.debug("==> AtlasStructDefStoreV1.create({}, {})", structDef, preCreateResult);
} }
verifyAttributeTypeReadAccess(structDef.getAttributeDefs());
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, structDef), "create struct-def ", structDef.getName()); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, structDef), "create struct-def ", structDef.getName());
if (CollectionUtils.isEmpty(structDef.getAttributeDefs())) { if (CollectionUtils.isEmpty(structDef.getAttributeDefs())) {
...@@ -186,6 +188,9 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe ...@@ -186,6 +188,9 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
LOG.debug("==> AtlasStructDefStoreV1.update({})", structDef); LOG.debug("==> AtlasStructDefStoreV1.update({})", structDef);
} }
verifyAttributeTypeReadAccess(structDef.getAttributeDefs());
validateType(structDef); validateType(structDef);
AtlasStructDef ret = StringUtils.isNotBlank(structDef.getGuid()) ? updateByGuid(structDef.getGuid(), structDef) AtlasStructDef ret = StringUtils.isNotBlank(structDef.getGuid()) ? updateByGuid(structDef.getGuid(), structDef)
......
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