diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-09-02 22:41:51 +0200 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-09-02 22:41:51 +0200 |
commit | f0924be187a9058bf1c024f885ac2ba7a8a90c74 (patch) | |
tree | 74dd6a750df103e50700ebb137f40afc4ba79880 | |
parent | 3cbc92527ad55c2c6a42748b72e7acfb9d55b3b4 (diff) |
Security configuration moved to separate class
Issue-ID: SO-3747
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com>
Change-Id: If470ea254b95711ad51839411d07aa49f7054f17
3 files changed, 62 insertions, 8 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/BasicSecurityConfig.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/BasicSecurityConfig.java new file mode 100644 index 0000000..32281b8 --- /dev/null +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/BasicSecurityConfig.java @@ -0,0 +1,58 @@ +package org.onap.so.adapters.cnf; + +import org.onap.so.security.UserCredentials; +import org.onap.so.security.UserDetailsServiceImpl; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; + +@Component +@ConfigurationProperties( + prefix = "spring.security" +) +public class BasicSecurityConfig { + private List<UserCredentials> credentials = new ArrayList(); + private final List<String> roles = new ArrayList(); + + public BasicSecurityConfig() { + } + + public List<String> getRoles() { + return this.roles; + } + + @PostConstruct + private void addRoles() { + for(int i = 0; i < this.credentials.size(); ++i) { + this.roles.add(((UserCredentials)this.credentials.get(i)).getRole()); + } + + } + + public List<UserCredentials> getUsercredentials() { + return this.credentials; + } + + public void setUsercredentials(final List<UserCredentials> usercredentials) { + if (usercredentials != null) { + this.credentials = usercredentials; + } + + } + + @Bean + public UserDetailsService userDetailsService() { + return new UserDetailsServiceImpl(); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java index f60aa94..0ba40e2 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java @@ -20,7 +20,6 @@ package org.onap.so.adapters.cnf; -import org.onap.so.security.SoUserCredentialConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -32,14 +31,10 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; import org.springframework.web.client.RestTemplate; @SpringBootApplication -@ComponentScan(basePackages = {"org.onap.so.adapters.cnf", "org.onap.so.security"}, - includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, - classes = SoUserCredentialConfiguration.class), @ComponentScan.Filter(type = FilterType.REGEX, - pattern="org.onap.so.adapters.cnf")}) +@ComponentScan(basePackages = {"org.onap.so.adapters.cnf"}) @EnableAutoConfiguration(exclude = {LiquibaseAutoConfiguration.class, HibernateJpaAutoConfiguration.class, DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, SecurityAutoConfiguration.class}) diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/SoCallbackClient.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/SoCallbackClient.java index 2ae0532..f2c605e 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/SoCallbackClient.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/client/SoCallbackClient.java @@ -1,6 +1,7 @@ package org.onap.so.adapters.cnf.client; import com.google.gson.Gson; +import org.onap.so.adapters.cnf.BasicSecurityConfig; import org.onap.so.security.SoUserCredentialConfiguration; import org.onap.so.security.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; @@ -22,12 +23,12 @@ public class SoCallbackClient { private final static Gson gson = new Gson(); private final RestTemplate restTemplate; - private final SoUserCredentialConfiguration userCredentialConfiguration; + private final BasicSecurityConfig userCredentialConfiguration; private final String role = "ACTUATOR"; private final UserCredentials credentials; @Autowired - public SoCallbackClient(RestTemplate restTemplate, SoUserCredentialConfiguration userCredentialConfiguration) { + public SoCallbackClient(RestTemplate restTemplate, BasicSecurityConfig userCredentialConfiguration) { this.restTemplate = restTemplate; this.userCredentialConfiguration = userCredentialConfiguration; if (!userCredentialConfiguration.getRoles().contains(role)) |