aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/controller/PolicyEngineServices.java1102
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ListPolicyService.java100
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java1634
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/ConfigNameRequest.java (renamed from ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/ConfigNameRequest.java)29
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngine.java1289
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java69
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java42
-rwxr-xr-xdocs/platform/api-docs.json2
-rw-r--r--docs/platform/offeredapis.rst29
9 files changed, 2349 insertions, 1947 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/controller/PolicyEngineServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/controller/PolicyEngineServices.java
index 2348fd0da..4296c058c 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/controller/PolicyEngineServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/controller/PolicyEngineServices.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,19 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.pdp.rest.api.controller;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+package org.onap.policy.pdp.rest.api.controller;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicLong;
-
import javax.servlet.http.HttpServletRequest;
-
+import org.onap.policy.api.ConfigNameRequest;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DecisionRequestParameters;
import org.onap.policy.api.DecisionResponse;
@@ -45,7 +40,6 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pdp.rest.XACMLPdpServlet;
import org.onap.policy.pdp.rest.api.models.ConfigFirewallPolicyAPIRequest;
-import org.onap.policy.pdp.rest.api.models.ConfigNameRequest;
import org.onap.policy.pdp.rest.api.models.ConfigPolicyAPIRequest;
import org.onap.policy.pdp.rest.api.models.PolicyConfig;
import org.onap.policy.pdp.rest.api.services.CreateUpdateConfigPolicyService;
@@ -58,6 +52,7 @@ import org.onap.policy.pdp.rest.api.services.GetDecisionService;
import org.onap.policy.pdp.rest.api.services.GetDictionaryService;
import org.onap.policy.pdp.rest.api.services.GetMetricsService;
import org.onap.policy.pdp.rest.api.services.ListConfigService;
+import org.onap.policy.pdp.rest.api.services.ListPolicyService;
import org.onap.policy.pdp.rest.api.services.NotificationService;
import org.onap.policy.pdp.rest.api.services.NotificationService.NotificationServiceType;
import org.onap.policy.pdp.rest.api.services.PolicyEngineImportService;
@@ -68,6 +63,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -76,583 +72,559 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
-
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
@RestController
@Api(value = "Policy Engine Services")
@RequestMapping("/")
public class PolicyEngineServices {
- private static Logger logger = FlexLogger.getLogger(PolicyEngineServices.class.getName());
- private static final String NOTIFICATIONPERM = "notification";
-
- private final AtomicLong configCounter = new AtomicLong();
- private final AtomicLong configNameCounter = new AtomicLong();
- private final AtomicLong eventCounter = new AtomicLong();
- private final AtomicLong decisionCounter = new AtomicLong();
- private final AtomicLong pushCounter = new AtomicLong();
- private final AtomicLong deleteCounter = new AtomicLong();
- private final AtomicLong createPolicyCounter = new AtomicLong();
- private final AtomicLong updatePolicyCounter = new AtomicLong();
- private final AtomicLong createDictionaryCounter = new AtomicLong();
- private final AtomicLong updateDictionaryCounter = new AtomicLong();
- private final AtomicLong getDictionaryCounter = new AtomicLong();
- private final AtomicLong policyEngineImportCounter = new AtomicLong();
- private final AtomicLong deprecatedCounter = new AtomicLong();
- private final AtomicLong metricCounter = new AtomicLong();
- private final AtomicLong notificationCounter = new AtomicLong();
+ private static Logger logger = FlexLogger.getLogger(PolicyEngineServices.class.getName());
+ private static final String NOTIFICATIONPERM = "notification";
+
+ private final AtomicLong configCounter = new AtomicLong();
+ private final AtomicLong configNameCounter = new AtomicLong();
+ private final AtomicLong eventCounter = new AtomicLong();
+ private final AtomicLong decisionCounter = new AtomicLong();
+ private final AtomicLong pushCounter = new AtomicLong();
+ private final AtomicLong deleteCounter = new AtomicLong();
+ private final AtomicLong createPolicyCounter = new AtomicLong();
+ private final AtomicLong updatePolicyCounter = new AtomicLong();
+ private final AtomicLong createDictionaryCounter = new AtomicLong();
+ private final AtomicLong updateDictionaryCounter = new AtomicLong();
+ private final AtomicLong getDictionaryCounter = new AtomicLong();
+ private final AtomicLong policyEngineImportCounter = new AtomicLong();
+ private final AtomicLong deprecatedCounter = new AtomicLong();
+ private final AtomicLong metricCounter = new AtomicLong();
+ private final AtomicLong notificationCounter = new AtomicLong();
+
+ /**
+ * Gets the config.
+ *
+ * @param configRequestParameters the config request parameters
+ * @param clientEncoding the client encoding
+ * @param requestId the request ID
+ * @return the config
+ */
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the configuration from the PolicyDecisionPoint(PDP)")
+ @RequestMapping(value = "/getConfig", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<Collection<PolicyConfig>> getConfig(
+ @RequestBody ConfigRequestParameters configRequestParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ Collection<PolicyConfig> policyConfig = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getConfig")) {
+ GetConfigService getConfigService = new GetConfigService(configRequestParameters, requestID);
+ policyConfig = getConfigService.getResult();
+ status = getConfigService.getResponseCode();
+ }
+ configCounter.incrementAndGet();
+ return new ResponseEntity<>(policyConfig, status);
+ }
+
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the configuration from the PolicyDecisionPoint(PDP) using PolicyName")
+ @RequestMapping(value = "/getConfigByPolicyName", method = RequestMethod.POST)
+ @ResponseBody
+ @Deprecated
+ public ResponseEntity<Collection<PolicyConfig>> getConfigByPolicyName(
+ @RequestBody ConfigNameRequest configNameRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ Collection<PolicyConfig> policyConfig = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getConfigByPolicyName")) {
+ ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
+ configRequestParameters.setPolicyName(configNameRequest.getPolicyName());
+ GetConfigService getConfigService = new GetConfigService(configRequestParameters, requestID);
+ policyConfig = getConfigService.getResult();
+ status = getConfigService.getResponseCode();
+ }
+ configNameCounter.incrementAndGet();
+ return new ResponseEntity<>(policyConfig, status);
+ }
+
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the list of configuration policies from the PDP")
+ @RequestMapping(value = "/listConfig", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<Collection<String>> listConfig(@RequestBody ConfigRequestParameters configRequestParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ Collection<String> results = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "listConfig")) {
+ ListConfigService listConfigService = new ListConfigService(configRequestParameters, requestID);
+ results = listConfigService.getResult();
+ status = listConfigService.getResponseCode();
+ }
+ configCounter.incrementAndGet();
+ return new ResponseEntity<>(results, status);
+ }
+
+ /**
+ * List Policy.
+ *
+ * @param ConfigNameRequest the config request parameters
+ * @param clientEncoding the client encoding
+ * @param requestId the request ID
+ * @return the response entity
+ */
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the list of policies from the PDP")
+ @PostMapping(value = "/listPolicy")
+ @ResponseBody
+ public ResponseEntity<Collection<String>> listPolicy(@RequestBody ConfigNameRequest configNameRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestId) {
+ Collection<String> results = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ logger.info("Operation: listPolicy - " + configNameRequest);
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestId, "listPolicy")) {
+ ListPolicyService listPolicyService = new ListPolicyService(configNameRequest);
+ results = listPolicyService.getResult();
+ status = listPolicyService.getResponseCode();
+ }
+ configCounter.incrementAndGet();
+ return new ResponseEntity<>(results, status);
+ }
+
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the policy metrics from the PolicyAccessPoint(PAP)")
+ @RequestMapping(value = "/getMetrics", method = RequestMethod.GET)
+ @ResponseBody
+ public ResponseEntity<MetricsResponse> getMetrics(
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ MetricsResponse response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getMetrics")) {
+ GetMetricsService getMetricsService = new GetMetricsService(requestID);
+ response = getMetricsService.getResult();
+ status = getMetricsService.getResponseCode();
+ }
+ metricCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Gets the configuration from the PolicyDecisionPoint(PDP)")
- @RequestMapping(value = "/getConfig", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<Collection<PolicyConfig>> getConfig(
- @RequestBody ConfigRequestParameters configRequestParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- Collection<PolicyConfig> policyConfig = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getConfig")) {
- GetConfigService getConfigService = new GetConfigService(
- configRequestParameters, requestID);
- policyConfig = getConfigService.getResult();
- status = getConfigService.getResponseCode();
- }
- configCounter.incrementAndGet();
- return new ResponseEntity<>(policyConfig, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Registers DMaaP Topic to recieve notification from Policy Engine")
+ @RequestMapping(value = "/getNotification", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<String> getNotification(@RequestBody String notificationTopic,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String policyResponse = "Error Unauthorized to use Notification Service.";
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
+ NotificationService notificationService =
+ new NotificationService(notificationTopic, requestID, NotificationServiceType.ADD);
+ policyResponse = notificationService.getResult();
+ status = notificationService.getResponseCode();
+ }
+ notificationCounter.incrementAndGet();
+ return new ResponseEntity<>(policyResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Gets the configuration from the PolicyDecisionPoint(PDP) using PolicyName")
- @RequestMapping(value = "/getConfigByPolicyName", method = RequestMethod.POST)
- @ResponseBody
- @Deprecated
- public ResponseEntity<Collection<PolicyConfig>> getConfigByPolicyName(
- @RequestBody ConfigNameRequest configNameRequest,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- Collection<PolicyConfig> policyConfig = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,"getConfigByPolicyName")) {
- ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
- configRequestParameters.setPolicyName(configNameRequest
- .getPolicyName());
- GetConfigService getConfigService = new GetConfigService(
- configRequestParameters, requestID);
- policyConfig = getConfigService.getResult();
- status = getConfigService.getResponseCode();
- }
- configNameCounter.incrementAndGet();
- return new ResponseEntity<>(policyConfig, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "De-Registers DMaaP Topic to stop recieving notifications from Policy Engine")
+ @RequestMapping(value = "/stopNotification", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<String> stopNotification(@RequestBody String notificationTopic,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String policyResponse = "Error Unauthorized to use Notification Service.";
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
+ NotificationService notificationService =
+ new NotificationService(notificationTopic, requestID, NotificationServiceType.REMOVE);
+ policyResponse = notificationService.getResult();
+ status = notificationService.getResponseCode();
+ }
+ notificationCounter.incrementAndGet();
+ return new ResponseEntity<>(policyResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Gets the list of configuration policies from the PDP")
- @RequestMapping(value = "/listConfig", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<Collection<String>> listConfig(
- @RequestBody ConfigRequestParameters configRequestParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- Collection<String> results = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth
- .checkPermissions(clientEncoding, requestID, "listConfig")) {
- ListConfigService listConfigService = new ListConfigService(
- configRequestParameters, requestID);
- results = listConfigService.getResult();
- status = listConfigService.getResponseCode();
- }
- configCounter.incrementAndGet();
- return new ResponseEntity<>(results, status);
- }
-
- @ApiImplicitParams({
- @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name ="Environment", required = true, paramType = "Header")
- })
- @ApiOperation(value= "Gets the policy metrics from the PolicyAccessPoint(PAP)")
- @RequestMapping(value="/getMetrics", method=RequestMethod.GET)
- @ResponseBody
- public ResponseEntity<MetricsResponse> getMetrics(
- @RequestHeader(value="ClientAuth", required=true)String clientEncoding,
- @RequestHeader(value="X-ECOMP-RequestID", required=false)String requestID) {
- MetricsResponse response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if(PDPApiAuth.checkPermissions(clientEncoding, requestID, "getMetrics")){
- GetMetricsService getMetricsService = new GetMetricsService(requestID);
- response = getMetricsService.getResult();
- status = getMetricsService.getResponseCode();
- }
- metricCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
-
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Registers DMaaP Topic to recieve notification from Policy Engine")
- @RequestMapping(value = "/getNotification", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<String> getNotification(
- @RequestBody String notificationTopic,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String policyResponse = "Error Unauthorized to use Notification Service.";
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
- NotificationService notificationService = new NotificationService(notificationTopic, requestID, NotificationServiceType.ADD);
- policyResponse = notificationService.getResult();
- status = notificationService.getResponseCode();
- }
- notificationCounter.incrementAndGet();
- return new ResponseEntity<>(policyResponse, status);
- }
-
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "De-Registers DMaaP Topic to stop recieving notifications from Policy Engine")
- @RequestMapping(value = "/stopNotification", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<String> stopNotification(
- @RequestBody String notificationTopic,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String policyResponse = "Error Unauthorized to use Notification Service.";
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
- NotificationService notificationService = new NotificationService(notificationTopic, requestID, NotificationServiceType.REMOVE);
- policyResponse = notificationService.getResult();
- status = notificationService.getResponseCode();
- }
- notificationCounter.incrementAndGet();
- return new ResponseEntity<>(policyResponse, status);
- }
-
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Sends Heartbeat to DMaaP Topic Registry to continue recieving notifications from Policy Engine")
- @RequestMapping(value = "/sendHeartbeat", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<String> sendHeartbeat(
- @RequestBody String notificationTopic,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String policyResponse = "Error Unauthorized to use Heartbeat Service.";
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
- NotificationService notificationService = new NotificationService(notificationTopic, requestID, NotificationServiceType.HB);
- policyResponse = notificationService.getResult();
- status = notificationService.getResponseCode();
- }
- return new ResponseEntity<>(policyResponse, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(
+ value = "Sends Heartbeat to DMaaP Topic Registry to continue recieving notifications from Policy Engine")
+ @RequestMapping(value = "/sendHeartbeat", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<String> sendHeartbeat(@RequestBody String notificationTopic,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String policyResponse = "Error Unauthorized to use Heartbeat Service.";
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, NOTIFICATIONPERM)) {
+ NotificationService notificationService =
+ new NotificationService(notificationTopic, requestID, NotificationServiceType.HB);
+ policyResponse = notificationService.getResult();
+ status = notificationService.getResponseCode();
+ }
+ return new ResponseEntity<>(policyResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Sends the Events specified to the Policy Engine")
- @RequestMapping(value = "/sendEvent", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<Collection<PolicyResponse>> sendEvent(
- @RequestBody EventRequestParameters eventRequestParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- Collection<PolicyResponse> policyResponse = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "sendEvent")) {
- SendEventService sendEventService = new SendEventService(
- eventRequestParameters, requestID);
- policyResponse = sendEventService.getResult();
- status = sendEventService.getResponseCode();
- }
- eventCounter.incrementAndGet();
- return new ResponseEntity<>(policyResponse,
- status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Sends the Events specified to the Policy Engine")
+ @RequestMapping(value = "/sendEvent", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<Collection<PolicyResponse>> sendEvent(
+ @RequestBody EventRequestParameters eventRequestParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ Collection<PolicyResponse> policyResponse = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "sendEvent")) {
+ SendEventService sendEventService = new SendEventService(eventRequestParameters, requestID);
+ policyResponse = sendEventService.getResult();
+ status = sendEventService.getResponseCode();
+ }
+ eventCounter.incrementAndGet();
+ return new ResponseEntity<>(policyResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Gets the Decision using specified decision parameters")
- @RequestMapping(value = "/getDecision", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<DecisionResponse> getDecision(
- @RequestBody DecisionRequestParameters decisionRequestParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- DecisionResponse decisionResponse = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "getDecision")) {
- GetDecisionService getDecisionService = new GetDecisionService(
- decisionRequestParameters, requestID);
- decisionResponse = getDecisionService.getResult();
- status = getDecisionService.getResponseCode();
- }
- decisionCounter.incrementAndGet();
- return new ResponseEntity<>(decisionResponse, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the Decision using specified decision parameters")
+ @RequestMapping(value = "/getDecision", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<DecisionResponse> getDecision(
+ @RequestBody DecisionRequestParameters decisionRequestParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ DecisionResponse decisionResponse = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getDecision")) {
+ GetDecisionService getDecisionService = new GetDecisionService(decisionRequestParameters, requestID);
+ decisionResponse = getDecisionService.getResult();
+ status = getDecisionService.getResponseCode();
+ }
+ decisionCounter.incrementAndGet();
+ return new ResponseEntity<>(decisionResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Pushes the specified policy to the PDP Group.")
- @RequestMapping(value = "/pushPolicy", method = RequestMethod.PUT)
- @ResponseBody
- public ResponseEntity<String> pushPolicy(
- @RequestBody PushPolicyParameters pushPolicyParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth
- .checkPermissions(clientEncoding, requestID, "pushPolicy")) {
- PushPolicyService pushPolicyService = new PushPolicyService(
- pushPolicyParameters, requestID);
- response = pushPolicyService.getResult();
- status = pushPolicyService.getResponseCode();
- }
- pushCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Pushes the specified policy to the PDP Group.")
+ @RequestMapping(value = "/pushPolicy", method = RequestMethod.PUT)
+ @ResponseBody
+ public ResponseEntity<String> pushPolicy(@RequestBody PushPolicyParameters pushPolicyParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "pushPolicy")) {
+ PushPolicyService pushPolicyService = new PushPolicyService(pushPolicyParameters, requestID);
+ response = pushPolicyService.getResult();
+ status = pushPolicyService.getResponseCode();
+ }
+ pushCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Deletes the specified policy from the PDP Group or PAP.")
- @RequestMapping(value = "/deletePolicy", method = RequestMethod.DELETE)
- @ResponseBody
- public ResponseEntity<String> deletePolicy(
- @RequestBody DeletePolicyParameters deletePolicyParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "deletePolicy")) {
- DeletePolicyService deletePolicyService = new DeletePolicyService(
- deletePolicyParameters, requestID);
- response = deletePolicyService.getResult();
- status = deletePolicyService.getResponseCode();
- }
- deleteCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Deletes the specified policy from the PDP Group or PAP.")
+ @RequestMapping(value = "/deletePolicy", method = RequestMethod.DELETE)
+ @ResponseBody
+ public ResponseEntity<String> deletePolicy(@RequestBody DeletePolicyParameters deletePolicyParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "deletePolicy")) {
+ DeletePolicyService deletePolicyService = new DeletePolicyService(deletePolicyParameters, requestID);
+ response = deletePolicyService.getResult();
+ status = deletePolicyService.getResponseCode();
+ }
+ deleteCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Creates a Policy based on given Policy Parameters.")
- @RequestMapping(value = "/createPolicy", method = RequestMethod.PUT)
- @ResponseBody
- public ResponseEntity<String> createPolicy(
- @RequestBody PolicyParameters policyParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "createPolicy")) {
- CreateUpdatePolicyService createPolicyService;
- try {
- createPolicyService = (CreateUpdatePolicyService) XACMLPdpServlet.getCreateUpdatePolicyConstructor().newInstance(
- policyParameters, requestID, false);
- response = createPolicyService.getResult();
- status = createPolicyService.getResponseCode();
- } catch (InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- logger.error(e.getMessage(), e);
- response = "Problem with CreateUpdate Policy Service. ";
- status = HttpStatus.INTERNAL_SERVER_ERROR;
- }
- }
- createPolicyCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Creates a Policy based on given Policy Parameters.")
+ @RequestMapping(value = "/createPolicy", method = RequestMethod.PUT)
+ @ResponseBody
+ public ResponseEntity<String> createPolicy(@RequestBody PolicyParameters policyParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "createPolicy")) {
+ CreateUpdatePolicyService createPolicyService;
+ try {
+ createPolicyService = (CreateUpdatePolicyService) XACMLPdpServlet.getCreateUpdatePolicyConstructor()
+ .newInstance(policyParameters, requestID, false);
+ response = createPolicyService.getResult();
+ status = createPolicyService.getResponseCode();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ logger.error(e.getMessage(), e);
+ response = "Problem with CreateUpdate Policy Service. ";
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
+ }
+ }
+ createPolicyCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Updates a Policy based on given Policy Parameters.")
- @RequestMapping(value = "/updatePolicy", method = RequestMethod.PUT)
- @ResponseBody
- public ResponseEntity<String> updatePolicy(
- @RequestBody PolicyParameters policyParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "updatePolicy")) {
- CreateUpdatePolicyService updatePolicyService;
- try {
- updatePolicyService = (CreateUpdatePolicyService) XACMLPdpServlet.getCreateUpdatePolicyConstructor().newInstance(
- policyParameters, requestID, true);
- response = updatePolicyService.getResult();
- status = updatePolicyService.getResponseCode();
- } catch (InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- logger.error(e.getMessage(), e);
- response = "Problem with CreateUpdate Policy Service. ";
- status = HttpStatus.INTERNAL_SERVER_ERROR;
- }
- }
- updatePolicyCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Updates a Policy based on given Policy Parameters.")
+ @RequestMapping(value = "/updatePolicy", method = RequestMethod.PUT)
+ @ResponseBody
+ public ResponseEntity<String> updatePolicy(@RequestBody PolicyParameters policyParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "updatePolicy")) {
+ CreateUpdatePolicyService updatePolicyService;
+ try {
+ updatePolicyService = (CreateUpdatePolicyService) XACMLPdpServlet.getCreateUpdatePolicyConstructor()
+ .newInstance(policyParameters, requestID, true);
+ response = updatePolicyService.getResult();
+ status = updatePolicyService.getResponseCode();
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ logger.error(e.getMessage(), e);
+ response = "Problem with CreateUpdate Policy Service. ";
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
+ }
+ }
+ updatePolicyCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Creates a Dictionary Item for a specific dictionary based on given Parameters.")
- @RequestMapping(value = "/createDictionaryItem", method = RequestMethod.PUT)
- @ResponseBody
- public ResponseEntity<String> createDictionaryItem(
- @RequestBody DictionaryParameters dictionaryParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "createDictionary")) {
- CreateUpdateDictionaryService createDictionaryService = new CreateUpdateDictionaryService(
- dictionaryParameters, requestID, false);
- response = createDictionaryService.getResult();
- status = createDictionaryService.getResponseCode();
- }
- createDictionaryCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Creates a Dictionary Item for a specific dictionary based on given Parameters.")
+ @RequestMapping(value = "/createDictionaryItem", method = RequestMethod.PUT)
+ @ResponseBody
+ public ResponseEntity<String> createDictionaryItem(@RequestBody DictionaryParameters dictionaryParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "createDictionary")) {
+ CreateUpdateDictionaryService createDictionaryService =
+ new CreateUpdateDictionaryService(dictionaryParameters, requestID, false);
+ response = createDictionaryService.getResult();
+ status = createDictionaryService.getResponseCode();
+ }
+ createDictionaryCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Updates a Dictionary Item for a specific dictionary based on given Parameters.")
- @RequestMapping(value = "/updateDictionaryItem", method = RequestMethod.PUT)
- @ResponseBody
- public ResponseEntity<String> updateDictionaryItem(
- @RequestBody DictionaryParameters dictionaryParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "updateDictionary")) {
- CreateUpdateDictionaryService updateDictionaryService = new CreateUpdateDictionaryService(
- dictionaryParameters, requestID, true);
- response = updateDictionaryService.getResult();
- status = updateDictionaryService.getResponseCode();
- }
- updateDictionaryCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Updates a Dictionary Item for a specific dictionary based on given Parameters.")
+ @RequestMapping(value = "/updateDictionaryItem", method = RequestMethod.PUT)
+ @ResponseBody
+ public ResponseEntity<String> updateDictionaryItem(@RequestBody DictionaryParameters dictionaryParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "updateDictionary")) {
+ CreateUpdateDictionaryService updateDictionaryService =
+ new CreateUpdateDictionaryService(dictionaryParameters, requestID, true);
+ response = updateDictionaryService.getResult();
+ status = updateDictionaryService.getResponseCode();
+ }
+ updateDictionaryCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Gets the dictionary items from the PAP")
- @RequestMapping(value = "/getDictionaryItems", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<DictionaryResponse> getDictionaryItems(
- @RequestBody DictionaryParameters dictionaryParameters,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- DictionaryResponse dictionaryResponse = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "getDictionary")) {
- GetDictionaryService getDictionaryService = new GetDictionaryService(
- dictionaryParameters, requestID);
- dictionaryResponse = getDictionaryService.getResult();
- status = getDictionaryService.getResponseCode();
- }
- getDictionaryCounter.incrementAndGet();
- return new ResponseEntity<>(dictionaryResponse,
- status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Gets the dictionary items from the PAP")
+ @RequestMapping(value = "/getDictionaryItems", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<DictionaryResponse> getDictionaryItems(@RequestBody DictionaryParameters dictionaryParameters,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ DictionaryResponse dictionaryResponse = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "getDictionary")) {
+ GetDictionaryService getDictionaryService = new GetDictionaryService(dictionaryParameters, requestID);
+ dictionaryResponse = getDictionaryService.getResult();
+ status = getDictionaryService.getResponseCode();
+ }
+ getDictionaryCounter.incrementAndGet();
+ return new ResponseEntity<>(dictionaryResponse, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Imports Policy based on the parameters which represent the service used to create a policy Service.")
- @RequestMapping(value = "/policyEngineImport", method = RequestMethod.POST)
- @ResponseBody
- public ResponseEntity<String> policyEngineImport(
- @RequestParam("importParametersJson") String importParametersJson,
- @RequestParam("file") MultipartFile file,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "policyEngineImport")) {
- PolicyEngineImportService policyEngineImportService = new PolicyEngineImportService(
- importParametersJson, file, requestID);
- response = policyEngineImportService.getResult();
- status = policyEngineImportService.getResponseCode();
- }
- policyEngineImportCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(
+ value = "Imports Policy based on the parameters which represent the service used to create a policy Service.")
+ @RequestMapping(value = "/policyEngineImport", method = RequestMethod.POST)
+ @ResponseBody
+ public ResponseEntity<String> policyEngineImport(@RequestParam("importParametersJson") String importParametersJson,
+ @RequestParam("file") MultipartFile file,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "policyEngineImport")) {
+ PolicyEngineImportService policyEngineImportService =
+ new PolicyEngineImportService(importParametersJson, file, requestID);
+ response = policyEngineImportService.getResult();
+ status = policyEngineImportService.getResponseCode();
+ }
+ policyEngineImportCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Creates a Config Policy based on given Policy Parameters.")
- @RequestMapping(value = "/createConfig", method = RequestMethod.PUT)
- @ResponseBody
- @Deprecated
- public ResponseEntity<String> createConfig(
- @RequestBody ConfigPolicyAPIRequest configPolicyAPIRequest,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "createPolicy")) {
- CreateUpdateConfigPolicyService createPolicyService = new CreateUpdateConfigPolicyService(
- configPolicyAPIRequest, requestID, false);
- response = createPolicyService.getResult();
- status = createPolicyService.getResponseCode();
- }
- deprecatedCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Creates a Config Policy based on given Policy Parameters.")
+ @RequestMapping(value = "/createConfig", method = RequestMethod.PUT)
+ @ResponseBody
+ @Deprecated
+ public ResponseEntity<String> createConfig(@RequestBody ConfigPolicyAPIRequest configPolicyAPIRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "createPolicy")) {
+ CreateUpdateConfigPolicyService createPolicyService =
+ new CreateUpdateConfigPolicyService(configPolicyAPIRequest, requestID, false);
+ response = createPolicyService.getResult();
+ status = createPolicyService.getResponseCode();
+ }
+ deprecatedCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Updates a Config Policy based on given Policy Parameters.")
- @RequestMapping(value = "/updateConfig", method = RequestMethod.PUT)
- @ResponseBody
- @Deprecated
- public ResponseEntity<String> updateConfig(
- @RequestBody ConfigPolicyAPIRequest configPolicyAPIRequest,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "updatePolicy")) {
- CreateUpdateConfigPolicyService updatePolicyService = new CreateUpdateConfigPolicyService(
- configPolicyAPIRequest, requestID, true);
- response = updatePolicyService.getResult();
- status = updatePolicyService.getResponseCode();
- }
- deprecatedCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Updates a Config Policy based on given Policy Parameters.")
+ @RequestMapping(value = "/updateConfig", method = RequestMethod.PUT)
+ @ResponseBody
+ @Deprecated
+ public ResponseEntity<String> updateConfig(@RequestBody ConfigPolicyAPIRequest configPolicyAPIRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "updatePolicy")) {
+ CreateUpdateConfigPolicyService updatePolicyService =
+ new CreateUpdateConfigPolicyService(configPolicyAPIRequest, requestID, true);
+ response = updatePolicyService.getResult();
+ status = updatePolicyService.getResponseCode();
+ }
+ deprecatedCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Creates a Config Firewall Policy")
- @RequestMapping(value = "/createFirewallConfig", method = RequestMethod.PUT)
- @ResponseBody
- @Deprecated
- public ResponseEntity<String> createFirewallConfig(
- @RequestBody ConfigFirewallPolicyAPIRequest configFirewallPolicyAPIRequest,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "createPolicy")) {
- CreateUpdateFirewallPolicyService createFirewallPolicyService = new CreateUpdateFirewallPolicyService(
- configFirewallPolicyAPIRequest, requestID, false);
- response = createFirewallPolicyService.getResult();
- status = createFirewallPolicyService.getResponseCode();
- }
- deprecatedCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Creates a Config Firewall Policy")
+ @RequestMapping(value = "/createFirewallConfig", method = RequestMethod.PUT)
+ @ResponseBody
+ @Deprecated
+ public ResponseEntity<String> createFirewallConfig(
+ @RequestBody ConfigFirewallPolicyAPIRequest configFirewallPolicyAPIRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "createPolicy")) {
+ CreateUpdateFirewallPolicyService createFirewallPolicyService =
+ new CreateUpdateFirewallPolicyService(configFirewallPolicyAPIRequest, requestID, false);
+ response = createFirewallPolicyService.getResult();
+ status = createFirewallPolicyService.getResponseCode();
+ }
+ deprecatedCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiImplicitParams({
- @ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
- @ApiImplicitParam(name = "Environment", required = true, paramType = "Header") })
- @ApiOperation(value = "Updates a Config Firewall Policy")
- @RequestMapping(value = "/updateFirewallConfig", method = RequestMethod.PUT)
- @ResponseBody
- @Deprecated
- public ResponseEntity<String> updateFirewallConfig(
- @RequestBody ConfigFirewallPolicyAPIRequest configFirewallPolicyAPIRequest,
- @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
- @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
- String response = null;
- HttpStatus status = HttpStatus.UNAUTHORIZED;
- // Check Permissions.
- if (PDPApiAuth.checkPermissions(clientEncoding, requestID,
- "updatePolicy")) {
- CreateUpdateFirewallPolicyService updateFirewallPolicyService = new CreateUpdateFirewallPolicyService(
- configFirewallPolicyAPIRequest, requestID, true);
- response = updateFirewallPolicyService.getResult();
- status = updateFirewallPolicyService.getResponseCode();
- }
- deprecatedCounter.incrementAndGet();
- return new ResponseEntity<>(response, status);
- }
+ @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true, paramType = "Header"),
+ @ApiImplicitParam(name = "Environment", required = true, paramType = "Header")})
+ @ApiOperation(value = "Updates a Config Firewall Policy")
+ @RequestMapping(value = "/updateFirewallConfig", method = RequestMethod.PUT)
+ @ResponseBody
+ @Deprecated
+ public ResponseEntity<String> updateFirewallConfig(
+ @RequestBody ConfigFirewallPolicyAPIRequest configFirewallPolicyAPIRequest,
+ @RequestHeader(value = "ClientAuth", required = true) String clientEncoding,
+ @RequestHeader(value = "X-ECOMP-RequestID", required = false) String requestID) {
+ String response = null;
+ HttpStatus status = HttpStatus.UNAUTHORIZED;
+ // Check Permissions.
+ if (PDPApiAuth.checkPermissions(clientEncoding, requestID, "updatePolicy")) {
+ CreateUpdateFirewallPolicyService updateFirewallPolicyService =
+ new CreateUpdateFirewallPolicyService(configFirewallPolicyAPIRequest, requestID, true);
+ response = updateFirewallPolicyService.getResult();
+ status = updateFirewallPolicyService.getResponseCode();
+ }
+ deprecatedCounter.incrementAndGet();
+ return new ResponseEntity<>(response, status);
+ }
- @ApiOperation(value = "Gets the API Services usage Information")
- @ApiIgnore
- @RequestMapping(value = "/count", method = RequestMethod.GET)
- public String getCount() {
- return "Total Config Calls : " + configCounter + "\n"
- + "Total Config calls made using Policy File Name: "
- + configNameCounter + "\n" + "Total Event Calls : "
- + eventCounter + "\nTotal Decision Calls: " + decisionCounter
- + "\nTotal Push policy Calls: " + pushCounter
- + "\nTotal Delete Policy Calls: " + deleteCounter
- + "\nTotal Create Policy Calls: " + createPolicyCounter
- + "\nTotal Update Policy Calls: " + updatePolicyCounter
- + "\nTotal Create Dictionary Calls: " + createDictionaryCounter
- + "\nTotal Update Dictionary Calls: " + updateDictionaryCounter
- + "\nTotal Get Dictionary Calls: " + getDictionaryCounter
- + "\nTotal PolicyEngine Import Calls: "
- + policyEngineImportCounter
- + "\nTotal Deprecated Policy Calls: " + deprecatedCounter
- + "\nTotal Metrics Calls:" + metricCounter
- + "\nTotal Notification Calls:" + notificationCounter;
- }
+ @ApiOperation(value = "Gets the API Services usage Information")
+ @ApiIgnore
+ @RequestMapping(value = "/count", method = RequestMethod.GET)
+ public String getCount() {
+ return "Total Config Calls : " + configCounter + "\n" + "Total Config calls made using Policy File Name: "
+ + configNameCounter + "\n" + "Total Event Calls : " + eventCounter + "\nTotal Decision Calls: "
+ + decisionCounter + "\nTotal Push policy Calls: " + pushCounter + "\nTotal Delete Policy Calls: "
+ + deleteCounter + "\nTotal Create Policy Calls: " + createPolicyCounter
+ + "\nTotal Update Policy Calls: " + updatePolicyCounter + "\nTotal Create Dictionary Calls: "
+ + createDictionaryCounter + "\nTotal Update Dictionary Calls: " + updateDictionaryCounter
+ + "\nTotal Get Dictionary Calls: " + getDictionaryCounter + "\nTotal PolicyEngine Import Calls: "
+ + policyEngineImportCounter + "\nTotal Deprecated Policy Calls: " + deprecatedCounter
+ + "\nTotal Metrics Calls:" + metricCounter + "\nTotal Notification Calls:" + notificationCounter;
+ }
- @ExceptionHandler({ HttpMessageNotReadableException.class })
- public ResponseEntity<String> messageNotReadableExceptionHandler(
- HttpServletRequest req, HttpMessageNotReadableException exception) {
- logger.error("Request not readable: {}", exception);
- StringBuilder message = new StringBuilder();
- message.append(exception.getMessage());
- if (exception.getCause() != null) {
- message.append(" Reason Caused: "
- + exception.getCause().getMessage());
- }
- return new ResponseEntity<>(message.toString(), HttpStatus.BAD_REQUEST);
- }
+ @ExceptionHandler({HttpMessageNotReadableException.class})
+ public ResponseEntity<String> messageNotReadableExceptionHandler(HttpServletRequest req,
+ HttpMessageNotReadableException exception) {
+ logger.error("Request not readable: {}", exception);
+ StringBuilder message = new StringBuilder();
+ message.append(exception.getMessage());
+ if (exception.getCause() != null) {
+ message.append(" Reason Caused: " + exception.getCause().getMessage());
+ }
+ return new ResponseEntity<>(message.toString(), HttpStatus.BAD_REQUEST);
+ }
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ListPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ListPolicyService.java
new file mode 100644
index 000000000..cbb2d6f37
--- /dev/null
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ListPolicyService.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PDP-REST
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.rest.api.services;
+
+import com.att.research.xacml.api.pap.PAPException;
+import com.att.research.xacml.util.XACMLProperties;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.onap.policy.api.ConfigNameRequest;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.pdp.rest.XACMLPdpLoader;
+import org.springframework.http.HttpStatus;
+
+
+public class ListPolicyService {
+
+ private static Logger logger = FlexLogger.getLogger(ListPolicyService.class.getName());
+
+ private Collection<String> results = null;
+ private HttpStatus status = HttpStatus.BAD_REQUEST;
+ private ConfigNameRequest configRequestParameters = null;
+ private String requestId = null;
+
+
+ public ListPolicyService() {
+ // Default Constructor
+ }
+
+ /**
+ * Instantiates a new list policy service.
+ *
+ * @param configRequestParameters the config request parameters
+ */
+ public ListPolicyService(final ConfigNameRequest configRequestParameters) {
+ requestId = UUID.randomUUID().toString();
+ this.configRequestParameters = configRequestParameters;
+
+ try {
+ run();
+ } catch (Exception e) {
+ logger.warn("ListPolicy - ERROR for request - " + requestId + ", " + e);
+ status = HttpStatus.BAD_REQUEST;
+ results = null;
+ }
+
+ logger.info("Result for listPolicy - " + configRequestParameters + ", for request - " + requestId
+ + " - Response - " + results);
+ }
+
+ private void run() throws PAPException, IOException {
+ Properties currentProperties = new Properties();
+ try (InputStream is = Files.newInputStream(XACMLPdpLoader.getPDPPolicyCache())) {
+ currentProperties.load(is);
+ }
+
+ Set<String> listOfPolicies = XACMLProperties.getRootPolicyIDs(currentProperties);
+ results = filterList(listOfPolicies, configRequestParameters.getPolicyName());
+ status = HttpStatus.OK;
+
+ }
+
+ private List<String> filterList(Set<String> list, String regex) {
+ return list.stream().filter(s -> s.matches(regex)).collect(Collectors.toList());
+ }
+
+ public Collection<String> getResult() {
+ return results;
+ }
+
+ public HttpStatus getResponseCode() {
+ return status;
+ }
+
+}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
index 471f1a9a2..f6513d14b 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
-
+import com.att.research.xacml.util.XACMLProperties;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -33,11 +33,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.ConfigNameRequest;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DecisionRequestParameters;
import org.onap.policy.api.DeletePolicyCondition;
@@ -52,7 +52,6 @@ import org.onap.policy.api.PolicyType;
import org.onap.policy.api.PushPolicyParameters;
import org.onap.policy.pdp.rest.XACMLPdpServlet;
import org.onap.policy.pdp.rest.api.models.ConfigFirewallPolicyAPIRequest;
-import org.onap.policy.pdp.rest.api.models.ConfigNameRequest;
import org.onap.policy.pdp.rest.api.models.ConfigPolicyAPIRequest;
import org.onap.policy.pdp.rest.api.services.CreateUpdatePolicyServiceImpl;
import org.onap.policy.pdp.rest.api.services.NotificationService;
@@ -67,772 +66,871 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
-import com.att.research.xacml.util.XACMLProperties;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {PDPRestConfig.class})
@WebAppConfiguration
public class PolicyEngineServicesTest {
- private static final String CLIENTAUTHHEADER = "ClientAuth";
- private static final String UUIDHEADER = "X-ECOMP-RequestID";
- // This value is as per test resource code. Don't change this.
- private static final String CLIENTAUTHVALUE = "Basic cHl0aG9uOnRlc3Q=";
- private static final String ERRORCLIENTVALUE = "Basic dGVzdDp0ZXN0MTIz";
-
- private MockMvc mockMvc;
- private HttpHeaders headers;
-
- @Autowired
- private WebApplicationContext webApplicationContext;
-
- @Before()
- public void setup() throws IOException{
- headers = new HttpHeaders();
- headers.add(CLIENTAUTHHEADER, CLIENTAUTHVALUE);
- XACMLProperties.reloadProperties();
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/pass.xacml.pdp.properties");
- XACMLProperties.getProperties();
- this.mockMvc = webAppContextSetup(webApplicationContext).build();
- }
-
- @Test
- public void getConfigAPIFailureTest() throws Exception{
- ConfigRequestParameters pep = new ConfigRequestParameters();
- pep.setPolicyName(".*");
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().is(400));
- // Authorization tests.
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
- .andExpect(status().isUnauthorized());
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
- .andExpect(status().isUnauthorized());
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ERRORCLIENTVALUE))
- .andExpect(status().isUnauthorized());
- // Set wrong request.
- pep.setPolicyName(null);
- pep.setConfigName("test");
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, "123").contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isBadRequest());
- }
-
- @Test
- public void getConfigServiceTest() throws Exception{
- ConfigRequestParameters pep = new ConfigRequestParameters();
- pep.setPolicyName(".*");
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk());
- // Without policyName and using onapName and other fields.
- pep.setPolicyName(null);
- pep.setOnapName("test");
- pep.setConfigName("test");
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk());
- // with config attributes.
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("test", "test");
- pep.setConfigAttributes(configAttributes);
- pep.makeUnique(true);
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk());
- }
-
- @Test
- public void getConfigByPolicyNameTest() throws Exception{
- ConfigNameRequest pep = new ConfigNameRequest();
- pep.setPolicyName(".*");
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().is(400));
- // Authorization tests.
- mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
- .andExpect(status().isUnauthorized());
- mockMvc.perform(post("/getConfigByPolicyName").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk());
- }
-
- @Test
- public void listConfigTest() throws Exception{
- ConfigRequestParameters pep = new ConfigRequestParameters();
- pep.setPolicyName(".*");
- mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().is(400));
- // Authorization tests.
- mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
- .andExpect(status().isUnauthorized());
- mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk());
- }
-
- @Test
- public void getMetricsTest() throws Exception{
- //Failure Tests.
- mockMvc.perform(get("/getMetrics")).andExpect(status().isBadRequest());
- mockMvc.perform(get("/getMetrics").header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
- mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- mockMvc.perform(get("/getMetrics").headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void getNotificationAuthFailureTest() throws Exception{
- mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "").content("test")).andExpect(status().isUnauthorized());
- mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "Basic test123").content("test")).andExpect(status().isUnauthorized());
- mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, ERRORCLIENTVALUE).content(" ")).andExpect(status().isUnauthorized());
- }
-
- @Test
- public void getNotificationTopicFailureTest() throws Exception{
- mockMvc.perform(post("/getNotification")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/getNotification").headers(headers).content("")).andExpect(status().isBadRequest());
- }
-
- @Test
- public void getNotificationTopicValidFailTest() throws Exception{
- // Check failures.
- mockMvc.perform(post("/getNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/stopNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/sendHeartbeat").headers(headers).content(" ")).andExpect(status().isBadRequest());
- }
-
- @Test
- public void getNotificationTopicValidPassTest() throws Exception{
- // Values can be polluted due to failure tests and need to be reloaded.
- XACMLProperties.reloadProperties();
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/notification.xacml.pdp.properties");
+ private static final String CLIENTAUTHHEADER = "ClientAuth";
+ private static final String UUIDHEADER = "X-ECOMP-RequestID";
+ // This value is as per test resource code. Don't change this.
+ private static final String CLIENTAUTHVALUE = "Basic cHl0aG9uOnRlc3Q=";
+ private static final String ERRORCLIENTVALUE = "Basic dGVzdDp0ZXN0MTIz";
+
+ private MockMvc mockMvc;
+ private HttpHeaders headers;
+
+ @Autowired
+ private WebApplicationContext webApplicationContext;
+
+ @Before()
+ public void setup() throws IOException {
+ headers = new HttpHeaders();
+ headers.add(CLIENTAUTHHEADER, CLIENTAUTHVALUE);
+ XACMLProperties.reloadProperties();
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/pass.xacml.pdp.properties");
+ XACMLProperties.getProperties();
+ this.mockMvc = webAppContextSetup(webApplicationContext).build();
+ }
+
+ @Test
+ public void getConfigAPIFailureTest() throws Exception {
+ ConfigRequestParameters pep = new ConfigRequestParameters();
+ pep.setPolicyName(".*");
+ mockMvc.perform(
+ post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().is(400));
+ // Authorization tests.
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ERRORCLIENTVALUE))
+ .andExpect(status().isUnauthorized());
+ // Set wrong request.
+ pep.setPolicyName(null);
+ pep.setConfigName("test");
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, "123").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void getConfigServiceTest() throws Exception {
+ ConfigRequestParameters pep = new ConfigRequestParameters();
+ pep.setPolicyName(".*");
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk());
+ // Without policyName and using onapName and other fields.
+ pep.setPolicyName(null);
+ pep.setOnapName("test");
+ pep.setConfigName("test");
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
+ // with config attributes.
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("test", "test");
+ pep.setConfigAttributes(configAttributes);
+ pep.makeUnique(true);
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
+ }
+
+ @Test
+ public void getConfigByPolicyNameTest() throws Exception {
+ ConfigNameRequest pep = new ConfigNameRequest();
+ pep.setPolicyName(".*");
+ mockMvc.perform(
+ post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().is(400));
+ // Authorization tests.
+ mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/getConfigByPolicyName").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void listConfigTest() throws Exception {
+ ConfigRequestParameters pep = new ConfigRequestParameters();
+ pep.setPolicyName(".*");
+ mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(400));
+ // Authorization tests.
+ mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void listPolicyTest() throws Exception {
+ ConfigNameRequest pep = new ConfigNameRequest();
+ pep.setPolicyName(".*");
+ mockMvc.perform(post("/listPolicy").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk());
+ pep.setPolicyName("*");
+ mockMvc.perform(post("/listPolicy").content(PolicyUtils.objectToJsonString(pep)).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().is4xxClientError());
+ }
+
+ @Test
+ public void getMetricsTest() throws Exception {
+ // Failure Tests.
+ mockMvc.perform(get("/getMetrics")).andExpect(status().isBadRequest());
+ mockMvc.perform(get("/getMetrics").header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, "123"))
+ .andExpect(status().isBadRequest());
+ mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ mockMvc.perform(get("/getMetrics").headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void getNotificationAuthFailureTest() throws Exception {
+ mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "").content("test"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "Basic test123").content("test"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, ERRORCLIENTVALUE).content(" "))
+ .andExpect(status().isUnauthorized());
+ }
+
+ @Test
+ public void getNotificationTopicFailureTest() throws Exception {
+ mockMvc.perform(post("/getNotification")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/getNotification").headers(headers).content("")).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void getNotificationTopicValidFailTest() throws Exception {
+ // Check failures.
+ mockMvc.perform(post("/getNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/stopNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/sendHeartbeat").headers(headers).content(" ")).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void getNotificationTopicValidPassTest() throws Exception {
+ // Values can be polluted due to failure tests and need to be reloaded.
+ XACMLProperties.reloadProperties();
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,
+ "src/test/resources/notification.xacml.pdp.properties");
XACMLProperties.getProperties();
NotificationService.reloadProps();
- // Add a Topic.
- mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, "123").content("test")).andExpect(status().isOk());
- // Try to add same topic should fail.
- mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, UUID.randomUUID()).content("test")).andExpect(status().isBadRequest());
- // do a heart beat.
- mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isOk());
- // remove the added Topic.
- mockMvc.perform(post("/stopNotification").headers(headers).content("test")).andExpect(status().isOk());
- // try to remove again should fail.
- mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isBadRequest());
- }
-
- @Test
- public void sendEventTest() throws Exception{
- EventRequestParameters pep = new EventRequestParameters();
- Map<String,String> eventAttributes = new HashMap<>();
- eventAttributes.put("TEST", "test");
- pep.setEventAttributes(eventAttributes);
- //Failure Tests.
- mockMvc.perform(post("/sendEvent")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
- pep.setEventAttributes(null);
- mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setEventAttributes(eventAttributes);
- mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isOk());
- pep.setEventAttributes(eventAttributes);
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isOk());
- }
-
- @Test
- public void getDecisionTest() throws Exception{
- DecisionRequestParameters pep = new DecisionRequestParameters();
- Map<String,String> eventAttributes = new HashMap<>();
- eventAttributes.put("TEST", "test");
- pep.setOnapName("te123");
- pep.setDecisionAttributes(eventAttributes);
- //Failure Tests.
- mockMvc.perform(post("/getDecision")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
- pep.setDecisionAttributes(null);
- pep.setOnapName(null);
- mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setOnapName("testing");
- mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setDecisionAttributes(eventAttributes);
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isOk());
- }
-
- @Test
- public void pushPolicyTest() throws Exception{
- PushPolicyParameters pep = new PushPolicyParameters();
- //Failure Tests.
- mockMvc.perform(put("/pushPolicy")).andExpect(status().isBadRequest());
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("scopeless");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyName("testing.test");
- pep.setPolicyType("wrong");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("BRMS_PARAM");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("BRMS_RAW");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("MicroService");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("ClosedLoop_PM");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("ClosedLoop_Fault");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("Base");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("Decision");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("Action");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("Firewall");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPdpGroup("default");
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void deletePolicyTest() throws Exception{
- DeletePolicyParameters pep = new DeletePolicyParameters();
- //Failure Tests.
- mockMvc.perform(delete("/deletePolicy")).andExpect(status().isBadRequest());
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("testing");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "test123")).andExpect(status().isBadRequest());
- pep.setPolicyName("testscope.name");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyName("testscope.name");
- pep.setPolicyType("wrong");
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("BRMS_PARAM");
- pep.setPolicyComponent("wrong");
- pep.setRequestID(null);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyType("BRMS_RAW");
- pep.setPolicyComponent("PDP");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("MicroService");
- pep.setPolicyComponent("PAP");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("ClosedLoop_PM");
- pep.setPolicyComponent("PDP");
- pep.setDeleteCondition(DeletePolicyCondition.ALL);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("ClosedLoop_Fault");
- pep.setDeleteCondition(DeletePolicyCondition.ONE);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("Base");
- pep.setPolicyComponent("PAP");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("Decision");
- pep.setPolicyComponent("PDP");
- pep.setPolicyName("test.xml");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyType("Action");
- pep.setPolicyName("scope.Config_test.xml");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPdpGroup("default");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyComponent("PAP");
- pep.setPolicyType("Firewall");
- pep.setDeleteCondition(null);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyComponent("PAP");
- pep.setDeleteCondition(DeletePolicyCondition.ONE);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyComponent("fail");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyComponent("PDP");
- pep.setPolicyName("testscope.policyName");
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyComponent(null);
- mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- }
-
- @Test
- public void createUpdatePolicyTest() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- //Failure Tests.
- mockMvc.perform(put("/createPolicy")).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- setCreateUpdateImpl();
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("failName");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "test 123")).andExpect(status().isBadRequest());
- pep.setPolicyName("test. name");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setPolicyName(" ");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("test. ");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("te st.name");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("testá");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void brmsPolicyCreationTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for BRMS Param Policy.
- pep.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
- Map<String,String> matching = new HashMap<>();
- matching.put("key", "value");
- attributes.put(AttributeType.MATCHING, matching);
- pep.setAttributes(attributes);
- pep.setRiskLevel("5");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- // Checks for BRMS Raw Policy
- pep.setPolicyConfigType(PolicyConfigType.BRMS_RAW);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel(null);
- pep.setConfigBody("package droolsexample\n\n import com.sample.ItemCity;\nimport java.math.BigDecimal;\nrule \"Nagpur Medicine Item\"\n\n when\n item : ItemCity(purchaseCity == ItemCity.City.NAGPUR,\n typeofItem == ItemCity.Type.MEDICINES)\n then\n BigDecimal tax = new BigDecimal(0.0);\n item.setLocalTax(tax.multiply(item.getSellPrice()));\nend");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("5");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void baseConfigTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for Base config Policy.
- pep.setPolicyConfigType(PolicyConfigType.Base);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("testbody");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBodyType(PolicyType.OTHER);
- pep.setRiskLevel("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("4");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setOnapName("ec nam-e");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setOnapName("onapName");
- pep.setConfigName("tes config");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigName("configName");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{'test':'test}");
- pep.setConfigBodyType(PolicyType.JSON);
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
- Map<String,String> matching = new HashMap<>();
- matching.put("key", "value");
- attributes.put(AttributeType.MATCHING, matching);
- pep.setAttributes(attributes);
- pep.setConfigBody("testBody");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void closedLoopPolicyTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for Closed loop Policy.
- pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("te stá");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("testBody");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"key\":\"value\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"onapname\":\"\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"onapname\":\"test\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("4");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void closedLoopPMTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for Closed loop Policy.
- pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("te stá");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("testBody");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"key\":\"value\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"onapname\":\"\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"onapname\":\"test\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"onapname\":\"test\", \"serviceTypePolicyName\":\"value\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("4");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void firewallPolicyTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for Closed loop Policy.
- pep.setPolicyConfigType(PolicyConfigType.Firewall);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("te st");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"test\":\"test\"}");
- pep.setRiskLevel("test");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("4");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"configName\":\"test\"}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void microServicePolicyTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for Closed loop Policy.
- pep.setPolicyConfigType(PolicyConfigType.MicroService);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("te st");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{}");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"test\":\"test\"}");
- pep.setOnapName(" ");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setOnapName("testonap");
- pep.setRiskLevel("fail");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRiskLevel("4");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setConfigBody("{\"service\":\"test\",\"uuid\":\"test\",\"location\":\"test\",\"configName\":\"test\",\"description\":\"test\",\"priority\":\"test\",\"version\":\"test\"}");
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void actionDecisionPolicyCreationTests() throws Exception{
- PolicyParameters pep = new PolicyParameters();
- pep.setPolicyName("test.name");
- pep.setPolicyDescription("good");
- pep.setTtlDate(new Date());
- pep.setRequestID(UUID.randomUUID());
- setCreateUpdateImpl();
- // Checks for action Policy.
- pep.setPolicyClass(PolicyClass.Action);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
- pep.setAttributes(attributes);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- attributes.put(AttributeType.MATCHING, new HashMap<>());
- pep.setAttributes(attributes);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- Map<String,String> matching = new HashMap<>();
- matching.put("key", "value");
- attributes.put(AttributeType.MATCHING, matching);
- pep.setAttributes(attributes);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setActionAttribute("A1");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setActionPerformer("PEX");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setActionPerformer("PEP");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- // Checks for Decision Policy.
- pep.setPolicyClass(PolicyClass.Decision);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setOnapName("xyz");
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- attributes.remove(AttributeType.MATCHING);
- attributes.put(AttributeType.SETTINGS, matching);
- pep.setAttributes(attributes);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- attributes.put(AttributeType.MATCHING, matching);
- pep.setAttributes(attributes);
- mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void createUpdateDictionaryTests() throws Exception{
- DictionaryParameters pep = new DictionaryParameters();
- //Failure Tests.
- mockMvc.perform(put("/createDictionaryItem")).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setDictionaryType(DictionaryType.MicroService);
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setDictionary("test dict");
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setDictionaryJson("{\"test\":\"value\"}");
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
- pep.setDictionaryJson("test123");
- mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
- pep.setDictionary("MicroServiceDictionary");
- mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void getDictionaryTests() throws Exception{
- DictionaryParameters pep = new DictionaryParameters();
- //Failure Tests.
- mockMvc.perform(post("/getDictionaryItems")).andExpect(status().isBadRequest());
- mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setDictionaryType(DictionaryType.Common);
- mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID().toString())).andExpect(status().isBadRequest());
- pep.setDictionary("OnapName");
- mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- pep.setRequestID(UUID.randomUUID());
- mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isBadRequest());
- }
-
- @Test
- public void policyEngineImportTests() throws Exception{
- //Failure Tests.
- mockMvc.perform(post("/policyEngineImport")).andExpect(status().isBadRequest());
- }
-
- @Test
- public void oldConfigAPITests() throws Exception{
- ConfigPolicyAPIRequest pep = new ConfigPolicyAPIRequest();
- //Failure Tests.
- mockMvc.perform(put("/createConfig")).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setPolicyScope("test");
- mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setPolicyName("name");
- mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setConfigType("OTHER");
- mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setTtlDate(new Date().toString());
- mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- }
-
- @Test
- public void oldFirewallAPITests() throws Exception{
- ConfigFirewallPolicyAPIRequest pep = new ConfigFirewallPolicyAPIRequest();
- //Failure Tests.
- mockMvc.perform(put("/createFirewallConfig")).andExpect(status().isBadRequest());
- mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
- //Service Tests.
- mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setPolicyScope("test");
- mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setPolicyName("name");
- mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- pep.setTtlDate(new Date().toString());
- mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
- }
-
- private void setCreateUpdateImpl() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- Method setter = XACMLPdpServlet.class.getDeclaredMethod("setCreateUpdatePolicyConstructor", String.class);
- setter.setAccessible(true);
- setter.invoke(new XACMLPdpServlet(), CreateUpdatePolicyServiceImpl.class.getName());
- }
-
- //Health Check Tests
- @Test
- public void getCountTest() throws Exception {
- mockMvc.perform(get("/count"))
- .andExpect(status().isOk());
- }
+ // Add a Topic.
+ mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, "123").content("test"))
+ .andExpect(status().isOk());
+ // Try to add same topic should fail.
+ mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, UUID.randomUUID()).content("test"))
+ .andExpect(status().isBadRequest());
+ // do a heart beat.
+ mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isOk());
+ // remove the added Topic.
+ mockMvc.perform(post("/stopNotification").headers(headers).content("test")).andExpect(status().isOk());
+ // try to remove again should fail.
+ mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void sendEventTest() throws Exception {
+ EventRequestParameters pep = new EventRequestParameters();
+ Map<String, String> eventAttributes = new HashMap<>();
+ eventAttributes.put("TEST", "test");
+ pep.setEventAttributes(eventAttributes);
+ // Failure Tests.
+ mockMvc.perform(post("/sendEvent")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "123"))
+ .andExpect(status().isOk());
+ pep.setEventAttributes(null);
+ mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setEventAttributes(eventAttributes);
+ mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isOk());
+ pep.setEventAttributes(eventAttributes);
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isOk());
+ }
+
+ @Test
+ public void getDecisionTest() throws Exception {
+ DecisionRequestParameters pep = new DecisionRequestParameters();
+ Map<String, String> eventAttributes = new HashMap<>();
+ eventAttributes.put("TEST", "test");
+ pep.setOnapName("te123");
+ pep.setDecisionAttributes(eventAttributes);
+ // Failure Tests.
+ mockMvc.perform(post("/getDecision")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "123"))
+ .andExpect(status().isOk());
+ pep.setDecisionAttributes(null);
+ pep.setOnapName(null);
+ mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setOnapName("testing");
+ mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setDecisionAttributes(eventAttributes);
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isOk());
+ }
+
+ @Test
+ public void pushPolicyTest() throws Exception {
+ PushPolicyParameters pep = new PushPolicyParameters();
+ // Failure Tests.
+ mockMvc.perform(put("/pushPolicy")).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("scopeless");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyName("testing.test");
+ pep.setPolicyType("wrong");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("BRMS_PARAM");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("BRMS_RAW");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("MicroService");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("ClosedLoop_PM");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("ClosedLoop_Fault");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("Base");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("Decision");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("Action");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("Firewall");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPdpGroup("default");
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "123"))
+ .andExpect(status().isBadRequest());
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void deletePolicyTest() throws Exception {
+ DeletePolicyParameters pep = new DeletePolicyParameters();
+ // Failure Tests.
+ mockMvc.perform(delete("/deletePolicy")).andExpect(status().isBadRequest());
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("testing");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "test123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("testscope.name");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyName("testscope.name");
+ pep.setPolicyType("wrong");
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("BRMS_PARAM");
+ pep.setPolicyComponent("wrong");
+ pep.setRequestID(null);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyType("BRMS_RAW");
+ pep.setPolicyComponent("PDP");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("MicroService");
+ pep.setPolicyComponent("PAP");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("ClosedLoop_PM");
+ pep.setPolicyComponent("PDP");
+ pep.setDeleteCondition(DeletePolicyCondition.ALL);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("ClosedLoop_Fault");
+ pep.setDeleteCondition(DeletePolicyCondition.ONE);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("Base");
+ pep.setPolicyComponent("PAP");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("Decision");
+ pep.setPolicyComponent("PDP");
+ pep.setPolicyName("test.xml");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyType("Action");
+ pep.setPolicyName("scope.Config_test.xml");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPdpGroup("default");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyComponent("PAP");
+ pep.setPolicyType("Firewall");
+ pep.setDeleteCondition(null);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyComponent("PAP");
+ pep.setDeleteCondition(DeletePolicyCondition.ONE);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyComponent("fail");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyComponent("PDP");
+ pep.setPolicyName("testscope.policyName");
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyComponent(null);
+ mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void createUpdatePolicyTest() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ // Failure Tests.
+ mockMvc.perform(put("/createPolicy")).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ setCreateUpdateImpl();
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("failName");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "test 123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("test. name");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setPolicyName(" ");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("test. ");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("te st.name");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("testá");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void brmsPolicyCreationTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for BRMS Param Policy.
+ pep.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+ Map<String, String> matching = new HashMap<>();
+ matching.put("key", "value");
+ attributes.put(AttributeType.MATCHING, matching);
+ pep.setAttributes(attributes);
+ pep.setRiskLevel("5");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ // Checks for BRMS Raw Policy
+ pep.setPolicyConfigType(PolicyConfigType.BRMS_RAW);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel(null);
+ pep.setConfigBody(
+ "package droolsexample\n\n import com.sample.ItemCity;\nimport java.math.BigDecimal;\nrule \"Nagpur Medicine Item\"\n\n when\n item : ItemCity(purchaseCity == ItemCity.City.NAGPUR,\n typeofItem == ItemCity.Type.MEDICINES)\n then\n BigDecimal tax = new BigDecimal(0.0);\n item.setLocalTax(tax.multiply(item.getSellPrice()));\nend");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("5");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void baseConfigTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for Base config Policy.
+ pep.setPolicyConfigType(PolicyConfigType.Base);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("testbody");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBodyType(PolicyType.OTHER);
+ pep.setRiskLevel("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("4");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setOnapName("ec nam-e");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setOnapName("onapName");
+ pep.setConfigName("tes config");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigName("configName");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{'test':'test}");
+ pep.setConfigBodyType(PolicyType.JSON);
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+ Map<String, String> matching = new HashMap<>();
+ matching.put("key", "value");
+ attributes.put(AttributeType.MATCHING, matching);
+ pep.setAttributes(attributes);
+ pep.setConfigBody("testBody");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void closedLoopPolicyTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for Closed loop Policy.
+ pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("te stá");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("testBody");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"key\":\"value\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"onapname\":\"\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"onapname\":\"test\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("4");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void closedLoopPMTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for Closed loop Policy.
+ pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("te stá");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("testBody");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"key\":\"value\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"onapname\":\"\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"onapname\":\"test\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"onapname\":\"test\", \"serviceTypePolicyName\":\"value\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("4");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void firewallPolicyTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for Closed loop Policy.
+ pep.setPolicyConfigType(PolicyConfigType.Firewall);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("te st");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"test\":\"test\"}");
+ pep.setRiskLevel("test");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("4");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"configName\":\"test\"}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void microServicePolicyTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for Closed loop Policy.
+ pep.setPolicyConfigType(PolicyConfigType.MicroService);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("te st");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{}");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody("{\"test\":\"test\"}");
+ pep.setOnapName(" ");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setOnapName("testonap");
+ pep.setRiskLevel("fail");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRiskLevel("4");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setConfigBody(
+ "{\"service\":\"test\",\"uuid\":\"test\",\"location\":\"test\",\"configName\":\"test\",\"description\":\"test\",\"priority\":\"test\",\"version\":\"test\"}");
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void actionDecisionPolicyCreationTests() throws Exception {
+ PolicyParameters pep = new PolicyParameters();
+ pep.setPolicyName("test.name");
+ pep.setPolicyDescription("good");
+ pep.setTtlDate(new Date());
+ pep.setRequestID(UUID.randomUUID());
+ setCreateUpdateImpl();
+ // Checks for action Policy.
+ pep.setPolicyClass(PolicyClass.Action);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+ pep.setAttributes(attributes);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ attributes.put(AttributeType.MATCHING, new HashMap<>());
+ pep.setAttributes(attributes);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ Map<String, String> matching = new HashMap<>();
+ matching.put("key", "value");
+ attributes.put(AttributeType.MATCHING, matching);
+ pep.setAttributes(attributes);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setActionAttribute("A1");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setActionPerformer("PEX");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setActionPerformer("PEP");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ // Checks for Decision Policy.
+ pep.setPolicyClass(PolicyClass.Decision);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setOnapName("xyz");
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ attributes.remove(AttributeType.MATCHING);
+ attributes.put(AttributeType.SETTINGS, matching);
+ pep.setAttributes(attributes);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ attributes.put(AttributeType.MATCHING, matching);
+ pep.setAttributes(attributes);
+ mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void createUpdateDictionaryTests() throws Exception {
+ DictionaryParameters pep = new DictionaryParameters();
+ // Failure Tests.
+ mockMvc.perform(put("/createDictionaryItem")).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setDictionaryType(DictionaryType.MicroService);
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setDictionary("test dict");
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setDictionaryJson("{\"test\":\"value\"}");
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, UUID.randomUUID()))
+ .andExpect(status().isBadRequest());
+ pep.setDictionaryJson("test123");
+ mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "123"))
+ .andExpect(status().isBadRequest());
+ pep.setDictionary("MicroServiceDictionary");
+ mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void getDictionaryTests() throws Exception {
+ DictionaryParameters pep = new DictionaryParameters();
+ // Failure Tests.
+ mockMvc.perform(post("/getDictionaryItems")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setDictionaryType(DictionaryType.Common);
+ mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)
+ .header(UUIDHEADER, UUID.randomUUID().toString())).andExpect(status().isBadRequest());
+ pep.setDictionary("OnapName");
+ mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ pep.setRequestID(UUID.randomUUID());
+ mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers)).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void policyEngineImportTests() throws Exception {
+ // Failure Tests.
+ mockMvc.perform(post("/policyEngineImport")).andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void oldConfigAPITests() throws Exception {
+ ConfigPolicyAPIRequest pep = new ConfigPolicyAPIRequest();
+ // Failure Tests.
+ mockMvc.perform(put("/createConfig")).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyScope("test");
+ mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("name");
+ mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setConfigType("OTHER");
+ mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setTtlDate(new Date().toString());
+ mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ public void oldFirewallAPITests() throws Exception {
+ ConfigFirewallPolicyAPIRequest pep = new ConfigFirewallPolicyAPIRequest();
+ // Failure Tests.
+ mockMvc.perform(put("/createFirewallConfig")).andExpect(status().isBadRequest());
+ mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
+ .andExpect(status().isUnauthorized());
+ // Service Tests.
+ mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyScope("test");
+ mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setPolicyName("name");
+ mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ pep.setTtlDate(new Date().toString());
+ mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep))
+ .contentType(MediaType.APPLICATION_JSON).headers(headers).header(UUIDHEADER, "tes123"))
+ .andExpect(status().isBadRequest());
+ }
+
+ private void setCreateUpdateImpl() throws NoSuchMethodException, SecurityException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException {
+ Method setter = XACMLPdpServlet.class.getDeclaredMethod("setCreateUpdatePolicyConstructor", String.class);
+ setter.setAccessible(true);
+ setter.invoke(new XACMLPdpServlet(), CreateUpdatePolicyServiceImpl.class.getName());
+ }
+
+ // Health Check Tests
+ @Test
+ public void getCountTest() throws Exception {
+ mockMvc.perform(get("/count")).andExpect(status().isOk());
+ }
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/ConfigNameRequest.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/ConfigNameRequest.java
index 945445991..1a64757ca 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/ConfigNameRequest.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/ConfigNameRequest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,23 +17,32 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.pdp.rest.api.models;
-import io.swagger.annotations.ApiModel;
+package org.onap.policy.api;
+import com.google.gson.Gson;
import java.io.Serializable;
-@ApiModel
-public class ConfigNameRequest implements Serializable{
+public class ConfigNameRequest implements Serializable {
private static final long serialVersionUID = 4487978240532425305L;
-
+
private String policyName = null;
-
+
public void setPolicyName(String policyName) {
this.policyName = policyName;
}
-
+
public String getPolicyName() {
return policyName;
}
+
+ /**
+ * Used to print the input Params for getCOnfig REST call.
+ *
+ * @return JSON String of this object.
+ */
+ @Override
+ public String toString() {
+ return new Gson().toJson(this);
+ }
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngine.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngine.java
index b8b077c99..a664496e7 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngine.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEngine.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineAPI
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,596 +24,705 @@ import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
-
import javax.json.JsonObject;
-
-import org.onap.policy.api.NotificationHandler;
-import org.onap.policy.api.PDPNotification;
import org.onap.policy.std.StdPolicyEngine;
/**
- * PolicyEngine is the Interface that applications use to make policy queries against a PEPEngine
- *
+ * PolicyEngine is the Interface that applications use to make policy queries against a PEPEngine
+ *
* @version 2.0
*/
-public class PolicyEngine{
- private final StdPolicyEngine stdPolicyEngine;
- private NotificationScheme scheme = null;
- private NotificationHandler handler = null;
-
- /**
- * PolicyEngine Constructor with <code>Properties</code> structure
- *
- * @param properties the <code>Properties</code> structure containing the Policy engine parameters
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final Properties properties) throws PolicyEngineException {
- this.stdPolicyEngine= new StdPolicyEngine(properties, (String)null);
- }
-
- /**
- * PolicyEngine Constructor with <code>String</code> format of propertiesFilePathname
- *
- * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final String propertiesFilePathname) throws PolicyEngineException {
- this.stdPolicyEngine= new StdPolicyEngine(propertiesFilePathname, (String)null);
- }
-
- /**
- * PolicyEngine Constructor with <code>Properties</code> structure
- *
- * @param properties the <code>Properties</code> structure containing the Policy engine parameters
- * @param clientKey depicts String format of Password/ Client_Key.
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final Properties properties, final String clientKey) throws PolicyEngineException {
- this.stdPolicyEngine= new StdPolicyEngine(properties, clientKey);
- }
-
- /**
- * PolicyEngine Constructor with <code>String</code> format of propertiesFilePathname
- *
- * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
- * @param clientKey depicts String format of Password/ Client_Key.
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final String propertiesFilePathname, final String clientKey) throws PolicyEngineException {
- this.stdPolicyEngine= new StdPolicyEngine(propertiesFilePathname, clientKey);
- }
-
- /**
- * PolicyEngine Constructor with <code>String</code> format of PropertiesFilePathname and <code>NotificationScheme</code>
- *
- * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
- * @param scheme the <code>NotificationScheme</code> of {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final String propertiesFilePathname, final NotificationScheme scheme) throws PolicyEngineException{
- this.scheme = scheme;
- this.stdPolicyEngine = new StdPolicyEngine(propertiesFilePathname, this.scheme);
- }
-
- /**
- * PolicyEngine Constructor with <code>String</code> format of PropertiesFilePathname, <code>NotificationScheme</code> and <code>NotificationHandler</code>
- *
- * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
- * @param scheme the <code>NotificationScheme</code> of {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
- * @param handler the <code>NotificationHandler</code> of {@link org.onap.policy.api.NotificationHandler} which defines what should happen when a notification is received.
- * @throws PolicyEngineException PolicyEngine Exception
- */
- public PolicyEngine(final String propertiesFilePathname, final NotificationScheme scheme, final NotificationHandler handler) throws PolicyEngineException {
- this.scheme = scheme;
- this.handler = handler;
- this.stdPolicyEngine= new StdPolicyEngine(propertiesFilePathname,this.scheme,this.handler);
- }
-
- /**
- * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which represents the Policy File Name
- *
- * @param policyName the <code>String</code> format of the PolicyFile Name whose configuration is required.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters configRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfigByPolicyName(final String policyName) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(policyName, null, null, null, null));
- }
-
- /**
- * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which represents the Policy File Name
- *
- * @param policyName the <code>String</code> format of the PolicyFile Name whose configuration is required.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters configRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfigByPolicyName(final String policyName, final UUID requestID) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(policyName, null, null, null, requestID));
- }
-
- /**
- * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which represents the onapName
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(null, onapName, null, null, null));
- }
-
- /**
- * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which represents the onapName
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName, final UUID requestID) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(null, onapName, null, null, requestID));
- }
-
- /**
- * Requests the configuration of the <code>String</code> which represents the onapName and <code>String</code>
- * which represents the configName and returns the configuration if different Configurations exist for the
- * particular onapName.
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @param configName the <code>String</code> format of the configurationName whose configuration is required.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName, final String configName) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(null, onapName, configName, null, null));
- }
-
- /**
- * Requests the configuration of the <code>String</code> which represents the onapName and <code>String</code>
- * which represents the configName and returns the configuration if different Configurations exist for the
- * particular onapName.
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @param configName the <code>String</code> format of the configurationName whose configuration is required.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName, final String configName, final UUID requestID) throws PolicyConfigException {
- return getConfig(setConfigRequestParameters(null, onapName, configName, null, requestID));
- }
-
- /**
- * Requests the configuration of the <code>String</code> which represents the onapName, <code>String</code>
- * which represents the configName and <code>Map</code> of <code>String,String</code> which has the configAttribute and returns the specific
- * configuration related to the configAttributes mentioned.
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @param configName the <code>String</code> format of the configurationName whose configuration is required.
- * @param configAttributes the <code>Map</code> of <code>String,String</code> format of the configuration attributes which are required.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName, final String configName, final Map<String, String> configAttributes) throws PolicyConfigException{
- return getConfig(setConfigRequestParameters(null, onapName, configName, configAttributes, null));
- }
-
- /**
- * Requests the configuration of the <code>String</code> which represents the onapName, <code>String</code>
- * which represents the configName and <code>Map</code> of <code>String,String</code> which has the configAttribute and returns the specific
- * configuration related to the configAttributes mentioned.
- *
- * @param onapName the <code>String</code> format of the onapName whose configuration is required.
- * @param configName the <code>String</code> format of the configurationName whose configuration is required.
- * @param configAttributes the <code>Map</code> of <code>String,String</code> format of the configuration attributes which are required.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyConfig> getConfig(final String onapName, final String configName, final Map<String, String> configAttributes, final UUID requestID) throws PolicyConfigException{
- return getConfig(setConfigRequestParameters(null, onapName, configName, configAttributes, requestID));
- }
-
- /**
- * Requests the configuration of the <code>ConfigRequestParameters</code> which represents the Config policy request parameters
- * and returns the specific configuration related to the matching parameters.
- *
- * @param configRequestParameters {@link org.onap.policy.api.ConfigRequestParameters} which represents the Config policy request parameters.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the configuration.
- * @throws PolicyConfigException PolicyConfig Exception
- */
- public Collection<PolicyConfig> getConfig(final ConfigRequestParameters configRequestParameters) throws PolicyConfigException{
- return stdPolicyEngine.getConfig(configRequestParameters);
- }
-
- /**
- * Requests the list of policies based on the <code>ConfigRequestParameters</code> which represents the policy request parameters
- * and returns the list of policies filtered by the parameters.
- *
- * @param configRequestParameters {@link org.onap.policy.api.ConfigRequestParameters} which represents the List Policy request parameters.
- * @return <code>Collection</code> of <code>String</code> which returns the list of policies.
- * @throws PolicyConfigException PolicyConfig Exception
- */
- public Collection<String> listConfig(final ConfigRequestParameters listPolicyRequestParameters) throws PolicyConfigException{
- return stdPolicyEngine.listConfig(listPolicyRequestParameters);
- }
-
-
- /**
- * Sends the Events specified to the PEP and returns back the PolicyResponse.
- *
- * @param eventAttributes the <code>Map</code> of <code>String,String</code> format of the eventAttributes that must contain the event ID and values.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the Response.
- * @throws PolicyEventException PolicyEvent Exception
- * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyResponse> sendEvent(final Map<String, String> eventAttributes) throws PolicyEventException {
- return stdPolicyEngine.sendEvent(eventAttributes, (UUID) null);
- }
-
- /**
- * Sends the Events specified to the PEP and returns back the PolicyResponse.
- *
- * @param eventAttributes the <code>Map</code> of <code>String,String</code> format of the eventAttributes that must contain the event ID and values.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the Response.
- * @throws PolicyEventException PolicyEvent Exception
- * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead.
- */
- @Deprecated
- public Collection<PolicyResponse> sendEvent(final Map<String, String> eventAttributes, final UUID requestID) throws PolicyEventException {
- return stdPolicyEngine.sendEvent(eventAttributes, requestID);
- }
-
- /**
- * Sends the Events specified to the PEP and returns back the PolicyResponse.
- *
- * @param eventRequestParameters {@link org.onap.policy.api.EventRequestParameters} which represents the Event Request Parameters.
- * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the Response.
- * @throws PolicyEventException PolicyEvent Exception
- */
- public Collection<PolicyResponse> sendEvent(final EventRequestParameters eventRequestParameters) throws PolicyEventException {
- return stdPolicyEngine.sendEvent(eventRequestParameters);
- }
-
- /**
- * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
- *
- * @param onapName the <code>String</code> format of the onapName whose Decision is required.
- * @param decisionAttributes the <code>Map</code> of <code>String,String</code> format of the decisionAttributes that must contain the ID and values.
- * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
- * @throws PolicyDecisionException PolicyDecision Exception
- * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead.
- */
- @Deprecated
- public DecisionResponse getDecision(final String onapName, final Map<String,String> decisionAttributes) throws PolicyDecisionException {
- return stdPolicyEngine.getDecision(onapName, decisionAttributes, null);
- }
-
- /**
- * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
- *
- * @param onapName the <code>String</code> format of the onapName whose Decision is required.
- * @param decisionAttributes the <code>Map</code> of <code>String,String</code> format of the decisionAttributes that must contain the ID and values.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
- * @throws PolicyDecisionException PolicyDecision Exception
- * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead.
- */
- @Deprecated
- public DecisionResponse getDecision(final String onapName, final Map<String,String> decisionAttributes, final UUID requestID) throws PolicyDecisionException {
- return stdPolicyEngine.getDecision(onapName, decisionAttributes, requestID);
- }
-
- /**
- * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
- *
- * @param decisionRequestParameters {@link org.onap.policy.api.DecisionRequestParameters} which represents the Decision Request Parameters.
- * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
- * @throws PolicyDecisionException PolicyDecision Exception
- */
- public DecisionResponse getDecision(final DecisionRequestParameters decisionRequestParameters) throws PolicyDecisionException {
- return stdPolicyEngine.getDecision(decisionRequestParameters);
- }
-
- /**
- * Retrieves the count of policies on the PAP, PDP, and Policy Engine as a whole
- *
- * @param parameters {@link org.onap.policy.api.MetricsRequestParameters} which represents the Parameters required to get the Policy Metrics
- * @return {@link org.onap.policy.api.MetricsResponse} which consists of the response related to getMetrics Request.
- * @throws PolicyException PolicyException related to the operation
- *
- * */
- public MetricsResponse getMetrics(final MetricsRequestParameters parameters) throws PolicyException {
- return stdPolicyEngine.getMetrics(parameters);
- }
-
- /**
- * Creates a Config Policy based on given arguments
- * @param policyName the <code>String</code> format of the Policy Name
- * @param policyDescription the <code>String</code> format of the Policy Description
- * @param onapName the <code>String</code> format of the ONAP Name
- * @param configName the <code>String</code> format of the Config Name
- * @param configAttributes the <code>List</code> the <code>Map</code> Attributes that must contain the key and value.
- * @param configType the <code>String</code> format of the Config Type
- * @param body the <code>String</code> format of the Policy Body
- * @param policyScope the <code>String</code> value of the sub scope directory where the policy will be created and stored
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @param riskLevel the <code>String</code> value of risk Level.
- * @param riskType the <code>String</code> value of risk Type.
- * @param guard the <code>String</code> value of guard.
- * @param ttlDate the <code>String</code> value of time to live Date.
- * @throws PolicyException PolicyException related to the operation.
- * @return <code>String</code> format of response
- * @deprecated use {@link #createPolicy(PolicyParameters)} Instead.
- */
- @Deprecated
- public String createConfigPolicy(final String policyName, final String policyDescription, final String onapName, final String configName,
- final Map<String, String> configAttributes, final String configType, final String body, final String policyScope, final UUID requestID,
- final String riskLevel, final String riskType, final String guard, final String ttlDate) throws PolicyException {
- return stdPolicyEngine.createUpdateConfigPolicy(policyName, policyDescription, onapName, configName,
- configAttributes, configType, body, policyScope, requestID,
- riskLevel, riskType, guard, ttlDate, false);
- }
-
- /**
- * Creates a Config Policy based on given arguments
- * @param policyName the <code>String</code> format of the Policy Name
- * @param policyDescription the <code>String</code> format of the Policy Description
- * @param onapName the <code>String</code> format of the ONAP Name
- * @param configName the <code>String</code> format of the Config Name
- * @param configAttributes the <code>List</code> the <code>Map</code> Attributes that must contain the key and value.
- * @param configType the <code>String</code> format of the Config Type
- * @param body the <code>String</code> format of the Policy Body
- * @param policyScope the <code>String</code> value of the sub scope directory where the policy will be created and stored
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @param riskLevel the <code>String</code> value of risk Level.
- * @param riskType the <code>String</code> value of risk Type.
- * @param guard the <code>String</code> value of guard.
- * @param ttlDate the <code>String</code> value of time to live Date.
- * @throws PolicyException PolicyException related to the operation.
- * @return <code>String</code> format of response
- * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead.
- */
- @Deprecated
- public String updateConfigPolicy(final String policyName, final String policyDescription, final String onapName, final String configName,
- final Map<String, String> configAttributes, final String configType, final String body, final String policyScope, final UUID requestID,
- final String riskLevel, final String riskType, final String guard, final String ttlDate) throws PolicyException {
- return stdPolicyEngine.createUpdateConfigPolicy(policyName, policyDescription, onapName, configName,
- configAttributes, configType, body, policyScope, requestID,riskLevel, riskType, guard, ttlDate, true);
- }
-
- /**
- * Creates a Config Firewall Policy based on given arguments
- * @param policyName the <code>String</code> format of the Policy Name
- * @param firewallJson the <code>JsonObject</code> representation of the Firewall Rules List
- * @param policyScope the <code>String</code> value of the sub scope directory where the policy will be created and stored
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @param riskLevel the <code>String</code> value of risk Level.
- * @param riskType the <code>String</code> value of risk Type.
- * @param guard the <code>String</code> value of guard.
- * @param ttlDate the <code>String</code> value of time to live Date.
- * @throws PolicyException PolicyException related to the operation.
- * @return <code>String</code> format of response.
- * @deprecated use {@link #createPolicy(PolicyParameters)} Instead.
- */
- @Deprecated
- public String createConfigFirewallPolicy(final String policyName, final JsonObject firewallJson, final String policyScope, final UUID requestID,
- final String riskLevel, final String riskType, final String guard, final String ttlDate) throws PolicyException {
- return stdPolicyEngine.createUpdateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel,
- riskType, guard, ttlDate, false);
- }
-
- /**
- * Updates a Config Firewall Policy based on given arguments
- * @param policyName the <code>String</code> format of the Policy Name
- * @param firewallJson the <code>JsonObject</code> representation of the Firewall Rules List
- * @param policyScope the <code>String</code> value of the sub scope directory where the policy will be created and stored
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * A different request ID should be passed for each request.
- * @param riskLevel the <code>String</code> value of risk Level.
- * @param riskType the <code>String</code> value of risk Type.
- * @param guard the <code>String</code> value of guard.
- * @param ttlDate the <code>String</code> value of time to live Date.
- * @throws PolicyException PolicyException related to the operation.
- * @return <code>String</code> format of response.
- * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead.
- */
- @Deprecated
- public String updateConfigFirewallPolicy(final String policyName, final JsonObject firewallJson, final String policyScope, final UUID requestID,
- final String riskLevel, final String riskType, final String guard, final String ttlDate) throws PolicyException {
- return stdPolicyEngine.createUpdateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel, riskType, guard, ttlDate, true);
- }
-
- /**
- * Retrieves Dictionary Items for a specified dictionary
- *
- * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the Dictionary Parameters required to create a Dictionary Item.
- * @return {@link org.onap.policy.api.DictionaryResponse} which consists of the response related to create dictionary item Request.
- * @throws PolicyException PolicyException related to the operation
- *
- * */
- public DictionaryResponse getDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
- return stdPolicyEngine.getDictionaryItem(parameters);
- }
-
- /**
- * Creates a Dictionary Item based on given Dictionary Parameters
- *
- * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the Dictionary Parameters required to create a Dictionary Item.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to create dictionary item Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse createDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
- return stdPolicyEngine.createDictionaryItem(parameters);
- }
-
- /**
- * Updates a Dictionary Item based on given Dictionary Parameters
- *
- * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the Dictionary Parameters required to update a Dictionary Item.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to update dictionary item Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse updateDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
- return stdPolicyEngine.updateDictionaryItem(parameters);
- }
-
- /**
- * Creates a Policy based on given Policy Parameters.
- *
- * @param policyParameters {@link org.onap.policy.api.PolicyParameters} which represents the Policy Parameters required to create a Policy.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to create policy Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse createPolicy(final PolicyParameters policyParameters) throws PolicyException {
- return stdPolicyEngine.createPolicy(policyParameters);
- }
-
- /**
- * Update Policy based on given Policy Parameters.
- *
- * @param policyParameters {@link org.onap.policy.api.PolicyParameters} which represents the Policy Parameters required to update a Policy.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to create policy Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse updatePolicy(final PolicyParameters policyParameters) throws PolicyException {
- return stdPolicyEngine.updatePolicy(policyParameters);
- }
-
- /**
- * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used.
- *
- * @param policyScope the <code>String</code> value of the sub scope directory where the policy is located
- * @param policyName the <code>String</code> format of the Policy Name being pushed.
- * @param policyType the <code>String</code> format of the Policy Type which is being pushed.
- * @param pdpGroup the <code>String</code> format of the PDP Group name to which the policy needs to be pushed to.
- * @param requestID unique request ID which will be passed throughout the ONAP components to correlate logging messages.
- * @return <code>String</code> format of the response related to the push Policy Request.
- * @throws PolicyException PolicyException related to the operation.
- * @deprecated use {@link #pushPolicy(PushPolicyParameters)} instead.
- */
- @Deprecated
- public String pushPolicy(final String policyScope, final String policyName, final String policyType, final String pdpGroup, final UUID requestID) throws PolicyException {
- return stdPolicyEngine.pushPolicy(policyScope, policyName, policyType, pdpGroup, requestID);
- }
-
- /**
- * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used.
- *
- * @param pushPolicyParameters {@link org.onap.policy.api.PushPolicyParameters} which represents the Push Policy parameters required to push a policy.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to the push Policy Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse pushPolicy(final PushPolicyParameters pushPolicyParameters) throws PolicyException {
- return stdPolicyEngine.pushPolicy(pushPolicyParameters);
- }
-
- /**
- * Deletes the specified policy from the PAP or PDP.
- *
- * @param deletePolicyParameters {@link org.onap.policy.api.DeletePolicyParameters} which represents the Delete Policy parameters to delete a policy.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to the Delete Policy Request.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse deletePolicy(final DeletePolicyParameters deletePolicyParameters) throws PolicyException {
- return stdPolicyEngine.deletePolicy(deletePolicyParameters);
- }
-
- /**
- * Creates a new Policy Service based on given Service Parameters.
- *
- * @param importParameters {@link org.onap.policy.api.ImportParameters} which represents the Service Parameters required to create a Policy Service.
- * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related to create import Service.
- * @throws PolicyException PolicyException related to the operation.
- */
- public PolicyChangeResponse policyEngineImport(final ImportParameters importParameters) throws PolicyException {
- return stdPolicyEngine.policyEngineImport(importParameters);
- }
-
- /**
- * <code>setNotification</code> allows changes to the Notification Scheme and Notification Handler
- *
- * @param scheme the <code>NotificationScheme</code> of {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
- * @param handler the <code>NotificationHandler</code> of {@link org.onap.policy.api.NotificationHandler} which defines what should happen when a notification is received.
- */
- public void setNotification(final NotificationScheme scheme, final NotificationHandler handler) {
- this.scheme = scheme;
- this.handler = handler;
- stdPolicyEngine.notification(this.scheme,this.handler);
- }
-
- /**
- * <code>clearNotification</code> shutsDown the Notification Service if the Auto Scehme Notification service is running.
- */
- public void clearNotification(){
- stdPolicyEngine.stopNotification();
- }
-
- /**
- * <code>setNotification</code> allows changes to the Notification Scheme
- *
- * @param scheme the <code>NotificationScheme</code> of {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
- */
- public void setScheme(final NotificationScheme scheme){
- this.scheme = scheme;
- stdPolicyEngine.setScheme(this.scheme);
- }
-
- /**
- * Gets the <code>PDPNotification</code> if there is one exists. This is used for Polling Patterns.
- *
- * @return <code>PDPNotification</code> of {@link org.onap.policy.api.PDPNotification} which has the Notification.
- */
- public PDPNotification getNotification() {
- return stdPolicyEngine.getNotification();
- }
-
- /**
- * setClientKey allows the client to use their own implementation logic for Password Protection
- * and will be used to set the clear text password, this will be used while making Requests.
- *
- * @param clientKey depicts String format of Password/ Client_Key.
- */
- public void setClientKey(final String clientKey){
- StdPolicyEngine.setClientKey(clientKey);
- }
-
- // Internal Setter Method to help build configRequestParameters.
- private ConfigRequestParameters setConfigRequestParameters(final String policyName, final String onapName, final String configName, final Map<String, String> configAttributes, final UUID requestID){
- final ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
- configRequestParameters.setPolicyName(policyName);
- configRequestParameters.setOnapName(onapName);
- configRequestParameters.setConfigName(configName);
- configRequestParameters.setConfigAttributes(configAttributes);
- configRequestParameters.setRequestID(requestID);
- return configRequestParameters;
- }
-} \ No newline at end of file
+public class PolicyEngine {
+ private final StdPolicyEngine stdPolicyEngine;
+ private NotificationScheme scheme = null;
+ private NotificationHandler handler = null;
+
+ /**
+ * PolicyEngine Constructor with <code>Properties</code> structure
+ *
+ * @param properties the <code>Properties</code> structure containing the Policy engine parameters
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final Properties properties) throws PolicyEngineException {
+ this.stdPolicyEngine = new StdPolicyEngine(properties, (String) null);
+ }
+
+ /**
+ * PolicyEngine Constructor with <code>String</code> format of propertiesFilePathname
+ *
+ * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final String propertiesFilePathname) throws PolicyEngineException {
+ this.stdPolicyEngine = new StdPolicyEngine(propertiesFilePathname, (String) null);
+ }
+
+ /**
+ * PolicyEngine Constructor with <code>Properties</code> structure
+ *
+ * @param properties the <code>Properties</code> structure containing the Policy engine parameters
+ * @param clientKey depicts String format of Password/ Client_Key.
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final Properties properties, final String clientKey) throws PolicyEngineException {
+ this.stdPolicyEngine = new StdPolicyEngine(properties, clientKey);
+ }
+
+ /**
+ * PolicyEngine Constructor with <code>String</code> format of propertiesFilePathname
+ *
+ * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
+ * @param clientKey depicts String format of Password/ Client_Key.
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final String propertiesFilePathname, final String clientKey) throws PolicyEngineException {
+ this.stdPolicyEngine = new StdPolicyEngine(propertiesFilePathname, clientKey);
+ }
+
+ /**
+ * PolicyEngine Constructor with <code>String</code> format of PropertiesFilePathname and
+ * <code>NotificationScheme</code>
+ *
+ * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
+ * @param scheme the <code>NotificationScheme</code> of
+ * {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final String propertiesFilePathname, final NotificationScheme scheme)
+ throws PolicyEngineException {
+ this.scheme = scheme;
+ this.stdPolicyEngine = new StdPolicyEngine(propertiesFilePathname, this.scheme);
+ }
+
+ /**
+ * PolicyEngine Constructor with <code>String</code> format of PropertiesFilePathname,
+ * <code>NotificationScheme</code> and <code>NotificationHandler</code>
+ *
+ * @param propertiesFilePathname the <code>String</code> format of the propertiesFilePathname
+ * @param scheme the <code>NotificationScheme</code> of
+ * {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
+ * @param handler the <code>NotificationHandler</code> of
+ * {@link org.onap.policy.api.NotificationHandler} which defines what should happen when a
+ * notification is received.
+ * @throws PolicyEngineException PolicyEngine Exception
+ */
+ public PolicyEngine(final String propertiesFilePathname, final NotificationScheme scheme,
+ final NotificationHandler handler) throws PolicyEngineException {
+ this.scheme = scheme;
+ this.handler = handler;
+ this.stdPolicyEngine = new StdPolicyEngine(propertiesFilePathname, this.scheme, this.handler);
+ }
+
+ /**
+ * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which
+ * represents the Policy File Name
+ *
+ * @param policyName the <code>String</code> format of the PolicyFile Name whose configuration is
+ * required.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters configRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfigByPolicyName(final String policyName) throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(policyName, null, null, null, null));
+ }
+
+ /**
+ * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which
+ * represents the Policy File Name
+ *
+ * @param policyName the <code>String</code> format of the PolicyFile Name whose configuration is
+ * required.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters configRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfigByPolicyName(final String policyName, final UUID requestID)
+ throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(policyName, null, null, null, requestID));
+ }
+
+ /**
+ * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which
+ * represents the onapName
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName) throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, null, null, null));
+ }
+
+ /**
+ * Gets the configuration from the PolicyDecisionPoint(PDP) for the <code>String</code> which
+ * represents the onapName
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName, final UUID requestID)
+ throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, null, null, requestID));
+ }
+
+ /**
+ * Requests the configuration of the <code>String</code> which represents the onapName and
+ * <code>String</code> which represents the configName and returns the configuration if different
+ * Configurations exist for the particular onapName.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @param configName the <code>String</code> format of the configurationName whose configuration is
+ * required.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName, final String configName)
+ throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, configName, null, null));
+ }
+
+ /**
+ * Requests the configuration of the <code>String</code> which represents the onapName and
+ * <code>String</code> which represents the configName and returns the configuration if different
+ * Configurations exist for the particular onapName.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @param configName the <code>String</code> format of the configurationName whose configuration is
+ * required.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName, final String configName, final UUID requestID)
+ throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, configName, null, requestID));
+ }
+
+ /**
+ * Requests the configuration of the <code>String</code> which represents the onapName,
+ * <code>String</code> which represents the configName and <code>Map</code> of
+ * <code>String,String</code> which has the configAttribute and returns the specific configuration
+ * related to the configAttributes mentioned.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @param configName the <code>String</code> format of the configurationName whose configuration is
+ * required.
+ * @param configAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * configuration attributes which are required.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName, final String configName,
+ final Map<String, String> configAttributes) throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, configName, configAttributes, null));
+ }
+
+ /**
+ * Requests the configuration of the <code>String</code> which represents the onapName,
+ * <code>String</code> which represents the configName and <code>Map</code> of
+ * <code>String,String</code> which has the configAttribute and returns the specific configuration
+ * related to the configAttributes mentioned.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose configuration is required.
+ * @param configName the <code>String</code> format of the configurationName whose configuration is
+ * required.
+ * @param configAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * configuration attributes which are required.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyConfig> getConfig(final String onapName, final String configName,
+ final Map<String, String> configAttributes, final UUID requestID) throws PolicyConfigException {
+ return getConfig(setConfigRequestParameters(null, onapName, configName, configAttributes, requestID));
+ }
+
+ /**
+ * Requests the configuration of the <code>ConfigRequestParameters</code> which represents the
+ * Config policy request parameters and returns the specific configuration related to the matching
+ * parameters.
+ *
+ * @param configRequestParameters {@link org.onap.policy.api.ConfigRequestParameters} which
+ * represents the Config policy request parameters.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyConfig} which has the
+ * configuration.
+ * @throws PolicyConfigException PolicyConfig Exception
+ */
+ public Collection<PolicyConfig> getConfig(final ConfigRequestParameters configRequestParameters)
+ throws PolicyConfigException {
+ return stdPolicyEngine.getConfig(configRequestParameters);
+ }
+
+ /**
+ * Requests the list of policies based on the <code>ConfigRequestParameters</code> which represents
+ * the policy request parameters and returns the list of policies filtered by the parameters.
+ *
+ * @param configRequestParameters {@link org.onap.policy.api.ConfigRequestParameters} which
+ * represents the List Policy request parameters.
+ * @return <code>Collection</code> of <code>String</code> which returns the list of policies.
+ * @throws PolicyConfigException PolicyConfig Exception
+ */
+ public Collection<String> listConfig(final ConfigRequestParameters listPolicyRequestParameters)
+ throws PolicyConfigException {
+ return stdPolicyEngine.listConfig(listPolicyRequestParameters);
+ }
+
+ /**
+ * Requests the list of policies from PDP based on the <code>ConfigNameRequest</code> which
+ * represents the policy request parameters and returns the list of policies filtered by the
+ * parameters.
+ *
+ * @param ConfigNameRequest {@link org.onap.policy.api.ConfigNameRequest} which represents the List
+ * Policy request parameters.
+ * @return <code>Collection</code> of <code>String</code> which returns the list of policies.
+ * @throws PolicyConfigException PolicyConfig Exception
+ */
+ public Collection<String> listPolicy(final ConfigNameRequest listPolicyParams) throws PolicyConfigException {
+ return stdPolicyEngine.listPolicy(listPolicyParams);
+ }
+
+ /**
+ * Sends the Events specified to the PEP and returns back the PolicyResponse.
+ *
+ * @param eventAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * eventAttributes that must contain the event ID and values.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the
+ * Response.
+ * @throws PolicyEventException PolicyEvent Exception
+ * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyResponse> sendEvent(final Map<String, String> eventAttributes) throws PolicyEventException {
+ return stdPolicyEngine.sendEvent(eventAttributes, (UUID) null);
+ }
+
+ /**
+ * Sends the Events specified to the PEP and returns back the PolicyResponse.
+ *
+ * @param eventAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * eventAttributes that must contain the event ID and values.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the
+ * Response.
+ * @throws PolicyEventException PolicyEvent Exception
+ * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead.
+ */
+ @Deprecated
+ public Collection<PolicyResponse> sendEvent(final Map<String, String> eventAttributes, final UUID requestID)
+ throws PolicyEventException {
+ return stdPolicyEngine.sendEvent(eventAttributes, requestID);
+ }
+
+ /**
+ * Sends the Events specified to the PEP and returns back the PolicyResponse.
+ *
+ * @param eventRequestParameters {@link org.onap.policy.api.EventRequestParameters} which represents
+ * the Event Request Parameters.
+ * @return <code>Collection</code> of {@link org.onap.policy.api.PolicyResponse} which has the
+ * Response.
+ * @throws PolicyEventException PolicyEvent Exception
+ */
+ public Collection<PolicyResponse> sendEvent(final EventRequestParameters eventRequestParameters)
+ throws PolicyEventException {
+ return stdPolicyEngine.sendEvent(eventRequestParameters);
+ }
+
+ /**
+ * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose Decision is required.
+ * @param decisionAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * decisionAttributes that must contain the ID and values.
+ * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
+ * @throws PolicyDecisionException PolicyDecision Exception
+ * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead.
+ */
+ @Deprecated
+ public DecisionResponse getDecision(final String onapName, final Map<String, String> decisionAttributes)
+ throws PolicyDecisionException {
+ return stdPolicyEngine.getDecision(onapName, decisionAttributes, null);
+ }
+
+ /**
+ * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
+ *
+ * @param onapName the <code>String</code> format of the onapName whose Decision is required.
+ * @param decisionAttributes the <code>Map</code> of <code>String,String</code> format of the
+ * decisionAttributes that must contain the ID and values.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
+ * @throws PolicyDecisionException PolicyDecision Exception
+ * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead.
+ */
+ @Deprecated
+ public DecisionResponse getDecision(final String onapName, final Map<String, String> decisionAttributes,
+ final UUID requestID) throws PolicyDecisionException {
+ return stdPolicyEngine.getDecision(onapName, decisionAttributes, requestID);
+ }
+
+ /**
+ * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision.
+ *
+ * @param decisionRequestParameters {@link org.onap.policy.api.DecisionRequestParameters} which
+ * represents the Decision Request Parameters.
+ * @return {@link org.onap.policy.api.DecisionResponse} which has the Decision.
+ * @throws PolicyDecisionException PolicyDecision Exception
+ */
+ public DecisionResponse getDecision(final DecisionRequestParameters decisionRequestParameters)
+ throws PolicyDecisionException {
+ return stdPolicyEngine.getDecision(decisionRequestParameters);
+ }
+
+ /**
+ * Retrieves the count of policies on the PAP, PDP, and Policy Engine as a whole
+ *
+ * @param parameters {@link org.onap.policy.api.MetricsRequestParameters} which represents the
+ * Parameters required to get the Policy Metrics
+ * @return {@link org.onap.policy.api.MetricsResponse} which consists of the response related to
+ * getMetrics Request.
+ * @throws PolicyException PolicyException related to the operation
+ *
+ */
+ public MetricsResponse getMetrics(final MetricsRequestParameters parameters) throws PolicyException {
+ return stdPolicyEngine.getMetrics(parameters);
+ }
+
+ /**
+ * Creates a Config Policy based on given arguments
+ *
+ * @param policyName the <code>String</code> format of the Policy Name
+ * @param policyDescription the <code>String</code> format of the Policy Description
+ * @param onapName the <code>String</code> format of the ONAP Name
+ * @param configName the <code>String</code> format of the Config Name
+ * @param configAttributes the <code>List</code> the <code>Map</code> Attributes that must contain
+ * the key and value.
+ * @param configType the <code>String</code> format of the Config Type
+ * @param body the <code>String</code> format of the Policy Body
+ * @param policyScope the <code>String</code> value of the sub scope directory where the policy will
+ * be created and stored
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @param riskLevel the <code>String</code> value of risk Level.
+ * @param riskType the <code>String</code> value of risk Type.
+ * @param guard the <code>String</code> value of guard.
+ * @param ttlDate the <code>String</code> value of time to live Date.
+ * @throws PolicyException PolicyException related to the operation.
+ * @return <code>String</code> format of response
+ * @deprecated use {@link #createPolicy(PolicyParameters)} Instead.
+ */
+ @Deprecated
+ public String createConfigPolicy(final String policyName, final String policyDescription, final String onapName,
+ final String configName, final Map<String, String> configAttributes, final String configType,
+ final String body, final String policyScope, final UUID requestID, final String riskLevel,
+ final String riskType, final String guard, final String ttlDate) throws PolicyException {
+ return stdPolicyEngine.createUpdateConfigPolicy(policyName, policyDescription, onapName, configName,
+ configAttributes, configType, body, policyScope, requestID, riskLevel, riskType, guard, ttlDate, false);
+ }
+
+ /**
+ * Creates a Config Policy based on given arguments
+ *
+ * @param policyName the <code>String</code> format of the Policy Name
+ * @param policyDescription the <code>String</code> format of the Policy Description
+ * @param onapName the <code>String</code> format of the ONAP Name
+ * @param configName the <code>String</code> format of the Config Name
+ * @param configAttributes the <code>List</code> the <code>Map</code> Attributes that must contain
+ * the key and value.
+ * @param configType the <code>String</code> format of the Config Type
+ * @param body the <code>String</code> format of the Policy Body
+ * @param policyScope the <code>String</code> value of the sub scope directory where the policy will
+ * be created and stored
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @param riskLevel the <code>String</code> value of risk Level.
+ * @param riskType the <code>String</code> value of risk Type.
+ * @param guard the <code>String</code> value of guard.
+ * @param ttlDate the <code>String</code> value of time to live Date.
+ * @throws PolicyException PolicyException related to the operation.
+ * @return <code>String</code> format of response
+ * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead.
+ */
+ @Deprecated
+ public String updateConfigPolicy(final String policyName, final String policyDescription, final String onapName,
+ final String configName, final Map<String, String> configAttributes, final String configType,
+ final String body, final String policyScope, final UUID requestID, final String riskLevel,
+ final String riskType, final String guard, final String ttlDate) throws PolicyException {
+ return stdPolicyEngine.createUpdateConfigPolicy(policyName, policyDescription, onapName, configName,
+ configAttributes, configType, body, policyScope, requestID, riskLevel, riskType, guard, ttlDate, true);
+ }
+
+ /**
+ * Creates a Config Firewall Policy based on given arguments
+ *
+ * @param policyName the <code>String</code> format of the Policy Name
+ * @param firewallJson the <code>JsonObject</code> representation of the Firewall Rules List
+ * @param policyScope the <code>String</code> value of the sub scope directory where the policy will
+ * be created and stored
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @param riskLevel the <code>String</code> value of risk Level.
+ * @param riskType the <code>String</code> value of risk Type.
+ * @param guard the <code>String</code> value of guard.
+ * @param ttlDate the <code>String</code> value of time to live Date.
+ * @throws PolicyException PolicyException related to the operation.
+ * @return <code>String</code> format of response.
+ * @deprecated use {@link #createPolicy(PolicyParameters)} Instead.
+ */
+ @Deprecated
+ public String createConfigFirewallPolicy(final String policyName, final JsonObject firewallJson,
+ final String policyScope, final UUID requestID, final String riskLevel, final String riskType,
+ final String guard, final String ttlDate) throws PolicyException {
+ return stdPolicyEngine.createUpdateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,
+ riskLevel, riskType, guard, ttlDate, false);
+ }
+
+ /**
+ * Updates a Config Firewall Policy based on given arguments
+ *
+ * @param policyName the <code>String</code> format of the Policy Name
+ * @param firewallJson the <code>JsonObject</code> representation of the Firewall Rules List
+ * @param policyScope the <code>String</code> value of the sub scope directory where the policy will
+ * be created and stored
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages. A different request ID should be passed for each request.
+ * @param riskLevel the <code>String</code> value of risk Level.
+ * @param riskType the <code>String</code> value of risk Type.
+ * @param guard the <code>String</code> value of guard.
+ * @param ttlDate the <code>String</code> value of time to live Date.
+ * @throws PolicyException PolicyException related to the operation.
+ * @return <code>String</code> format of response.
+ * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead.
+ */
+ @Deprecated
+ public String updateConfigFirewallPolicy(final String policyName, final JsonObject firewallJson,
+ final String policyScope, final UUID requestID, final String riskLevel, final String riskType,
+ final String guard, final String ttlDate) throws PolicyException {
+ return stdPolicyEngine.createUpdateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,
+ riskLevel, riskType, guard, ttlDate, true);
+ }
+
+ /**
+ * Retrieves Dictionary Items for a specified dictionary
+ *
+ * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the
+ * Dictionary Parameters required to create a Dictionary Item.
+ * @return {@link org.onap.policy.api.DictionaryResponse} which consists of the response related to
+ * create dictionary item Request.
+ * @throws PolicyException PolicyException related to the operation
+ *
+ */
+ public DictionaryResponse getDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
+ return stdPolicyEngine.getDictionaryItem(parameters);
+ }
+
+ /**
+ * Creates a Dictionary Item based on given Dictionary Parameters
+ *
+ * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the
+ * Dictionary Parameters required to create a Dictionary Item.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to create dictionary item Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse createDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
+ return stdPolicyEngine.createDictionaryItem(parameters);
+ }
+
+ /**
+ * Updates a Dictionary Item based on given Dictionary Parameters
+ *
+ * @param parameters {@link org.onap.policy.api.DictionaryParameters} which represents the
+ * Dictionary Parameters required to update a Dictionary Item.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to update dictionary item Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse updateDictionaryItem(final DictionaryParameters parameters) throws PolicyException {
+ return stdPolicyEngine.updateDictionaryItem(parameters);
+ }
+
+ /**
+ * Creates a Policy based on given Policy Parameters.
+ *
+ * @param policyParameters {@link org.onap.policy.api.PolicyParameters} which represents the Policy
+ * Parameters required to create a Policy.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to create policy Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse createPolicy(final PolicyParameters policyParameters) throws PolicyException {
+ return stdPolicyEngine.createPolicy(policyParameters);
+ }
+
+ /**
+ * Update Policy based on given Policy Parameters.
+ *
+ * @param policyParameters {@link org.onap.policy.api.PolicyParameters} which represents the Policy
+ * Parameters required to update a Policy.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to create policy Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse updatePolicy(final PolicyParameters policyParameters) throws PolicyException {
+ return stdPolicyEngine.updatePolicy(policyParameters);
+ }
+
+ /**
+ * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used.
+ *
+ * @param policyScope the <code>String</code> value of the sub scope directory where the policy is
+ * located
+ * @param policyName the <code>String</code> format of the Policy Name being pushed.
+ * @param policyType the <code>String</code> format of the Policy Type which is being pushed.
+ * @param pdpGroup the <code>String</code> format of the PDP Group name to which the policy needs to
+ * be pushed to.
+ * @param requestID unique request ID which will be passed throughout the ONAP components to
+ * correlate logging messages.
+ * @return <code>String</code> format of the response related to the push Policy Request.
+ * @throws PolicyException PolicyException related to the operation.
+ * @deprecated use {@link #pushPolicy(PushPolicyParameters)} instead.
+ */
+ @Deprecated
+ public String pushPolicy(final String policyScope, final String policyName, final String policyType,
+ final String pdpGroup, final UUID requestID) throws PolicyException {
+ return stdPolicyEngine.pushPolicy(policyScope, policyName, policyType, pdpGroup, requestID);
+ }
+
+ /**
+ * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used.
+ *
+ * @param pushPolicyParameters {@link org.onap.policy.api.PushPolicyParameters} which represents the
+ * Push Policy parameters required to push a policy.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to the push Policy Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse pushPolicy(final PushPolicyParameters pushPolicyParameters) throws PolicyException {
+ return stdPolicyEngine.pushPolicy(pushPolicyParameters);
+ }
+
+ /**
+ * Deletes the specified policy from the PAP or PDP.
+ *
+ * @param deletePolicyParameters {@link org.onap.policy.api.DeletePolicyParameters} which represents
+ * the Delete Policy parameters to delete a policy.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to the Delete Policy Request.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse deletePolicy(final DeletePolicyParameters deletePolicyParameters)
+ throws PolicyException {
+ return stdPolicyEngine.deletePolicy(deletePolicyParameters);
+ }
+
+ /**
+ * Creates a new Policy Service based on given Service Parameters.
+ *
+ * @param importParameters {@link org.onap.policy.api.ImportParameters} which represents the Service
+ * Parameters required to create a Policy Service.
+ * @return {@link org.onap.policy.api.PolicyChangeResponse} which consists of the response related
+ * to create import Service.
+ * @throws PolicyException PolicyException related to the operation.
+ */
+ public PolicyChangeResponse policyEngineImport(final ImportParameters importParameters) throws PolicyException {
+ return stdPolicyEngine.policyEngineImport(importParameters);
+ }
+
+ /**
+ * <code>setNotification</code> allows changes to the Notification Scheme and Notification Handler
+ *
+ * @param scheme the <code>NotificationScheme</code> of
+ * {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
+ * @param handler the <code>NotificationHandler</code> of
+ * {@link org.onap.policy.api.NotificationHandler} which defines what should happen when a
+ * notification is received.
+ */
+ public void setNotification(final NotificationScheme scheme, final NotificationHandler handler) {
+ this.scheme = scheme;
+ this.handler = handler;
+ stdPolicyEngine.notification(this.scheme, this.handler);
+ }
+
+ /**
+ * <code>clearNotification</code> shutsDown the Notification Service if the Auto Scehme Notification
+ * service is running.
+ */
+ public void clearNotification() {
+ stdPolicyEngine.stopNotification();
+ }
+
+ /**
+ * <code>setNotification</code> allows changes to the Notification Scheme
+ *
+ * @param scheme the <code>NotificationScheme</code> of
+ * {@link org.onap.policy.api.NotificationScheme} which defines the Notification Scheme
+ */
+ public void setScheme(final NotificationScheme scheme) {
+ this.scheme = scheme;
+ stdPolicyEngine.setScheme(this.scheme);
+ }
+
+ /**
+ * Gets the <code>PDPNotification</code> if there is one exists. This is used for Polling Patterns.
+ *
+ * @return <code>PDPNotification</code> of {@link org.onap.policy.api.PDPNotification} which has the
+ * Notification.
+ */
+ public PDPNotification getNotification() {
+ return stdPolicyEngine.getNotification();
+ }
+
+ /**
+ * setClientKey allows the client to use their own implementation logic for Password Protection and
+ * will be used to set the clear text password, this will be used while making Requests.
+ *
+ * @param clientKey depicts String format of Password/ Client_Key.
+ */
+ public void setClientKey(final String clientKey) {
+ StdPolicyEngine.setClientKey(clientKey);
+ }
+
+ // Internal Setter Method to help build configRequestParameters.
+ private ConfigRequestParameters setConfigRequestParameters(final String policyName, final String onapName,
+ final String configName, final Map<String, String> configAttributes, final UUID requestID) {
+ final ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
+ configRequestParameters.setPolicyName(policyName);
+ configRequestParameters.setOnapName(onapName);
+ configRequestParameters.setConfigName(configName);
+ configRequestParameters.setConfigAttributes(configAttributes);
+ configRequestParameters.setRequestID(requestID);
+ return configRequestParameters;
+ }
+}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
index 8f3cf043a..ab356ec17 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
@@ -2,15 +2,15 @@
* ============LICENSE_START=======================================================
* PolicyEngineAPI
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -60,6 +60,9 @@ import static org.onap.policy.std.utils.PolicyConfigConstants.UEB_API_SECRET_PRO
import static org.onap.policy.std.utils.PolicyConfigConstants.UNAUTHORIZED_STATUS_CODE;
import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_DICTIONARY_ITEM_RESOURCE_NAME;
import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_POLICY_RESOURCE_NAME;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
@@ -89,6 +92,7 @@ import javax.json.JsonReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.ConfigNameRequest;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DecisionRequestParameters;
import org.onap.policy.api.DecisionResponse;
@@ -134,13 +138,10 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.xml.sax.InputSource;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
/**
* PolicyEngine Implementation class
- *
+ *
* @version 1.0
*/
public class StdPolicyEngine {
@@ -169,6 +170,7 @@ public class StdPolicyEngine {
private static final String UNIQUEID = UUID.randomUUID().toString();
private static final Logger LOGGER = FlexLogger.getLogger(StdPolicyConfig.class.getName());
+ private static final String LIST_POLICY_RESOURCE_NAME = "listPolicy";
/*
* Taking the Property file even if it null.
@@ -176,7 +178,7 @@ public class StdPolicyEngine {
public StdPolicyEngine(final String propertyFilePath, final String clientKey) throws PolicyEngineException {
setProperty(propertyFilePath, clientKey);
}
-
+
/*
* Taking the Property structure even if it null.
*/
@@ -246,6 +248,14 @@ public class StdPolicyEngine {
}
/*
+ * listPolicies from PDP using ConfigNameRequest Implementation
+ */
+ public Collection<String> listPolicy(final ConfigNameRequest listPolicyRequestParameters)
+ throws PolicyConfigException {
+ return listPolicyImpl(listPolicyRequestParameters);
+ }
+
+ /*
* getDecision using the decision Attributes.
*/
public DecisionResponse getDecision(final String onapName, final Map<String, String> decisionAttributes,
@@ -488,7 +498,8 @@ public class StdPolicyEngine {
return policyEngineImportImpl(importParameters);
}
- private PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters) throws PolicyException {
+ private PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters)
+ throws PolicyException {
final LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
// Create Request.
try {
@@ -795,6 +806,38 @@ public class StdPolicyEngine {
return policyList;
}
+ public Collection<String> listPolicyImpl(final ConfigNameRequest listPolicyRequestParameters)
+ throws PolicyConfigException {
+ final Collection<String> policyList = new ArrayList<>();
+ if (junit) {
+ policyList.add(TEST_POLICY_NAME);
+ return policyList;
+ }
+ String body = null;
+ // Create Request.
+ try {
+ body = PolicyUtils.objectToJsonString(listPolicyRequestParameters);
+ } catch (final JsonProcessingException e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID, e);
+ throw new PolicyConfigException(XACMLErrorConstants.ERROR_SCHEMA_INVALID, e);
+ }
+ // Get Response.
+ try {
+ final ResponseEntity<String[]> result =
+ callNewPDP(LIST_POLICY_RESOURCE_NAME, HttpMethod.POST, body, String[].class);
+ for (final String policy : result.getBody()) {
+ policyList.add(policy);
+ }
+ } catch (final Exception exception) {
+ final String defaulMessage = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_INVALID_PDPS + pdps;
+ final String message = getErrorMessage(exception, defaulMessage, LIST_POLICY_RESOURCE_NAME);
+ LOGGER.error(message, exception);
+ throw new PolicyConfigException(message, exception);
+ }
+
+ return policyList;
+ }
+
private Collection<PolicyResponse> sendEventImpl(final Map<String, String> eventAttributes, final UUID requestID)
throws PolicyEventException {
String body = null;
@@ -851,9 +894,9 @@ public class StdPolicyEngine {
XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided");
}
final Properties prop = getProperties(propertyFilePath);
- setProperty(prop,clientKey);
+ setProperty(prop, clientKey);
}
-
+
private void setProperty(final Properties properties, String clientKey) throws PolicyEngineException {
if (properties == null) {
throw new PolicyEngineException(
@@ -922,8 +965,8 @@ public class StdPolicyEngine {
private void readPDPPropertyURL(Properties prop, String propertyKey) throws PolicyEngineException {
final String propertyValue = prop.getProperty(propertyKey);
if (propertyValue == null) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Properties file doesn't have the PDP_URL parameter");
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Properties file doesn't have the PDP_URL parameter");
}
if (propertyValue.contains(SEMICOLLON)) {
final List<String> pdpDefault = Arrays.asList(propertyValue.split(REGEX));
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java
new file mode 100644
index 000000000..785c44d11
--- /dev/null
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PolicyEngineClient
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policyengine;
+
+import java.util.Collection;
+import org.onap.policy.api.ConfigNameRequest;
+import org.onap.policy.api.PolicyEngine;
+
+/**
+ * List Policy Client Code. policyName : ".*" returns list of policy names from PAP. policyName :
+ * "scope + "_" + "policyType" + "_" + policyName" + ".*" returns the matching policy from pap
+ * (active version)
+ */
+public class ListPolicyClient {
+ public static void main(String[] args) throws Exception {
+ PolicyEngine pe = new PolicyEngine("config.properties");
+ ConfigNameRequest listPolicyParams = new ConfigNameRequest();
+ listPolicyParams.setPolicyName(".*");
+ Collection<String> policies = pe.listPolicy(listPolicyParams);
+ for (String policy : policies) {
+ System.out.println(policy);
+ }
+ }
+}
diff --git a/docs/platform/api-docs.json b/docs/platform/api-docs.json
index 36281a089..f9296d274 100755
--- a/docs/platform/api-docs.json
+++ b/docs/platform/api-docs.json
@@ -1 +1 @@
-{"swagger":"2.0","info":{"description":"This API helps to make queries against Policy Engine","version":"3.0","title":"Policy Engine REST API"},"host":"104.239.197.207:8081","basePath":"/pdp/api","tags":[{"name":"policy-engine-services","description":"Policy Engine Services"}],"paths":{"/createConfig":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Config Policy based on given Policy Parameters.","operationId":"createConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configPolicyAPIRequest","description":"configPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/createDictionaryItem":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Dictionary Item for a specific dictionary based on given Parameters.","operationId":"createDictionaryItemUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/createFirewallConfig":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Config Firewall Policy","operationId":"createFirewallConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configFirewallPolicyAPIRequest","description":"configFirewallPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigFirewallPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/createPolicy":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Policy based on given Policy Parameters.","operationId":"createPolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"policyParameters","description":"policyParameters","required":true,"schema":{"$ref":"#/definitions/PolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/deletePolicy":{"delete":{"tags":["policy-engine-services"],"summary":"Deletes the specified policy from the PDP Group or PAP.","operationId":"deletePolicyUsingDELETE","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"deletePolicyParameters","description":"deletePolicyParameters","required":true,"schema":{"$ref":"#/definitions/DeletePolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"204":{"description":"No Content"},"403":{"description":"Forbidden"}}}},"/getConfig":{"post":{"tags":["policy-engine-services"],"summary":"Gets the configuration from the PolicyDecisionPoint(PDP)","operationId":"getConfigUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configRequestParameters","description":"configRequestParameters","required":true,"schema":{"$ref":"#/definitions/ConfigRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyConfig»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getConfigByPolicyName":{"post":{"tags":["policy-engine-services"],"summary":"Gets the configuration from the PolicyDecisionPoint(PDP) using PolicyName","operationId":"getConfigByPolicyNameUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configNameRequest","description":"configNameRequest","required":true,"schema":{"$ref":"#/definitions/ConfigNameRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyConfig»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/getDecision":{"post":{"tags":["policy-engine-services"],"summary":"Gets the Decision using specified decision parameters","operationId":"getDecisionUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"decisionRequestParameters","description":"decisionRequestParameters","required":true,"schema":{"$ref":"#/definitions/DecisionRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/DecisionResponse"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getDictionaryItems":{"post":{"tags":["policy-engine-services"],"summary":"Gets the dictionary items from the PAP","operationId":"getDictionaryItemsUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/DictionaryResponse"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getMetrics":{"get":{"tags":["policy-engine-services"],"summary":"Gets the policy metrics from the PolicyAccessPoint(PAP)","operationId":"getMetricsUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/MetricsResponse"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getNotification":{"post":{"tags":["policy-engine-services"],"summary":"Registers DMaaP Topic to recieve notification from Policy Engine","operationId":"getNotificationUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/listConfig":{"post":{"tags":["policy-engine-services"],"summary":"Gets the list of configuration policies from the PDP","operationId":"listConfigUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configRequestParameters","description":"configRequestParameters","required":true,"schema":{"$ref":"#/definitions/ConfigRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«string»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/policyEngineImport":{"post":{"tags":["policy-engine-services"],"summary":"Imports Policy based on the parameters which represent the service used to create a policy Service.","operationId":"policyEngineImportUsingPOST","consumes":["multipart/form-data"],"produces":["*/*"],"parameters":[{"name":"importParametersJson","in":"query","description":"importParametersJson","required":true,"type":"string"},{"name":"file","in":"formData","description":"file","required":true,"type":"file"},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/pushPolicy":{"put":{"tags":["policy-engine-services"],"summary":"Pushes the specified policy to the PDP Group.","operationId":"pushPolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"pushPolicyParameters","description":"pushPolicyParameters","required":true,"schema":{"$ref":"#/definitions/PushPolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/sendEvent":{"post":{"tags":["policy-engine-services"],"summary":"Sends the Events specified to the Policy Engine","operationId":"sendEventUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"eventRequestParameters","description":"eventRequestParameters","required":true,"schema":{"$ref":"#/definitions/EventRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyResponse»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/sendHeartbeat":{"post":{"tags":["policy-engine-services"],"summary":"Sends Heartbeat to DMaaP Topic Registry to continue recieving notifications from Policy Engine","operationId":"sendHeartbeatUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/stopNotification":{"post":{"tags":["policy-engine-services"],"summary":"De-Registers DMaaP Topic to stop recieving notifications from Policy Engine","operationId":"stopNotificationUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/updateConfig":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Config Policy based on given Policy Parameters.","operationId":"updateConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configPolicyAPIRequest","description":"configPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/updateDictionaryItem":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Dictionary Item for a specific dictionary based on given Parameters.","operationId":"updateDictionaryItemUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/updateFirewallConfig":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Config Firewall Policy","operationId":"updateFirewallConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configFirewallPolicyAPIRequest","description":"configFirewallPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigFirewallPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/updatePolicy":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Policy based on given Policy Parameters.","operationId":"updatePolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"policyParameters","description":"policyParameters","required":true,"schema":{"$ref":"#/definitions/PolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}},"definitions":{"PolicyParameters":{"type":"object","properties":{"actionAttribute":{"type":"string"},"actionPerformer":{"type":"string"},"attributes":{"type":"object","additionalProperties":{"$ref":"#/definitions/Map«string,string»"}},"configBody":{"type":"string"},"configBodyType":{"type":"string","enum":["Properties","json","xml","other"]},"configName":{"type":"string"},"controllerName":{"type":"string"},"dependencyNames":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmField1":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmField2":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmFunctions":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmLabels":{"type":"array","items":{"type":"string"}},"ecompName":{"type":"string"},"extendedOption":{"type":"string"},"guard":{"type":"boolean"},"onapName":{"type":"string"},"policyClass":{"type":"string","enum":["Config","Action","Decision"]},"policyConfigType":{"type":"string","enum":["Base","Fault","PM","FW","BRMS_Raw","BRMS_Param","MS","EXTENDED"]},"policyDescription":{"type":"string"},"policyName":{"type":"string"},"priority":{"type":"string"},"requestID":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ruleProvider":{"type":"string","enum":["Custom","AAF","GUARD_YAML","GUARD_BL_YAML","GUARD_MIN_MAX"]},"ttlDate":{"type":"string","format":"date-time"}}},"ConfigRequestParameters":{"type":"object","properties":{"configAttributes":{"type":"object","additionalProperties":{"type":"string"}},"configName":{"type":"string"},"ecompName":{"type":"string"},"onapName":{"type":"string"},"policyName":{"type":"string"},"requestID":{"type":"string"},"unique":{"type":"boolean"}}},"Collection«PolicyResponse»":{"type":"object"},"DecisionResponse":{"type":"object","properties":{"decision":{"type":"string","enum":["permit","deny","error"]},"details":{"type":"string"}}},"DictionaryParameters":{"type":"object","properties":{"dictionary":{"type":"string"},"dictionaryJson":{"type":"string"},"dictionaryType":{"type":"string","enum":["Common","Action","ClosedLoop","Firewall","Decision","BRMS","MicroService","DescriptiveScope","PolicyScope","Enforcer","SafePolicy","Extended"]},"requestID":{"type":"string"}}},"JsonValue":{"type":"object","properties":{"valueType":{"type":"string","enum":["ARRAY","OBJECT","STRING","NUMBER","TRUE","FALSE","NULL"]}}},"DecisionRequestParameters":{"type":"object","properties":{"decisionAttributes":{"type":"object","additionalProperties":{"type":"string"}},"ecompcomponentName":{"type":"string"},"onapName":{"type":"string"},"requestID":{"type":"string"}}},"ConfigPolicyAPIRequest":{"type":"object","properties":{"body":{"type":"string"},"configAttributes":{"type":"object","additionalProperties":{"type":"string"}},"configName":{"type":"string"},"configType":{"type":"string"},"ecompName":{"type":"string"},"guard":{"type":"string"},"onapName":{"type":"string"},"policyDescription":{"type":"string"},"policyName":{"type":"string"},"policyScope":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ttlDate":{"type":"string"}}},"PushPolicyParameters":{"type":"object","properties":{"pdpGroup":{"type":"string"},"policyName":{"type":"string"},"policyType":{"type":"string"},"requestID":{"type":"string"}}},"ConfigFirewallPolicyAPIRequest":{"type":"object","properties":{"firewallJson":{"type":"string"},"guard":{"type":"string"},"policyName":{"type":"string"},"policyScope":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ttlDate":{"type":"string"}}},"PolicyConfig":{"type":"object","properties":{"config":{"type":"string"},"matchingConditions":{"type":"object","additionalProperties":{"type":"string"}},"policyConfigMessage":{"type":"string"},"policyConfigStatus":{"type":"string","enum":["retrieved","not_found"]},"policyName":{"type":"string"},"policyVersion":{"type":"string"},"property":{"type":"object","additionalProperties":{"type":"string"}},"responseAttributes":{"type":"object","additionalProperties":{"type":"string"}},"type":{"type":"string","enum":["Properties","json","xml","other"]}}},"EventRequestParameters":{"type":"object","properties":{"eventAttributes":{"type":"object","additionalProperties":{"type":"string"}},"requestID":{"type":"string"}}},"Map«string,string»":{"type":"object","additionalProperties":{"type":"string"}},"Collection«PolicyConfig»":{"type":"object"},"DictionaryResponse":{"type":"object","properties":{"dictionaryData":{"type":"object","additionalProperties":{"type":"string"}},"dictionaryJson":{"type":"object","additionalProperties":{"$ref":"#/definitions/JsonValue"}},"responseCode":{"type":"integer","format":"int32"},"responseMessage":{"type":"string"}}},"ConfigNameRequest":{"type":"object","properties":{"policyName":{"type":"string"}}},"MetricsResponse":{"type":"object","properties":{"metricsTotal":{"type":"integer","format":"int32"},"papMetrics":{"type":"integer","format":"int32"},"pdpMetrics":{"type":"integer","format":"int32"},"responseCode":{"type":"integer","format":"int32"},"responseMessage":{"type":"string"}}},"Collection«string»":{"type":"object"},"PolicyResponse":{"type":"object","properties":{"actionAdvised":{"type":"object","additionalProperties":{"type":"string"}},"actionTaken":{"type":"object","additionalProperties":{"type":"string"}},"policyResponseMessage":{"type":"string"},"policyResponseStatus":{"type":"string","enum":["no_action","action_advised","action_taken"]},"requestAttributes":{"type":"object","additionalProperties":{"type":"string"}}}},"DeletePolicyParameters":{"type":"object","properties":{"deleteCondition":{"type":"string","enum":["Current Version","All Versions"]},"pdpGroup":{"type":"string"},"policyComponent":{"type":"string"},"policyName":{"type":"string"},"policyType":{"type":"string"},"requestID":{"type":"string"}}}}} \ No newline at end of file
+{"swagger":"2.0","info":{"description":"This API helps to make queries against Policy Engine","version":"3.0","title":"Policy Engine REST API"},"host":"104.239.197.207:8081","basePath":"/pdp/api","tags":[{"name":"policy-engine-services","description":"Policy Engine Services"}],"paths":{"/createConfig":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Config Policy based on given Policy Parameters.","operationId":"createConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configPolicyAPIRequest","description":"configPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/createDictionaryItem":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Dictionary Item for a specific dictionary based on given Parameters.","operationId":"createDictionaryItemUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/createFirewallConfig":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Config Firewall Policy","operationId":"createFirewallConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configFirewallPolicyAPIRequest","description":"configFirewallPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigFirewallPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/createPolicy":{"put":{"tags":["policy-engine-services"],"summary":"Creates a Policy based on given Policy Parameters.","operationId":"createPolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"policyParameters","description":"policyParameters","required":true,"schema":{"$ref":"#/definitions/PolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/deletePolicy":{"delete":{"tags":["policy-engine-services"],"summary":"Deletes the specified policy from the PDP Group or PAP.","operationId":"deletePolicyUsingDELETE","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"deletePolicyParameters","description":"deletePolicyParameters","required":true,"schema":{"$ref":"#/definitions/DeletePolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"204":{"description":"No Content"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}}},"/getConfig":{"post":{"tags":["policy-engine-services"],"summary":"Gets the configuration from the PolicyDecisionPoint(PDP)","operationId":"getConfigUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configRequestParameters","description":"configRequestParameters","required":true,"schema":{"$ref":"#/definitions/ConfigRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyConfig»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getConfigByPolicyName":{"post":{"tags":["policy-engine-services"],"summary":"Gets the configuration from the PolicyDecisionPoint(PDP) using PolicyName","operationId":"getConfigByPolicyNameUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configNameRequest","description":"configNameRequest","required":true,"schema":{"$ref":"#/definitions/ConfigNameRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyConfig»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/getDecision":{"post":{"tags":["policy-engine-services"],"summary":"Gets the Decision using specified decision parameters","operationId":"getDecisionUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"decisionRequestParameters","description":"decisionRequestParameters","required":true,"schema":{"$ref":"#/definitions/DecisionRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/DecisionResponse"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getDictionaryItems":{"post":{"tags":["policy-engine-services"],"summary":"Gets the dictionary items from the PAP","operationId":"getDictionaryItemsUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/DictionaryResponse"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getMetrics":{"get":{"tags":["policy-engine-services"],"summary":"Gets the policy metrics from the PolicyAccessPoint(PAP)","operationId":"getMetricsUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/MetricsResponse"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/getNotification":{"post":{"tags":["policy-engine-services"],"summary":"Registers DMaaP Topic to recieve notification from Policy Engine","operationId":"getNotificationUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/listConfig":{"post":{"tags":["policy-engine-services"],"summary":"Gets the list of configuration policies from the PDP","operationId":"listConfigUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configRequestParameters","description":"configRequestParameters","required":true,"schema":{"$ref":"#/definitions/ConfigRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«string»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/listPolicy":{"post":{"tags":["policy-engine-services"],"summary":"Gets the list of policies from the PAP","operationId":"listPolicyUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configNameRequest","description":"configNameRequest","required":true,"schema":{"$ref":"#/definitions/ConfigNameRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«string»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/policyEngineImport":{"post":{"tags":["policy-engine-services"],"summary":"Imports Policy based on the parameters which represent the service used to create a policy Service.","operationId":"policyEngineImportUsingPOST","consumes":["multipart/form-data"],"produces":["*/*"],"parameters":[{"name":"importParametersJson","in":"query","description":"importParametersJson","required":true,"type":"string"},{"name":"file","in":"formData","description":"file","required":true,"type":"file"},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/pushPolicy":{"put":{"tags":["policy-engine-services"],"summary":"Pushes the specified policy to the PDP Group.","operationId":"pushPolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"pushPolicyParameters","description":"pushPolicyParameters","required":true,"schema":{"$ref":"#/definitions/PushPolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/sendEvent":{"post":{"tags":["policy-engine-services"],"summary":"Sends the Events specified to the Policy Engine","operationId":"sendEventUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"eventRequestParameters","description":"eventRequestParameters","required":true,"schema":{"$ref":"#/definitions/EventRequestParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«PolicyResponse»"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/sendHeartbeat":{"post":{"tags":["policy-engine-services"],"summary":"Sends Heartbeat to DMaaP Topic Registry to continue recieving notifications from Policy Engine","operationId":"sendHeartbeatUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/stopNotification":{"post":{"tags":["policy-engine-services"],"summary":"De-Registers DMaaP Topic to stop recieving notifications from Policy Engine","operationId":"stopNotificationUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"notificationTopic","description":"notificationTopic","required":true,"schema":{"type":"string"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/updateConfig":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Config Policy based on given Policy Parameters.","operationId":"updateConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configPolicyAPIRequest","description":"configPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/updateDictionaryItem":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Dictionary Item for a specific dictionary based on given Parameters.","operationId":"updateDictionaryItemUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"dictionaryParameters","description":"dictionaryParameters","required":true,"schema":{"$ref":"#/definitions/DictionaryParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}},"/updateFirewallConfig":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Config Firewall Policy","operationId":"updateFirewallConfigUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"configFirewallPolicyAPIRequest","description":"configFirewallPolicyAPIRequest","required":true,"schema":{"$ref":"#/definitions/ConfigFirewallPolicyAPIRequest"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":true}},"/updatePolicy":{"put":{"tags":["policy-engine-services"],"summary":"Updates a Policy based on given Policy Parameters.","operationId":"updatePolicyUsingPUT","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"policyParameters","description":"policyParameters","required":true,"schema":{"$ref":"#/definitions/PolicyParameters"}},{"name":"ClientAuth","in":"header","description":"ClientAuth","required":true,"type":"string"},{"name":"X-ECOMP-RequestID","in":"header","description":"X-ECOMP-RequestID","required":false,"type":"string"},{"name":"Authorization","in":"header","required":true,"type":"string"},{"name":"Environment","in":"header","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}},"definitions":{"PolicyParameters":{"type":"object","properties":{"actionAttribute":{"type":"string"},"actionPerformer":{"type":"string"},"attributes":{"type":"object","additionalProperties":{"$ref":"#/definitions/Map«string,string»"}},"configBody":{"type":"string"},"configBodyType":{"type":"string","enum":["Properties","json","xml","other"]},"configName":{"type":"string"},"controllerName":{"type":"string"},"dependencyNames":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmField1":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmField2":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmFunctions":{"type":"array","items":{"type":"string"}},"dynamicRuleAlgorithmLabels":{"type":"array","items":{"type":"string"}},"ecompName":{"type":"string"},"extendedOption":{"type":"string"},"guard":{"type":"boolean"},"onapName":{"type":"string"},"policyClass":{"type":"string","enum":["Config","Action","Decision"]},"policyConfigType":{"type":"string","enum":["Base","Fault","PM","FW","BRMS_Raw","BRMS_Param","MS","EXTENDED"]},"policyDescription":{"type":"string"},"policyName":{"type":"string"},"priority":{"type":"string"},"requestID":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ruleProvider":{"type":"string","enum":["Custom","AAF","GUARD_YAML","GUARD_BL_YAML","GUARD_MIN_MAX"]},"ttlDate":{"type":"string","format":"date-time"}}},"ConfigRequestParameters":{"type":"object","properties":{"configAttributes":{"type":"object","additionalProperties":{"type":"string"}},"configName":{"type":"string"},"ecompName":{"type":"string"},"onapName":{"type":"string"},"policyName":{"type":"string"},"requestID":{"type":"string"},"unique":{"type":"boolean"}}},"Collection«PolicyResponse»":{"type":"object"},"DecisionResponse":{"type":"object","properties":{"decision":{"type":"string","enum":["permit","deny","error"]},"details":{"type":"string"}}},"DictionaryParameters":{"type":"object","properties":{"dictionary":{"type":"string"},"dictionaryJson":{"type":"string"},"dictionaryType":{"type":"string","enum":["Common","Action","ClosedLoop","Firewall","Decision","BRMS","MicroService","DescriptiveScope","PolicyScope","Enforcer","SafePolicy","Extended"]},"requestID":{"type":"string"}}},"JsonValue":{"type":"object","properties":{"valueType":{"type":"string","enum":["ARRAY","OBJECT","STRING","NUMBER","TRUE","FALSE","NULL"]}}},"DecisionRequestParameters":{"type":"object","properties":{"decisionAttributes":{"type":"object","additionalProperties":{"type":"string"}},"ecompcomponentName":{"type":"string"},"onapName":{"type":"string"},"requestID":{"type":"string"}}},"ConfigPolicyAPIRequest":{"type":"object","properties":{"body":{"type":"string"},"configAttributes":{"type":"object","additionalProperties":{"type":"string"}},"configName":{"type":"string"},"configType":{"type":"string"},"ecompName":{"type":"string"},"guard":{"type":"string"},"onapName":{"type":"string"},"policyDescription":{"type":"string"},"policyName":{"type":"string"},"policyScope":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ttlDate":{"type":"string"}}},"PushPolicyParameters":{"type":"object","properties":{"pdpGroup":{"type":"string"},"policyName":{"type":"string"},"policyType":{"type":"string"},"requestID":{"type":"string"}}},"ConfigFirewallPolicyAPIRequest":{"type":"object","properties":{"firewallJson":{"type":"string"},"guard":{"type":"string"},"policyName":{"type":"string"},"policyScope":{"type":"string"},"riskLevel":{"type":"string"},"riskType":{"type":"string"},"ttlDate":{"type":"string"}}},"PolicyConfig":{"type":"object","properties":{"config":{"type":"string"},"matchingConditions":{"type":"object","additionalProperties":{"type":"string"}},"policyConfigMessage":{"type":"string"},"policyConfigStatus":{"type":"string","enum":["retrieved","not_found"]},"policyName":{"type":"string"},"policyVersion":{"type":"string"},"property":{"type":"object","additionalProperties":{"type":"string"}},"responseAttributes":{"type":"object","additionalProperties":{"type":"string"}},"type":{"type":"string","enum":["Properties","json","xml","other"]}}},"EventRequestParameters":{"type":"object","properties":{"eventAttributes":{"type":"object","additionalProperties":{"type":"string"}},"requestID":{"type":"string"}}},"Map«string,string»":{"type":"object","additionalProperties":{"type":"string"}},"Collection«PolicyConfig»":{"type":"object"},"DictionaryResponse":{"type":"object","properties":{"dictionaryData":{"type":"object","additionalProperties":{"type":"string"}},"dictionaryJson":{"type":"object","additionalProperties":{"$ref":"#/definitions/JsonValue"}},"responseCode":{"type":"integer","format":"int32"},"responseMessage":{"type":"string"}}},"ConfigNameRequest":{"type":"object","properties":{"policyName":{"type":"string"}}},"MetricsResponse":{"type":"object","properties":{"metricsTotal":{"type":"integer","format":"int32"},"papMetrics":{"type":"integer","format":"int32"},"pdpMetrics":{"type":"integer","format":"int32"},"responseCode":{"type":"integer","format":"int32"},"responseMessage":{"type":"string"}}},"Collection«string»":{"type":"object"},"PolicyResponse":{"type":"object","properties":{"actionAdvised":{"type":"object","additionalProperties":{"type":"string"}},"actionTaken":{"type":"object","additionalProperties":{"type":"string"}},"policyResponseMessage":{"type":"string"},"policyResponseStatus":{"type":"string","enum":["no_action","action_advised","action_taken"]},"requestAttributes":{"type":"object","additionalProperties":{"type":"string"}}}},"DeletePolicyParameters":{"type":"object","properties":{"deleteCondition":{"type":"string","enum":["Current Version","All Versions"]},"pdpGroup":{"type":"string"},"policyComponent":{"type":"string"},"policyName":{"type":"string"},"policyType":{"type":"string"},"requestID":{"type":"string"}}}}} \ No newline at end of file
diff --git a/docs/platform/offeredapis.rst b/docs/platform/offeredapis.rst
index 4a76fb770..197735100 100644
--- a/docs/platform/offeredapis.rst
+++ b/docs/platform/offeredapis.rst
@@ -418,6 +418,35 @@ Examples
}
}
}
+
+
+ .. code-block:: java
+ :caption: ListPolicy Example
+ :linenos:
+
+ package org.onap.policyengine;
+
+ import java.util.Collection;
+ import org.onap.policy.api.ConfigNameRequest;
+ import org.onap.policy.api.PolicyEngine;
+
+ /**
+ * List Policy Client Code
+ * policyName : ".*" returns list of policy names from PAP.
+ * policyName : "scope + "_" + "policyType" + "_" + policyName" + ".*" returns the matching policy from pap (active version)
+ *
+ */
+ public class ListPolicyClient {
+ public static void main(String[] args) throws Exception {
+ PolicyEngine pe = new PolicyEngine("config.properties");
+ ConfigNameRequest listPolicyParams = new ConfigNameRequest();
+ listPolicyParams.setPolicyName(".*");
+ Collection<String> policies = pe.listPolicy(listPolicyParams);
+ for (String policy : policies) {
+ System.out.println(policy);
+ }
+ }
+ }
.. code-block:: java