2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.xacml;
24 import jakarta.ws.rs.core.Response;
25 import java.util.Collections;
27 import java.util.concurrent.CompletableFuture;
28 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
29 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
32 import org.onap.policy.models.decisions.concepts.DecisionRequest;
33 import org.onap.policy.models.decisions.concepts.DecisionResponse;
36 * Guard Operation. The outcome message is set to the guard response. If the guard is
37 * permitted or indeterminate, then the outcome is set to SUCCESS.
39 * The input to the request is taken from the payload, where properties are mapped to the
40 * field names in the {@link DecisionRequest} object. Properties whose names begin with
41 * "resource." are placed into the "resource" field of the {@link DecisionRequest}. The
42 * following will be provided, if not specified in the payload:
50 public class GuardOperation extends DecisionOperation {
52 public static final String NAME = "Guard";
54 public static final String PERMIT = "Permit";
55 public static final String DENY = "Deny";
56 public static final String INDETERMINATE = "Indeterminate";
60 * Constructs the object.
62 * @param params operation parameters
63 * @param config configuration for this operation
65 public GuardOperation(ControlLoopOperationParams params, HttpConfig config) {
66 super(params, config, Collections.emptyList());
70 * Makes a request from the payload.
72 * @return a new request
74 protected DecisionRequest makeRequest() {
75 if (params.getPayload() == null) {
76 throw new IllegalArgumentException("missing payload");
79 DecisionRequest req = config.makeRequest();
80 req.setRequestId(getSubRequestId());
81 req.setResource(Map.of("guard", params.getPayload()));
87 protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
88 Response rawResponse, DecisionResponse response) {
90 outcome.setResponse(response);
92 // determine the result
93 String status = response.getStatus();
95 outcome.setResult(OperationResult.FAILURE);
96 outcome.setMessage("response contains no status");
97 return CompletableFuture.completedFuture(outcome);
100 if (PERMIT.equalsIgnoreCase(status) || INDETERMINATE.equalsIgnoreCase(status)) {
101 outcome.setResult(OperationResult.SUCCESS);
103 outcome.setResult(OperationResult.FAILURE);
107 outcome.setMessage(response.getStatus());
109 return CompletableFuture.completedFuture(outcome);