From 6e4582e760f0f63f8938a64b1317658dcde119cd Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 9 Nov 2022 11:50:59 +0000 Subject: Add forwarding support for policy-pap The GUI server must forward calls to PAP to allow policies to be deployed and undeployed. Issue-ID: POLICY-4138 Change-Id: I10ef96a8154cf618c3a22be1e06ec969729db54e Signed-off-by: liamfallon --- .../server/config/FilterRegistrationConfig.java | 6 +- .../server/config/PolicyApiRestTemplateConfig.java | 6 +- .../server/config/PolicyPapRestTemplateConfig.java | 54 +++++++++++++++ .../gui/server/rest/PolicyApiRestController.java | 8 +-- .../gui/server/rest/PolicyPapRestController.java | 76 ++++++++++++++++++++++ 5 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyPapRestTemplateConfig.java create mode 100644 gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyPapRestController.java (limited to 'gui-server/src/main/java') diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/FilterRegistrationConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/FilterRegistrationConfig.java index 179a3aa..c7a3aa4 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/config/FilterRegistrationConfig.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/FilterRegistrationConfig.java @@ -29,9 +29,12 @@ import org.springframework.context.annotation.Configuration; @Configuration public class FilterRegistrationConfig { - @Value("${runtime-ui.policy.mapping-path}") + @Value("${runtime-ui.policy-api.mapping-path}") private String policyApiMappingPath; + @Value("${runtime-ui.policy-pap.mapping-path}") + private String policyPapMappingPath; + @Value("${runtime-ui.acm.mapping-path}") private String acmRuntimeMappingPath; @@ -44,6 +47,7 @@ public class FilterRegistrationConfig { registrationBean.setFilter(new ClientSslHeaderFilter()); registrationBean.addUrlPatterns( StringUtils.stripEnd(policyApiMappingPath, "/") + "/*", + StringUtils.stripEnd(policyPapMappingPath, "/") + "/*", StringUtils.stripEnd(acmRuntimeMappingPath, "/") + "/*" ); return registrationBean; diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyApiRestTemplateConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyApiRestTemplateConfig.java index e88b0a5..b3bcb24 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyApiRestTemplateConfig.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyApiRestTemplateConfig.java @@ -36,10 +36,10 @@ public class PolicyApiRestTemplateConfig extends BaseRestTemplateConfig { * @param disableSslValidation Turn off SSL altogether on this REST interface * @param disableSslHostnameCheck Turn off SSL host name checking */ - @Value("{runtime-ui.policy}") + @Value("{runtime-ui.policy-api}") public void setSslFlags( - @Value("${runtime-ui.policy.disable-ssl-validation:false}") boolean disableSslValidation, - @Value("${runtime-ui.policy.disable-ssl-hostname-check:false}") boolean disableSslHostnameCheck) { + @Value("${runtime-ui.policy-api.disable-ssl-validation:false}") boolean disableSslValidation, + @Value("${runtime-ui.policy-api.disable-ssl-hostname-check:false}") boolean disableSslHostnameCheck) { super.setDisableSslValidation(disableSslValidation); super.setDisableSslHostnameCheck(disableSslHostnameCheck); } diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyPapRestTemplateConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyPapRestTemplateConfig.java new file mode 100644 index 0000000..3d7731b --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyPapRestTemplateConfig.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.gui.server.config; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class PolicyPapRestTemplateConfig extends BaseRestTemplateConfig { + + /** + * Set the SSL validation flags on the template. + * + * @param disableSslValidation Turn off SSL altogether on this REST interface + * @param disableSslHostnameCheck Turn off SSL host name checking + */ + @Value("{runtime-ui.policy-pap}") + public void setSslFlags( + @Value("${runtime-ui.policy-pap.disable-ssl-validation:false}") boolean disableSslValidation, + @Value("${runtime-ui.policy-pap.disable-ssl-hostname-check:false}") boolean disableSslHostnameCheck) { + super.setDisableSslValidation(disableSslValidation); + super.setDisableSslHostnameCheck(disableSslHostnameCheck); + } + + /** + * Returns a RestTemplate, optionally disabling SSL host name check or disabling SSL validation entirely. + */ + @Bean + public RestTemplate policyPapRestTemplate() throws GeneralSecurityException, IOException { + return super.getRestTemplate(); + } +} diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyApiRestController.java b/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyApiRestController.java index 2be3417..5e3f5d3 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyApiRestController.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyApiRestController.java @@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @RestController -@RequestMapping("${runtime-ui.policy.mapping-path}") +@RequestMapping("${runtime-ui.policy-api.mapping-path}") public class PolicyApiRestController extends BaseRestController { /** * Set the mapping parameters for the REST controller. @@ -43,10 +43,10 @@ public class PolicyApiRestController extends BaseRestController { * @param mappingPath The mapping path to map from * @param url The URL path to map to */ - @Value("{runtime-ui.policy}") + @Value("{runtime-ui.policy-api}") public void setSslFlags( - @Value("${runtime-ui.policy.mapping-path}") String mappingPath, - @Value("${runtime-ui.policy.url}") URI url) { + @Value("${runtime-ui.policy-api.mapping-path}") String mappingPath, + @Value("${runtime-ui.policy-api.url}") URI url) { super.setMappingPath(mappingPath); super.setUrl(url); } diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyPapRestController.java b/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyPapRestController.java new file mode 100644 index 0000000..c837b03 --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyPapRestController.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.gui.server.rest; + +import java.net.URI; +import javax.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +@RequestMapping("${runtime-ui.policy-pap.mapping-path}") +public class PolicyPapRestController extends BaseRestController { + /** + * Set the mapping parameters for the REST controller. + * + * @param mappingPath The mapping path to map from + * @param url The URL path to map to + */ + @Value("{runtime-ui.policy-pap}") + public void setSslFlags( + @Value("${runtime-ui.policy-pap.mapping-path}") String mappingPath, + @Value("${runtime-ui.policy-pap.url}") URI url) { + super.setMappingPath(mappingPath); + super.setUrl(url); + } + + /** + * Set the REST template for the REST controller. + * + * @param restTemplate The REST template + */ + @Autowired + public void setControllerRestTemplate( + @Qualifier("policyPapRestTemplate") RestTemplate restTemplate) { + super.setRestTemplate(restTemplate); + } + + /** + * Proxy rest calls to ACM runtime. + */ + @Override + @RequestMapping("/**") + public ResponseEntity mirrorRest(@RequestBody(required = false) String body, + @RequestHeader HttpHeaders headers, + HttpMethod method, + HttpServletRequest request) { + return super.mirrorRest(body, headers, method, request); + } +} -- cgit 1.2.3-korg