diff options
author | shivasubedi <shiva.subedi@est.tech> | 2021-06-23 16:31:02 +0100 |
---|---|---|
committer | shivasubedi <shiva.subedi@est.tech> | 2021-06-29 02:37:43 +0100 |
commit | 55500c3685dbc032c5cb79a727cc588d542e7d15 (patch) | |
tree | 2c8a8170b3610497fc3a6c737efd2b27d83bbf4b /src/main | |
parent | b5a238326e5fc5e240acb11f52748774c2f6da40 (diff) |
create quality params in dmi-plugin
Issue-ID: CPS-432
Issue-ID: CPS-403
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: I4ada1e4927a3726500396da64c454d9937f95bcf
Signed-off-by: shivasubedi <shiva.subedi@est.tech>
Diffstat (limited to 'src/main')
5 files changed, 152 insertions, 2 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java b/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java new file mode 100644 index 00000000..427ffe19 --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/config/DmiPluginConfig.java @@ -0,0 +1,45 @@ +/* + * ============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 new file mode 100644 index 00000000..34bfae9d --- /dev/null +++ b/src/main/java/org/onap/cps/ncmp/config/WebSecurityConfig.java @@ -0,0 +1,81 @@ +/* + * ============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/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java index 700ca82c..9507c695 100644 --- a/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java +++ b/src/main/java/org/onap/cps/ncmp/rest/controller/DmiRestController.java @@ -20,6 +20,8 @@ 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; @@ -29,9 +31,12 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class DmiRestController implements DmiPluginApi { + @Autowired + private DmiService dmiService; + @Override public ResponseEntity<Object> helloWorld() { - final var helloWorld = "Hello World"; + final var helloWorld = dmiService.getHelloWorld() ; return new ResponseEntity<>(helloWorld, HttpStatus.OK); } diff --git a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java index a1cecc3e..b0c140cd 100644 --- a/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/service/DmiServiceImpl.java @@ -19,6 +19,9 @@ package org.onap.cps.ncmp.service; +import org.springframework.stereotype.Service; + +@Service public class DmiServiceImpl implements DmiService { @Override diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 08466681..e506a546 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -26,4 +26,20 @@ security: permit-uri: /manage/health/**,/manage/info,/swagger-ui/**,/swagger-resources/**,/v3/api-docs auth: username: ${CPS_USERNAME} - password: ${CPS_PASSWORD}
\ No newline at end of file + password: ${CPS_PASSWORD} + +# Actuator +management: + endpoints: + web: + base-path: /manage + exposure: + include: info,health,loggers + endpoint: + health: + show-details: always + # kubernetes probes: liveness and readiness + probes: + enabled: true + loggers: + enabled: true |