diff options
Diffstat (limited to 'gui-server/src/main')
13 files changed, 326 insertions, 83 deletions
diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/AcmRuntimeRestTemplateConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/AcmRuntimeRestTemplateConfig.java new file mode 100644 index 0000000..e326a63 --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/AcmRuntimeRestTemplateConfig.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 AcmRuntimeRestTemplateConfig 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.acm}") + public void setSslFlags( + @Value("${runtime-ui.acm.disable-ssl-validation:false}") boolean disableSslValidation, + @Value("${runtime-ui.acm.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 acmRuntimeRestTemplate() throws GeneralSecurityException, IOException { + return super.getRestTemplate(); + } +} diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/ClampRestTemplateConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/BaseRestTemplateConfig.java index 8d501d2..26d2296 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/config/ClampRestTemplateConfig.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/BaseRestTemplateConfig.java @@ -25,6 +25,7 @@ import java.security.GeneralSecurityException; import javax.annotation.PostConstruct; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; +import lombok.Setter; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustAllStrategy; @@ -33,27 +34,24 @@ import org.apache.http.ssl.SSLContextBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -@Configuration -public class ClampRestTemplateConfig { - private static final Logger LOG = LoggerFactory.getLogger(ClampRestTemplateConfig.class); +public class BaseRestTemplateConfig { + private static final Logger LOG = LoggerFactory.getLogger(BaseRestTemplateConfig.class); - @Value("${clamp.disable-ssl-validation:false}") + @Setter private boolean disableSslValidation; - @Value("${clamp.disable-ssl-hostname-check:false}") + @Setter private boolean disableSslHostnameCheck; @Value("${server.ssl.trust-store:#{null}}") - private Resource trustStore; + protected Resource trustStore; @Value("${server.ssl.trust-store-password:#{null}}") - private char[] trustStorePassword; + protected char[] trustStorePassword; @PostConstruct private void validateProperties() { @@ -69,8 +67,7 @@ public class ClampRestTemplateConfig { /** * Returns a RestTemplate, optionally disabling SSL hostname check or disabling SSL validation entirely. */ - @Bean - public RestTemplate clampRestTemplate() throws GeneralSecurityException, IOException { + protected RestTemplate getRestTemplate() throws GeneralSecurityException, IOException { SSLContext sslContext; if (disableSslValidation) { sslContext = new SSLContextBuilder().loadTrustMaterial(new TrustAllStrategy()).build(); 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 3e62237..179a3aa 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 @@ -20,22 +20,32 @@ package org.onap.policy.gui.server.config; +import org.apache.commons.lang3.StringUtils; import org.onap.policy.gui.server.filters.ClientSslHeaderFilter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class FilterRegistrationConfig { + @Value("${runtime-ui.policy.mapping-path}") + private String policyApiMappingPath; + + @Value("${runtime-ui.acm.mapping-path}") + private String acmRuntimeMappingPath; /** - * Registers ClientSslToHeaderFilter for /clamp/restservices/*. + * Registers ClientSslToHeaderFilter for the mapped URLs. */ @Bean public FilterRegistrationBean<ClientSslHeaderFilter> clientSslHeaderFilter() { FilterRegistrationBean<ClientSslHeaderFilter> registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new ClientSslHeaderFilter()); - registrationBean.addUrlPatterns("/clamp/restservices/*"); + registrationBean.addUrlPatterns( + StringUtils.stripEnd(policyApiMappingPath, "/") + "/*", + 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 new file mode 100644 index 0000000..e88b0a5 --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/PolicyApiRestTemplateConfig.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 PolicyApiRestTemplateConfig 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}") + public void setSslFlags( + @Value("${runtime-ui.policy.disable-ssl-validation:false}") boolean disableSslValidation, + @Value("${runtime-ui.policy.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 policyApiRestTemplate() throws GeneralSecurityException, IOException { + return super.getRestTemplate(); + } +} diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/config/StaticContentConfig.java b/gui-server/src/main/java/org/onap/policy/gui/server/config/StaticContentConfig.java index 479202d..8338215 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/config/StaticContentConfig.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/config/StaticContentConfig.java @@ -29,10 +29,10 @@ public class StaticContentConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/clamp").setViewName("redirect:/clamp/"); - registry.addViewController("/clamp/").setViewName("forward:/clamp/index.html"); - registry.addViewController("/apex-editor").setViewName("redirect:/apex-editor/"); - registry.addViewController("/apex-editor/").setViewName("forward:/apex-editor/index.html"); + registry.addViewController("/runtime-ui").setViewName("redirect:/runtime-ui/"); + registry.addViewController("/runtime-ui/").setViewName("forward:/runtime-ui/index.html"); + registry.addViewController("/designtime-ui").setViewName("redirect:/designtime-ui/"); + registry.addViewController("/designtime-ui/").setViewName("forward:/designtime-ui/index.html"); } } diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/filters/ClientSslHeaderFilter.java b/gui-server/src/main/java/org/onap/policy/gui/server/filters/ClientSslHeaderFilter.java index db8f593..06af720 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/filters/ClientSslHeaderFilter.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/filters/ClientSslHeaderFilter.java @@ -43,9 +43,9 @@ import org.springframework.web.filter.OncePerRequestFilter; /** * Filter which encodes a client SSL certificate into X-SSL-Cert HTTP header. - * CLAMP has a corresponding filter called ClampCadiFilter which decodes the - * header. This is needed as CLAMP runtime uses AAF for auth, and AAF uses - * client cert authentication. Since REST requests from CLAMP GUI to CLAMP + * A target runtime may have a corresponding filter that decodes the + * header. This is needed as a target runtime may use a mechanism for + * client cert authentication. Since REST requests from the GUI to the * runtime are proxied in gui-server, the proxy needs to attach a copy of the * client SSL cert, as the proxy could not know the client's private key. */ @@ -56,7 +56,7 @@ public class ClientSslHeaderFilter extends OncePerRequestFilter { // Name of attribute containing request SSL cert. public static final String X509_ATTRIBUTE_NAME = "javax.servlet.request.X509Certificate"; - // Name of header containing encoded SSL cert - also used in clamp's ClampCadiFilter. + // Name of header containing encoded SSL cert - also used in the runtime filter. public static final String SSL_CERT_HEADER_NAME = "X-SSL-Cert"; @Override diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/rest/AcmRuntimeRestController.java b/gui-server/src/main/java/org/onap/policy/gui/server/rest/AcmRuntimeRestController.java new file mode 100644 index 0000000..713ceb4 --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/rest/AcmRuntimeRestController.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.acm.mapping-path}") +public class AcmRuntimeRestController 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.acm}") + public void setSslFlags( + @Value("${runtime-ui.acm.mapping-path}") String mappingPath, + @Value("${runtime-ui.acm.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("acmRuntimeRestTemplate") RestTemplate restTemplate) { + super.setRestTemplate(restTemplate); + } + + /** + * Proxy rest calls to ACM runtime. + */ + @Override + @RequestMapping("/**") + public ResponseEntity<String> mirrorRest(@RequestBody(required = false) String body, + @RequestHeader HttpHeaders headers, + HttpMethod method, + HttpServletRequest request) { + return super.mirrorRest(body, headers, method, request); + } +} diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/rest/ApexEditorRestController.java b/gui-server/src/main/java/org/onap/policy/gui/server/rest/ApexEditorRestController.java deleted file mode 100644 index a4b92ef..0000000 --- a/gui-server/src/main/java/org/onap/policy/gui/server/rest/ApexEditorRestController.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============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 javax.servlet.http.HttpServletRequest; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.ModelAndView; - -@RestController -@RequestMapping("/apex-editor/policy/gui/v*/apex/editor") -public class ApexEditorRestController { - - /** - * Strip /apex-editor prefix from Apex Editor rest calls. - */ - @RequestMapping("/**") - public ModelAndView forwardApexEditorRest(ModelMap model, HttpServletRequest request) { - String targetUrl = request.getRequestURI().replaceFirst("^/apex-editor", ""); - return new ModelAndView("forward:" + targetUrl, model); - } -} diff --git a/gui-server/src/main/java/org/onap/policy/gui/server/rest/ClampRestController.java b/gui-server/src/main/java/org/onap/policy/gui/server/rest/BaseRestController.java index b13003c..e4aa511 100644 --- a/gui-server/src/main/java/org/onap/policy/gui/server/rest/ClampRestController.java +++ b/gui-server/src/main/java/org/onap/policy/gui/server/rest/BaseRestController.java @@ -22,44 +22,37 @@ 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 lombok.Setter; import org.springframework.http.HttpEntity; 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.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; -@RestController -@RequestMapping("/clamp/restservices") -public class ClampRestController { +public class BaseRestController { + @Setter + private String mappingPath; - @Value("${clamp.url}") - private URI clampUrl; + @Setter + private URI url; - @Autowired - @Qualifier("clampRestTemplate") + @Setter private RestTemplate restTemplate; /** - * Proxy rest calls to clamp backend. + * Proxy rest calls to a runtime. */ - @SuppressWarnings("java:S3752") // Suppress warning about RequestMapping without HTTP method. - @RequestMapping("/**") public ResponseEntity<String> mirrorRest(@RequestBody(required = false) String body, @RequestHeader HttpHeaders headers, HttpMethod method, HttpServletRequest request) { - // Strip /clamp/ prefix from request URI. - String requestUri = request.getRequestURI().replaceFirst("^/clamp/", ""); - URI uri = UriComponentsBuilder.fromUri(clampUrl) + // Strip the runtime prefix from request URI. + String requestUri = request.getRequestURI().replaceFirst(mappingPath, ""); + URI uri = UriComponentsBuilder.fromUri(url) .path(requestUri) .query(request.getQueryString()) .build(true).toUri(); @@ -69,7 +62,7 @@ public class ClampRestController { return restTemplate.exchange(uri, method, httpEntity, String.class); } catch (HttpStatusCodeException e) { - // On error, return the backend error code instead of 500. + // On error, return the server runtime error code instead of 500. return ResponseEntity.status(e.getRawStatusCode()) .headers(e.getResponseHeaders()) .body(e.getResponseBodyAsString()); 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 new file mode 100644 index 0000000..2be3417 --- /dev/null +++ b/gui-server/src/main/java/org/onap/policy/gui/server/rest/PolicyApiRestController.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.mapping-path}") +public class PolicyApiRestController 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}") + public void setSslFlags( + @Value("${runtime-ui.policy.mapping-path}") String mappingPath, + @Value("${runtime-ui.policy.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("policyApiRestTemplate") RestTemplate restTemplate) { + super.setRestTemplate(restTemplate); + } + + /** + * Proxy rest calls to ACM runtime. + */ + @Override + @RequestMapping("/**") + public ResponseEntity<String> mirrorRest(@RequestBody(required = false) String body, + @RequestHeader HttpHeaders headers, + HttpMethod method, + HttpServletRequest request) { + return super.mirrorRest(body, headers, method, request); + } +} diff --git a/gui-server/src/main/resources/static/designtime-ui/index.html b/gui-server/src/main/resources/static/designtime-ui/index.html new file mode 100644 index 0000000..8da1b06 --- /dev/null +++ b/gui-server/src/main/resources/static/designtime-ui/index.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>ONAP Policy GUI</title> +</head> +<body> +<ul> + <li><a href="/designtime-ui/apex-editor/index.html">The Apex Policy Editor</a></li> +</ul> +</body> +</html> diff --git a/gui-server/src/main/resources/static/index.html b/gui-server/src/main/resources/static/index.html index 3b079a8..b0bdb06 100644 --- a/gui-server/src/main/resources/static/index.html +++ b/gui-server/src/main/resources/static/index.html @@ -6,8 +6,8 @@ </head> <body> <ul> - <li><a href="/apex-editor/">Apex Policy Editor</a></li> - <li><a href="/clamp/">CLAMP Designer UI</a></li> + <li><a href="/designtime-ui/index.html">Design Time User Interface</a></li> + <li><a href="/runtime-ui/index.html">Run Time User Interface</a></li> </ul> </body> </html> diff --git a/gui-server/src/main/resources/static/runtime-ui/index.html b/gui-server/src/main/resources/static/runtime-ui/index.html new file mode 100644 index 0000000..74fa41a --- /dev/null +++ b/gui-server/src/main/resources/static/runtime-ui/index.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>ONAP Policy GUI</title> +</head> +<body> +<ul> + <li><a href="/runtime-ui/clamp/index.html">The CLAMP GUI</a></li> +</ul> +</body> +</html> |