diff options
author | M.Hosnidokht <mohammad.hosnidokht@yoppworks.com> | 2020-12-03 11:11:16 -0500 |
---|---|---|
committer | M.Hosnidokht <mohammad.hosnidokht@yoppworks.com> | 2021-01-06 10:15:57 -0500 |
commit | eca412c5285bb65bd82a8236e0fec8426a2c605e (patch) | |
tree | 9ac48d843e7d57d983dd0a0f1f87d043ac09ba0d /aai-core/src/main | |
parent | c42f46f79066734b96f91815b49b633a30e0ede4 (diff) |
Use data owner attribute instead of owning entity for OwnerCheck
Issue-ID: AAI-3226
Signed-off-by: Mohammad Hosnidokht <mohammad.hosnidokht@yoppworks.com>
Change-Id: I8222546e7264e99ca3e53fe1212a45008c1064e6
Diffstat (limited to 'aai-core/src/main')
-rw-r--r-- | aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java | 37 | ||||
-rw-r--r-- | aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java | 22 |
2 files changed, 29 insertions, 30 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java index 4ece3771..c383f0c5 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/OwnerCheck.java @@ -20,24 +20,23 @@ package org.onap.aai.introspection.sideeffect; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; - -import java.util.List; -import java.util.Map.Entry; -import java.util.Optional; +import org.apache.commons.lang3.ObjectUtils; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; -import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; -import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.schema.enums.PropertyMetadata; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.springframework.util.CollectionUtils; + +import java.util.Map.Entry; +import java.util.Optional; public class OwnerCheck extends SideEffect { + public static final String READ_ONLY_SUFFIX = "_readOnly"; + private static final String DATA_OWNER = "data-owner"; + public OwnerCheck(Introspector obj, Vertex self, TransactionalGraphEngine dbEngine, DBSerializer serializer) { super(obj, self, dbEngine, serializer); } @@ -55,21 +54,15 @@ public class OwnerCheck extends SideEffect { } public static boolean isAuthorized(java.util.Set<String> groups, Vertex vertex) { - if (groups != null && !groups.isEmpty()) { - List<Vertex> owningEntity = vertex.graph().traversal() - .V(vertex) - .bothE("org.onap.relationships.inventory.BelongsTo") - .otherV() - .has("aai-node-type", "owning-entity") - .toList(); - - if(!owningEntity.isEmpty()) { - VertexProperty owningEntityName = owningEntity.get(0).property("owning-entity-name"); - - return groups.contains(owningEntityName.orElseGet(null)); + if (!CollectionUtils.isEmpty(groups)) { + Object dataOwnerProperty = vertex.property(DATA_OWNER).orElse(null); + if (ObjectUtils.isNotEmpty(dataOwnerProperty)) { + String dataOwner = dataOwnerProperty.toString(); + String dataOwnerWithReadAccess = dataOwner + READ_ONLY_SUFFIX; + return groups.stream() + .anyMatch(group -> group.equals(dataOwner) || group.equals(dataOwnerWithReadAccess)); } } - return true; } diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java index 14621e83..7ab49a13 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java @@ -115,6 +115,7 @@ public class DBSerializer { private Map<String, Pair<Introspector, LinkedHashMap<String, Introspector>>> impliedDeleteUriObjectPair = new LinkedHashMap<>(); private int notificationDepth; private boolean isDeltaEventsEnabled; + private boolean isMultiTenancyEnabled; /** * Instantiates a new DB serializer. @@ -271,6 +272,7 @@ public class DBSerializer { EdgeSerializer es = ctx.getBean(EdgeSerializer.class); setEdgeSerializer(es); isDeltaEventsEnabled = Boolean.parseBoolean(SpringContextAware.getApplicationContext().getEnvironment().getProperty("delta.events.enabled", FALSE)); + isMultiTenancyEnabled = Boolean.parseBoolean(SpringContextAware.getApplicationContext().getEnvironment().getProperty("multi.tenancy.enabled", FALSE)); } public void setEdgeSerializer(EdgeSerializer edgeSer) { @@ -2270,10 +2272,12 @@ public class DBSerializer { private void executePreSideEffects(Introspector obj, Vertex self) throws AAIException { - SideEffectRunner runner = new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class) - .addSideEffect(PrivateEdge.class).addSideEffect(OwnerCheck.class).build(); - - runner.execute(obj, self); + SideEffectRunner.Builder runnerBuilder = + new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataCopy.class).addSideEffect(PrivateEdge.class); + if (isMultiTenancyEnabled) { + runnerBuilder.addSideEffect(OwnerCheck.class); + } + runnerBuilder.build().execute(obj, self); } private void executePostSideEffects(Introspector obj, Vertex self) throws AAIException { @@ -2286,11 +2290,13 @@ public class DBSerializer { private void enrichData(Introspector obj, Vertex self) throws AAIException { - SideEffectRunner runner = - new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataLinkReader.class) - .addSideEffect(OwnerCheck.class).build(); + SideEffectRunner.Builder runnerBuilder = + new SideEffectRunner.Builder(this.engine, this).addSideEffect(DataLinkReader.class); - runner.execute(obj, self); + if (isMultiTenancyEnabled) { + runnerBuilder.addSideEffect(OwnerCheck.class); + } + runnerBuilder.build().execute(obj, self); } public double getDBTimeMsecs() { |