2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 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.policy.controlloop.actor.xacml;
23 import java.util.Collections;
25 import java.util.concurrent.CompletableFuture;
26 import javax.ws.rs.core.Response;
27 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
28 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
31 import org.onap.policy.models.decisions.concepts.DecisionRequest;
32 import org.onap.policy.models.decisions.concepts.DecisionResponse;
35 * Guard Operation. The outcome message is set to the guard response. If the guard is
36 * permitted or indeterminate, then the outcome is set to SUCCESS.
38 * The input to the request is taken from the payload, where properties are mapped to the
39 * field names in the {@link DecisionRequest} object. Properties whose names begin with
40 * "resource." are placed into the "resource" field of the {@link DecisionRequest}. The
41 * following will be provided, if not specified in the payload:
49 public class GuardOperation extends DecisionOperation {
51 public static final String NAME = "Guard";
53 public static final String PERMIT = "Permit";
54 public static final String DENY = "Deny";
55 public static final String INDETERMINATE = "Indeterminate";
59 * Constructs the object.
61 * @param params operation parameters
62 * @param config configuration for this operation
64 public GuardOperation(ControlLoopOperationParams params, HttpConfig config) {
65 super(params, config, Collections.emptyList());
69 * Makes a request from the payload.
71 * @return a new request
73 protected DecisionRequest makeRequest() {
74 if (params.getPayload() == null) {
75 throw new IllegalArgumentException("missing payload");
78 DecisionRequest req = config.makeRequest();
79 req.setRequestId(getSubRequestId());
80 req.setResource(Map.of("guard", params.getPayload()));
86 protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
87 Response rawResponse, DecisionResponse response) {
89 outcome.setResponse(response);
91 // determine the result
92 String status = response.getStatus();
94 outcome.setResult(OperationResult.FAILURE);
95 outcome.setMessage("response contains no status");
96 return CompletableFuture.completedFuture(outcome);
99 if (PERMIT.equalsIgnoreCase(status) || INDETERMINATE.equalsIgnoreCase(status)) {
100 outcome.setResult(OperationResult.SUCCESS);
102 outcome.setResult(OperationResult.FAILURE);
106 outcome.setMessage(response.getStatus());
108 return CompletableFuture.completedFuture(outcome);