Changed Basic Authorization in receiving Notification 91/101191/7
authorPiotr Borelowski <p.borelowski@partner.samsung.com>
Wed, 5 Feb 2020 18:01:45 +0000 (19:01 +0100)
committerPiotr Borelowski <p.borelowski@partner.samsung.com>
Fri, 7 Feb 2020 08:14:26 +0000 (08:14 +0000)
Ve-Vnfm (SOL002) Adapter project

Issue-ID: SO-2574
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: I95dfebd0e024af91b9bac4d8a4bb97d271badc70

adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/Application.java
adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java [deleted file]
adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java
adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml
common/src/main/java/org/onap/so/security/SoBasicWebSecurityConfigurerAdapter.java

index e4a6bed..875fddd 100644 (file)
@@ -26,7 +26,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 @SpringBootApplication(scanBasePackages = {"org.onap.so"})
 public class Application {
 
+    public static final String BASIC_PROFILE = "basic";
+
     public static void main(final String... args) {
-        SpringApplication.run(Application.class, args);
+        final SpringApplication springApplication = new SpringApplication(Application.class);
+        springApplication.setAdditionalProfiles(BASIC_PROFILE);
+        springApplication.run(args);
     }
 }
diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/configuration/SecurityConfiguration.java
deleted file mode 100644 (file)
index cc56048..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SO
- * ================================================================================
- * Copyright (C) 2020 Samsung. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.adapters.vevnfm.configuration;
-
-import org.onap.so.security.SoBasicWebSecurityConfigurerAdapter;
-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.crypto.password.PasswordEncoder;
-
-@Configuration
-@EnableWebSecurity
-public class SecurityConfiguration extends SoBasicWebSecurityConfigurerAdapter {
-
-    @Value("${notification.url}")
-    private String notificationUrl;
-
-    @Value("${notification.username}")
-    private String notificationUsername;
-
-    @Value("${notification.password}")
-    private String notificationPassword;
-
-    @Autowired
-    private PasswordEncoder passwordEncoder;
-
-    @Override
-    protected void configure(final HttpSecurity https) throws Exception {
-        https.csrf().disable().authorizeRequests().antMatchers(notificationUrl).authenticated().and().httpBasic();
-    }
-
-    @Override
-    protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
-        auth.inMemoryAuthentication().withUser(notificationUsername)
-                .password(passwordEncoder.encode(notificationPassword)).authorities("ROLE_USER");
-    }
-}
index aa07ed6..c1a56fb 100644 (file)
@@ -43,11 +43,11 @@ public class SubscriberService {
     @Value("${notification.url}")
     private String notificationUrl;
 
-    @Value("${notification.username}")
-    private String notificationUsername;
+    @Value("${spring.security.usercredentials[0].username}")
+    private String username;
 
-    @Value("${notification.password}")
-    private String notificationPassword;
+    @Value("${spring.security.usercredentials[0].openpass}")
+    private String openpass;
 
     @Autowired
     private SubscribeSender sender;
@@ -62,8 +62,8 @@ public class SubscriberService {
         request.callbackUri(getCallbackUri());
         final SubscriptionsAuthenticationParamsBasic paramsBasic = new SubscriptionsAuthenticationParamsBasic();
         final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication();
-        paramsBasic.setUserName(notificationUsername);
-        paramsBasic.setPassword(notificationPassword);
+        paramsBasic.setUserName(username);
+        paramsBasic.setPassword(openpass);
         authentication.setAuthType(Collections.singletonList(SubscriptionsAuthentication.AuthTypeEnum.BASIC));
         authentication.setParamsBasic(paramsBasic);
         request.authentication(authentication);
index b16fa63..f3ad961 100644 (file)
@@ -22,8 +22,6 @@ system:
 
 notification:
   url: /lcm/v1/vnf/instances/notifications
-  username: admin
-  password: a4b3c2d1
 
 mso:
   key: 07a7159d3bf51a0e53be7a8f89699be7
@@ -36,6 +34,12 @@ vnfm:
   subscription: /vnflcm/v1/subscriptions
 
 spring:
+  security:
+    usercredentials:
+      - username: admin
+        openpass: a4b3c2d1
+        password: '$2a$10$vU.mWyNTsikAxXIA5c269ewCpAbYTiyMS0m1N.kn4F2CSGEnrKN7K'
+        role: USER
   http:
     converters:
       preferred-json-mapper: gson
index c778dde..21176e0 100644 (file)
@@ -28,6 +28,8 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.builders.WebSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.security.web.firewall.StrictHttpFirewall;
 import org.springframework.util.StringUtils;
 
@@ -44,6 +46,12 @@ public class SoBasicWebSecurityConfigurerAdapter extends WebSecurityConfigurerAd
     @Autowired
     private SoUserCredentialConfiguration soUserCredentialConfiguration;
 
+    @Autowired
+    private UserDetailsService userDetailsService;
+
+    @Autowired
+    private BCryptPasswordEncoder passwordEncoder;
+
     @Override
     protected void configure(final HttpSecurity http) throws Exception {
         http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll()
@@ -61,8 +69,6 @@ public class SoBasicWebSecurityConfigurerAdapter extends WebSecurityConfigurerAd
 
     @Override
     protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
-        auth.userDetailsService(soUserCredentialConfiguration.userDetailsService())
-                .passwordEncoder(soUserCredentialConfiguration.passwordEncoder());
+        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
     }
-
 }