2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.tutorial.tutorial;
22 import java.util.Map.Entry;
23 import org.onap.policy.models.decisions.concepts.DecisionRequest;
24 import com.att.research.xacml.std.annotations.XACMLAction;
25 import com.att.research.xacml.std.annotations.XACMLRequest;
26 import com.att.research.xacml.std.annotations.XACMLResource;
27 import com.att.research.xacml.std.annotations.XACMLSubject;
30 import lombok.ToString;
35 @XACMLRequest(ReturnPolicyIdList = true)
36 public class TutorialRequest {
37 @XACMLSubject(includeInResults = true)
38 private String onapName;
40 @XACMLSubject(attributeId = "urn:org:onap:onap-component", includeInResults = true)
41 private String onapComponent;
43 @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
44 private String onapInstance;
47 private String action;
49 @XACMLResource(attributeId = "urn:org:onap:tutorial-user", includeInResults = true)
52 @XACMLResource(attributeId = "urn:org:onap:tutorial-entity", includeInResults = true)
53 private String entity;
55 @XACMLResource(attributeId = "urn:org:onap:tutorial-permission", includeInResults = true)
56 private String permission;
58 public static TutorialRequest createRequest(DecisionRequest decisionRequest) {
62 TutorialRequest request = new TutorialRequest();
64 // Add the subject attributes
66 request.onapName = decisionRequest.getOnapName();
67 request.onapComponent = decisionRequest.getOnapComponent();
68 request.onapInstance = decisionRequest.getOnapInstance();
70 // Add the action attribute
72 request.action = decisionRequest.getAction();
74 // Add the resource attributes
76 Map<String, Object> resources = decisionRequest.getResource();
77 for (Entry<String, Object> entrySet : resources.entrySet()) {
78 if ("user".equals(entrySet.getKey())) {
79 request.user = entrySet.getValue().toString();
81 if ("entity".equals(entrySet.getKey())) {
82 request.entity = entrySet.getValue().toString();
84 if ("permission".equals(entrySet.getKey())) {
85 request.permission = entrySet.getValue().toString();