diff options
author | 2019-08-06 16:15:02 +0000 | |
---|---|---|
committer | 2019-08-06 16:15:17 +0000 | |
commit | 76a500eff0629b105fd276194c5dd093e0f60d9d (patch) | |
tree | 7aafbd6f48515d5acc5857ca4ffa8f4279fc8a33 | |
parent | cb99c281be08a1946c291e3ee700439620ee179f (diff) |
Adding basic support for sdnc sim
Change-Id: I84ff3c7c22642d41f77cc2ce789b1cc711da9729
Issue-ID: SO-1950
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
25 files changed, 475 insertions, 122 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml index 3c3ed718..428aeb7b 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml @@ -7,13 +7,16 @@ <version>1.0-SNAPSHOT</version> </parent> <artifactId>aai-simulator</artifactId> - <properties> <version.aai.schema>1.0.0</version.aai.schema> </properties> - <dependencies> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.onap.aai.schema-service</groupId> <artifactId>aai-schema</artifactId> <version>${version.aai.schema}</version> @@ -38,7 +41,6 @@ <scope>test</scope> </dependency> </dependencies> - <build> <plugins> <plugin> @@ -61,5 +63,4 @@ </plugin> </plugins> </build> - </project>
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java index eb92c246..1dc483f7 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java @@ -20,15 +20,12 @@ package org.onap.so.aaisimulator.configration; import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.simulator.configuration.SimulatorSecurityConfigurer; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; 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; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; /** * @author waqas.ikram@ericsson.com @@ -36,36 +33,17 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; */ @Configuration @EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { +public class WebSecurityConfigImpl extends SimulatorSecurityConfigurer { - private final String username; - private final String password; - private final String role; - - public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, - @Value("${spring.security.password}") final String password, - @Value("${spring.security.role}") final String role) { - this.username = username; - this.password = password; - this.role = role; + @Autowired + public WebSecurityConfigImpl(final UserCredentials userCredentials) { + super(userCredentials.getUsers()); } - @Override protected void configure(final HttpSecurity http) throws Exception { http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() .httpBasic(); } - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Autowired - public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) - .roles(role); - } - } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java index 374737ec..1d12a94d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -28,6 +28,7 @@ import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.ServiceSubscription; import org.onap.aai.domain.yang.ServiceSubscriptions; import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java index 7e8450f7..156abd24 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java @@ -23,6 +23,7 @@ import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import org.onap.so.aaisimulator.models.NodeServiceInstance; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java index 32590cb0..58a8b1e6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java @@ -25,6 +25,7 @@ import java.util.Optional; import org.onap.aai.domain.yang.OwningEntity; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java index 047a3881..3ddefbe6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java @@ -25,6 +25,7 @@ import java.util.Optional; import org.onap.aai.domain.yang.Project; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml index d4f42992..25be8dab 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml @@ -3,15 +3,14 @@ server: tomcat: max-threads: 4 ssl: - key-store: classpath:keystore/org.onap.so.p12 - key-store-password: 'u!@JQoYD])@ykq.NKM,O7iA.' - keyStoreType: PKCS12 + key-store: classpath:keystore/org.onap.so.p12 + key-store-password: u!@JQoYD])@ykq.NKM,O7iA. + keyStoreType: PKCS12 ssl-enable: true - spring: security: - username: aai - #password: aai.onap.org:demo123456! - password: $2a$04$crRntT01fAF4kb48mxlvgu68/silcLg.czC1LxQsKTdWuDBPpO3YO - role: VID -
\ No newline at end of file + users: + - username: aai + #password: aai.onap.org:demo123456! + password: $2a$04$crRntT01fAF4kb48mxlvgu68/silcLg.czC1LxQsKTdWuDBPpO3YO + role: VID
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java index 478651cc..ef49716a 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java @@ -48,8 +48,8 @@ import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.RequestError; import org.onap.so.aaisimulator.utils.ServiceException; import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -83,8 +83,8 @@ public class BusinessControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private CustomerCacheServiceProvider cacheServiceProvider; @@ -384,7 +384,7 @@ public class BusinessControllerTest { } private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } private String getServiceInstance() throws Exception, IOException { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java index 59246f56..50ab04c6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java @@ -44,8 +44,8 @@ import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -75,8 +75,8 @@ public class NodesControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private NodesCacheServiceProvider nodesCacheServiceProvider; @@ -175,6 +175,6 @@ public class NodesControllerTest { } private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java index a443a458..7f825db8 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java @@ -38,8 +38,8 @@ import org.onap.so.aaisimulator.models.Result; import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -74,8 +74,8 @@ public class OwningEntityControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private OwnEntityCacheServiceProvider cacheServiceProvider; @@ -153,7 +153,11 @@ public class OwningEntityControllerTest { } private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(getUsername())), clazz); + } + + private String getUsername() { + return userCredentials.getUsers().iterator().next().getUsername(); } private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { @@ -162,7 +166,7 @@ public class OwningEntityControllerTest { } private HttpEntity<?> getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); + return new HttpEntity<>(obj, getHttpHeaders(getUsername())); } private String getOwningEntityEndPointUrl() { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java index 1b702513..e7b067db 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java @@ -36,8 +36,8 @@ import org.onap.so.aaisimulator.models.Result; import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -74,8 +74,8 @@ public class ProjectControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private ProjectCacheServiceProvider cacheServiceProvider; @@ -147,7 +147,7 @@ public class ProjectControllerTest { } private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(getUsername())), clazz); } private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { @@ -156,7 +156,11 @@ public class ProjectControllerTest { } private HttpEntity<?> getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); + return new HttpEntity<>(obj, getHttpHeaders(getUsername())); + } + + private String getUsername() { + return userCredentials.getUsers().iterator().next().getUsername(); } private String getProjectEndPointUrl() { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java index fecfd85a..4dfe9c2c 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java @@ -33,7 +33,6 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; * @author waqas.ikram@ericsson.com * */ - public class TestUtils { private static final String PASSWORD = "aai.onap.org:demo123456!"; diff --git a/plans/so/integration-etsi-testing/so-simulators/common/pom.xml b/plans/so/integration-etsi-testing/so-simulators/common/pom.xml new file mode 100644 index 00000000..497e8213 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/pom.xml @@ -0,0 +1,38 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.so.simulators</groupId> + <artifactId>so-simulators</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>common</artifactId> + <properties> + <version.equalsverifier>2.5.1</version.equalsverifier> + <version.openpojo>0.8.6</version.openpojo> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <version>${version.equalsverifier}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.openpojo</groupId> + <artifactId>openpojo</artifactId> + <version>${version.openpojo}</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/cache/provider/AbstractCacheServiceProvider.java index 35e35917..ae31a3ff 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/cache/provider/AbstractCacheServiceProvider.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aaisimulator.service.providers; +package org.onap.so.simulator.cache.provider; import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; @@ -26,8 +26,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; /** - * @author waqas.ikram@ericsson.com - * + * @author Waqas Ikram (waqas.ikram@ericsson.com) */ public abstract class AbstractCacheServiceProvider { diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/configuration/SimulatorSecurityConfigurer.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/configuration/SimulatorSecurityConfigurer.java new file mode 100644 index 00000000..d2cf0049 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/configuration/SimulatorSecurityConfigurer.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.so.simulator.configuration; + +import java.util.List; +import org.onap.so.simulator.model.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public abstract class SimulatorSecurityConfigurer extends WebSecurityConfigurerAdapter { + + private final List<User> users; + + public SimulatorSecurityConfigurer(final List<User> users) { + this.users = users; + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Autowired + public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { + final InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuthentication = + auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()); + for (int index = 0; index < users.size(); index++) { + final User user = users.get(index); + inMemoryAuthentication.withUser(user.getUsername()).password(user.getPassword()).roles(user.getRole()); + if (index < users.size()) { + inMemoryAuthentication.and(); + } + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.java new file mode 100644 index 00000000..48d5622a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.so.simulator.model; + +import static org.springframework.util.ObjectUtils.nullSafeEquals; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class User { + private String username; + private String password; + private String role; + + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(final String username) { + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(final String password) { + this.password = password; + } + + /** + * @return the role + */ + public String getRole() { + return role; + } + + /** + * @param role the role to set + */ + public void setRole(final String role) { + this.role = role; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((role == null) ? 0 : role.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof User) { + final User other = (User) obj; + return nullSafeEquals(this.username, other.username) && nullSafeEquals(this.password, other.password) + && nullSafeEquals(this.role, other.role); + } + return false; + } + + @Override + public String toString() { + return "UserCredential [username=" + username + ", password=" + password + ", role=" + role + "]"; + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java new file mode 100644 index 00000000..f12c2475 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.so.simulator.model; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +@ConfigurationProperties(prefix = "spring.security") +public class UserCredentials { + + private final List<User> users = new ArrayList<>(); + + public List<User> getUsers() { + return users; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((users == null) ? 0 : users.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + + if (obj instanceof UserCredentials) { + final UserCredentials other = (UserCredentials) obj; + return ObjectUtils.nullSafeEquals(users, other.users); + } + + return false; + } + + @Override + public String toString() { + return "UserCredentials [userCredentials=" + users + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.java b/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.java new file mode 100644 index 00000000..8ae9b8b7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.so.simulator.model; + +import org.junit.Test; +import org.onap.so.simulator.model.UserCredentials; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PojoClassesTest { + + @Test + public void test_UserCredentials_class() throws ClassNotFoundException { + verify(UserCredentials.class); + validate(UserCredentials.class); + } + + @Test + public void test_User_class() throws ClassNotFoundException { + verify(User.class); + validate(User.class); + } + + private void validate(final Class<?> clazz) { + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()).build(); + validator.validate(PojoClassFactory.getPojoClass(clazz)); + } + + private void verify(final Class<?> clazz) { + EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/pom.xml b/plans/so/integration-etsi-testing/so-simulators/pom.xml index ee895a46..08d962b7 100644 --- a/plans/so/integration-etsi-testing/so-simulators/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/pom.xml @@ -17,6 +17,7 @@ </properties> <modules> + <module>common</module> <module>sdc-simulator</module> <module>aai-simulator</module> <module>sdnc-simulator</module> diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml index 22994ff0..0806d88c 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml @@ -13,6 +13,11 @@ </properties> <dependencies> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.onap.sdnc.northbound</groupId> <artifactId>generic-resource-api-client</artifactId> <version>${version.generic-resource-api-client}</version> @@ -27,6 +32,16 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> <build> <plugins> diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.java new file mode 100644 index 00000000..261b66d7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.so.sdncsimulator.configration; + +import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL; +import org.onap.so.simulator.configuration.SimulatorSecurityConfigurer; +import org.onap.so.simulator.model.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfigImpl extends SimulatorSecurityConfigurer { + + @Autowired + public WebSecurityConfigImpl(final UserCredentials userCredentials) { + super(userCredentials.getUsers()); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers(OPERATIONS_URL + "/**/**").authenticated().and() + .httpBasic(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/AbstractCacheServiceProvider.java deleted file mode 100644 index 55e6f541..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/AbstractCacheServiceProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 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.so.sdncsimulator.providers; - -import java.util.concurrent.ConcurrentHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - */ -public abstract class AbstractCacheServiceProvider { - - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); - - private final CacheManager cacheManager; - - public AbstractCacheServiceProvider(final CacheManager cacheManager) { - this.cacheManager = cacheManager; - } - - protected void clearCahce(final String name) { - final Cache cache = cacheManager.getCache(name); - if (cache != null) { - final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache(); - LOGGER.info("Clear all entries from cahce: {}", cache.getName()); - nativeCache.clear(); - } - } - - protected Cache getCache(final String name) { - return cacheManager.getCache(name); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java index 9436d224..37773e1f 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java @@ -47,6 +47,7 @@ import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServ import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier; import org.onap.so.sdncsimulator.models.OutputRequest; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml index bcd8d5fc..95b28455 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml @@ -2,4 +2,15 @@ server: port: 9994 tomcat: max-threads: 4 -ssl-enable: false
\ No newline at end of file +ssl-enable: false +spring: + security: + users: + - username: mso + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$f8SB6cW/VI26QvYM6z.GXu7hlEmwnFtePenD8zF18mS3Atu3QNqr2 + role: VID + - username: admin + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$f8SB6cW/VI26QvYM6z.GXu7hlEmwnFtePenD8zF18mS3Atu3QNqr2 + role: VID
\ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java index 36e12089..bcfff95e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Base64; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +35,7 @@ import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.OutputRequest; import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider; import org.onap.so.sdncsimulator.utils.Constants; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -66,6 +68,8 @@ public class OperationsControllerTest { private static final String SERVICE_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:service-topology-operation/"; + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + @LocalServerPort private int port; @@ -75,6 +79,10 @@ public class OperationsControllerTest { @Autowired private ServiceOperationsCacheServiceProvider cacheServiceProvider; + @Autowired + private UserCredentials userCredentials; + + @Test public void test_postServiceOperationInformation_successfullyAddedToCache() throws Exception { @@ -127,9 +135,7 @@ public class OperationsControllerTest { } private HttpHeaders getHttpHeaders() { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; + return getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } @@ -149,10 +155,21 @@ public class OperationsControllerTest { return new String(Files.readAllBytes(path)); } - private static File getFile(final String file) throws IOException { + private File getFile(final String file) throws IOException { return new ClassPathResource(file).getFile(); } + private HttpHeaders getHttpHeaders(final String username) { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + private String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + @After public void after() { cacheServiceProvider.clearAll(); |