2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pdp.xacml.application.common;
25 import com.att.research.xacml.api.Identifier;
26 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
27 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
28 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
29 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
32 * This class contains static methods of helper classes to convert TOSCA policies
33 * into XACML policies.
35 * @author pameladragosh
38 public final class ToscaPolicyTranslatorUtils {
40 private ToscaPolicyTranslatorUtils() {
45 * This method builds a MatchType for TargetType object for AttributeValue and AttributeDesignator
48 * @param <T> Incoming value could be any object
49 * @param function Function for the Match
50 * @param value Attribute value used
51 * @param datatype Datatype for attribute value and AttributeDesignator
52 * @param designatorId ID for the AttributeDesignator
53 * @param designatorCategory Category ID for the AttributeDesignator
54 * @return The MatchType object
56 public static <T> MatchType buildMatchTypeDesignator(Identifier function,
59 Identifier designatorId,
60 Identifier designatorCategory) {
62 // Create the MatchType object and set its function
64 MatchType match = new MatchType();
65 match.setMatchId(function.stringValue());
67 // Add in the AttributeValue object
69 AttributeValueType valueType = new AttributeValueType();
70 valueType.setDataType(datatype.stringValue());
71 valueType.getContent().add(value);
73 match.setAttributeValue(valueType);
75 // Add in the AttributeDesignator object
77 AttributeDesignatorType designator = new AttributeDesignatorType();
78 designator.setAttributeId(designatorId.stringValue());
79 designator.setCategory(designatorCategory.stringValue());
80 designator.setDataType(datatype.stringValue());
82 match.setAttributeDesignator(designator);
90 * Builds an AllOfType (AND) with one or more MatchType objects.
92 * @param matches A list of one or more MatchType
93 * @return The AllOf object
95 public static AllOfType buildAllOf(MatchType... matches) {
96 AllOfType allOf = new AllOfType();
97 for (MatchType match : matches) {
98 allOf.getMatch().add(match);