From 71a61bb124a906e6327e78f45ecc9a0f7b1ec0dc Mon Sep 17 00:00:00 2001 From: niamhcore Date: Tue, 6 Jul 2021 10:32:17 +0100 Subject: Implement Plugin Registration in DMI-Plugin - Refactor ncmp/dmi package Issue-ID: CPS-405 Issue-ID: CPS-499 Signed-off-by: niamhcore Change-Id: I0a7ab9bb0ca3861b171388613c44f7bc6e7f9aa9 --- src/main/java/org/onap/cps/ncmp/Application.java | 33 --------- .../org/onap/cps/ncmp/config/DmiPluginConfig.java | 46 ------------ .../onap/cps/ncmp/config/WebSecurityConfig.java | 82 ---------------------- .../java/org/onap/cps/ncmp/dmi/Application.java | 33 +++++++++ .../onap/cps/ncmp/dmi/config/CpsConfiguration.java | 55 +++++++++++++++ .../onap/cps/ncmp/dmi/config/DmiPluginConfig.java | 46 ++++++++++++ .../cps/ncmp/dmi/config/WebSecurityConfig.java | 82 ++++++++++++++++++++++ .../dmi/rest/controller/DmiRestController.java | 44 ++++++++++++ .../org/onap/cps/ncmp/dmi/service/DmiService.java | 31 ++++++++ .../onap/cps/ncmp/dmi/service/DmiServiceImpl.java | 32 +++++++++ .../ncmp/dmi/service/client/NcmpRestClient.java | 63 +++++++++++++++++ .../ncmp/rest/controller/DmiRestController.java | 44 ------------ .../java/org/onap/cps/ncmp/service/DmiService.java | 31 -------- .../org/onap/cps/ncmp/service/DmiServiceImpl.java | 32 --------- 14 files changed, 386 insertions(+), 268 deletions(-) delete mode 100644 src/main/java/org/onap/cps/ncmp/Application.java delete mode 100644 src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java delete mode 100644 src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/Application.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java create mode 100644 src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java delete mode 100644 src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java delete mode 100644 src/main/java/org/onap/cps/ncmp/service/DmiService.java delete mode 100644 src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/onap/cps/ncmp/Application.java b/src/main/java/org/onap/cps/ncmp/Application.java deleted file mode 100644 index 44acde4c..00000000 --- a/src/main/java/org/onap/cps/ncmp/Application.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(final String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java deleted file mode 100644 index 06b28691..00000000 --- a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; - - -@Configuration -public class DmiPluginConfig { - /** - * Swagger-ui configuration. - */ - @Bean("dmi-plugin-docket") - public Docket api() { - return new Docket(DocumentationType.OAS_30) - .groupName("dmi-plugin-docket") - .select() - .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) - .build(); - } -} - diff --git a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java b/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java deleted file mode 100644 index a911ef82..00000000 --- a/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -/** - * Configuration class to implement application security. - * It enforces Basic Authentication access control. - */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - - private static final String USER_ROLE = "USER"; - - private final String username; - private final String password; - private final String[] permitUris; - - /** - * Constructor. Accepts parameters from configuration. - * - * @param permitUris comma-separated list of uri patterns for endpoints permitted - * @param username username - * @param password password - */ - public WebSecurityConfig( - @Autowired @Value("${security.permit-uri}") final String permitUris, - @Autowired @Value("${security.auth.username}") final String username, - @Autowired @Value("${security.auth.password}") final String password - ) { - super(); - this.permitUris = permitUris.isEmpty() ? new String[] {"/v3/api-docs"} : permitUris.split("\\s{0,9},\\s{0,9}"); - this.username = username; - this.password = password; - } - - @Override - // The team decided to disable default CSRF Spring protection and not implement CSRF tokens validation. - // ncmp is a stateless REST API that is not as vulnerable to CSRF attacks as web applications running in - // web browsers are. ncmp does not manage sessions, each request requires the authentication token in the header. - // See https://docs.spring.io/spring-security/site/docs/5.3.8.RELEASE/reference/html5/#csrf - @SuppressWarnings("squid:S4502") - protected void configure(final HttpSecurity http) throws Exception { - http - .csrf().disable() - .authorizeRequests() - .antMatchers(permitUris).permitAll() - .anyRequest().authenticated() - .and().httpBasic(); - } - - @Override - protected void configure(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser(username).password("{noop}" + password).roles(USER_ROLE); - } -} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/Application.java b/src/main/java/org/onap/cps/ncmp/dmi/Application.java new file mode 100644 index 00000000..69d21ba1 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/Application.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(final String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java new file mode 100644 index 00000000..a9970da8 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/config/CpsConfiguration.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * Provides access to cps base url and cps authentication. + */ +@Configuration +public class CpsConfiguration { + + @Getter + @Component + public static class CpsProperties { + + @Value("${cps-core.baseUrl}") + private String baseUrl; + @Value("${cps-core.dmiRegistrationUrl}") + private String dmiRegistrationUrl; + @Value("${cps-core.auth.username}") + private String authUsername; + @Value("${cps-core.auth.password}") + private String authPassword; + } + + @Bean + public RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) { + return restTemplateBuilder.build(); + } +} \ No newline at end of file diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java new file mode 100644 index 00000000..33d6ae89 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiPluginConfig.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + + +@Configuration +public class DmiPluginConfig { + /** + * Swagger-ui configuration. + */ + @Bean("dmi-plugin-docket") + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .groupName("dmi-plugin-docket") + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + } +} + diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java new file mode 100644 index 00000000..a51d4862 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/config/WebSecurityConfig.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +/** + * Configuration class to implement application security. + * It enforces Basic Authentication access control. + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + private static final String USER_ROLE = "USER"; + + private final String username; + private final String password; + private final String[] permitUris; + + /** + * Constructor. Accepts parameters from configuration. + * + * @param permitUris comma-separated list of uri patterns for endpoints permitted + * @param username username + * @param password password + */ + public WebSecurityConfig( + @Autowired @Value("${security.permit-uri}") final String permitUris, + @Autowired @Value("${security.auth.username}") final String username, + @Autowired @Value("${security.auth.password}") final String password + ) { + super(); + this.permitUris = permitUris.isEmpty() ? new String[] {"/v3/api-docs"} : permitUris.split("\\s{0,9},\\s{0,9}"); + this.username = username; + this.password = password; + } + + @Override + // The team decided to disable default CSRF Spring protection and not implement CSRF tokens validation. + // ncmp is a stateless REST API that is not as vulnerable to CSRF attacks as web applications running in + // web browsers are. ncmp does not manage sessions, each request requires the authentication token in the header. + // See https://docs.spring.io/spring-security/site/docs/5.3.8.RELEASE/reference/html5/#csrf + @SuppressWarnings("squid:S4502") + protected void configure(final HttpSecurity http) throws Exception { + http + .csrf().disable() + .authorizeRequests() + .antMatchers(permitUris).permitAll() + .anyRequest().authenticated() + .and().httpBasic(); + } + + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().withUser(username).password("{noop}" + password).roles(USER_ROLE); + } +} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java new file mode 100644 index 00000000..c4cbaece --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.rest.controller; + +import org.onap.cps.ncmp.dmi.service.DmiService; +import org.onap.cps.ncmp.rest.api.DmiPluginApi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping("${rest.api.dmi-base-path}") +@RestController +public class DmiRestController implements DmiPluginApi { + + @Autowired + private DmiService dmiService; + + @Override + public ResponseEntity helloWorld() { + final var helloWorld = dmiService.getHelloWorld(); + return new ResponseEntity<>(helloWorld, HttpStatus.OK); + } + +} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java new file mode 100644 index 00000000..84c60d55 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.service; + +/** + * Interface for handling Dmi plugin Data. + */ +public interface DmiService { + /** + * Return Simple Hello World Statement. + */ + String getHelloWorld(); +} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java new file mode 100644 index 00000000..5051b1ad --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.service; + +import org.springframework.stereotype.Service; + +@Service +public class DmiServiceImpl implements DmiService { + + @Override + public String getHelloWorld() { + return "Hello World"; + } +} diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java new file mode 100644 index 00000000..2158e836 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.cps.ncmp.dmi.service.client; + +import org.onap.cps.ncmp.dmi.config.CpsConfiguration.CpsProperties; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +public class NcmpRestClient { + + private CpsProperties cpsProperties; + private RestTemplate restTemplate; + + public NcmpRestClient(final CpsProperties cpsProperties, final RestTemplate restTemplate) { + this.cpsProperties = cpsProperties; + this.restTemplate = restTemplate; + } + + /** + * Register a cmHandle with NCMP using a HTTP call. + * @param jsonData json data + * @return the response entity + */ + public ResponseEntity registerCmHandlesWithNcmp(final String jsonData) { + final var ncmpRegistrationUrl = buildNcmpRegistrationUrl(); + final var httpHeaders = new HttpHeaders(); + httpHeaders.setBasicAuth(cpsProperties.getAuthUsername(), cpsProperties.getAuthPassword()); + httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); + final var httpEntity = new HttpEntity<>(jsonData, httpHeaders); + return restTemplate.postForEntity(ncmpRegistrationUrl, httpEntity, String.class); + } + + private String buildNcmpRegistrationUrl() { + return UriComponentsBuilder + .fromHttpUrl(cpsProperties.getBaseUrl()) + .path(cpsProperties.getDmiRegistrationUrl()) + .toUriString(); + } +} \ No newline at end of file diff --git a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java deleted file mode 100644 index 16fb73a8..00000000 --- a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp.rest.controller; - -import org.onap.cps.ncmp.rest.api.DmiPluginApi; -import org.onap.cps.ncmp.service.DmiService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RequestMapping("${rest.api.dmi-base-path}") -@RestController -public class DmiRestController implements DmiPluginApi { - - @Autowired - private DmiService dmiService; - - @Override - public ResponseEntity helloWorld() { - final var helloWorld = dmiService.getHelloWorld(); - return new ResponseEntity<>(helloWorld, HttpStatus.OK); - } - -} diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/service/DmiService.java deleted file mode 100644 index 48509d98..00000000 --- a/src/main/java/org/onap/cps/ncmp/service/DmiService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp.service; - -/** - * Interface for handling Dmi plugin Data. - */ -public interface DmiService { - /** - * Return Simple Hello World Statement. - */ - String getHelloWorld(); -} diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java deleted file mode 100644 index f84039bb..00000000 --- a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.cps.ncmp.service; - -import org.springframework.stereotype.Service; - -@Service -public class DmiServiceImpl implements DmiService { - - @Override - public String getHelloWorld() { - return "Hello World"; - } -} -- cgit 1.2.3-korg