2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.introspection.sideeffect;
23 import java.io.UnsupportedEncodingException;
24 import java.net.URISyntaxException;
26 import java.util.List;
27 import java.util.Map.Entry;
28 import java.util.Optional;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
31 import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException;
32 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.Introspector;
35 import org.onap.aai.schema.enums.PropertyMetadata;
36 import org.onap.aai.serialization.db.DBSerializer;
37 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 public class OwnerCheck extends SideEffect {
41 public OwnerCheck(Introspector obj, Vertex self, TransactionalGraphEngine dbEngine, DBSerializer serializer) {
42 super(obj, self, dbEngine, serializer);
46 protected void processURI(Optional<String> completeUri, Entry<String, String> entry)
48 if (!isAuthorized(serializer.getGroups(), self)) {
50 throw new AAIException("AAI_3304",
51 "Group(s) :" + serializer.getGroups() + " not authorized to perform function");
53 } //else skip processing because no required properties were specified
57 public static boolean isAuthorized(java.util.Set<String> groups, Vertex vertex) {
58 if (groups != null && !groups.isEmpty()) {
59 List<Vertex> owningEntity = vertex.graph().traversal()
61 .bothE("org.onap.relationships.inventory.BelongsTo")
63 .has("aai-node-type", "owning-entity")
66 if(!owningEntity.isEmpty()) {
67 VertexProperty owningEntityName = owningEntity.get(0).property("owning-entity-name");
69 return groups.contains(owningEntityName.orElseGet(null));
77 protected PropertyMetadata getPropertyMetadata() {
78 return PropertyMetadata.OWNER_CHECK;
82 protected boolean replaceWithWildcard() {