3a39d7821ded4f6985e0e64e71ee429a685840c3
[ccsdk/cds.git] /
1 /*\r
2  *  Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.security;\r
18 \r
19 import com.att.eelf.configuration.EELFLogger;\r
20 import com.att.eelf.configuration.EELFManager;\r
21 import org.springframework.beans.factory.annotation.Autowired;\r
22 import org.springframework.beans.factory.annotation.Value;\r
23 import org.springframework.context.annotation.Bean;\r
24 import org.springframework.context.annotation.Configuration;\r
25 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;\r
26 import org.springframework.security.config.annotation.web.builders.HttpSecurity;\r
27 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;\r
28 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;\r
29 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;\r
30 import org.springframework.security.crypto.password.PasswordEncoder;\r
31 \r
32 @SuppressWarnings("unused")\r
33 @Configuration\r
34 @EnableWebSecurity\r
35 public class ApplicationSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {\r
36 \r
37     @Value("${basic-auth.user-name}")\r
38     private String userName;\r
39 \r
40     @Value("${basic-auth.hashed-pwd}")\r
41     private String userHashedPassword;\r
42 \r
43     private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationSecurityConfigurerAdapter.class);\r
44 \r
45     @Autowired\r
46     private ApplicationBasicAuthenticationEntryPoint authenticationEntryPoint;\r
47 \r
48     @Autowired\r
49     public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {\r
50         log.info("User Id {} and hashed pwd : {}", userName, userHashedPassword);\r
51         auth.inMemoryAuthentication()\r
52                 .withUser(userName).password(userHashedPassword)\r
53                 .authorities("ROLE_USER");\r
54     }\r
55 \r
56     @Override\r
57     protected void configure(HttpSecurity http) throws Exception {\r
58         http.authorizeRequests()\r
59                 .antMatchers("/actuator/health").permitAll()\r
60                 .antMatchers("/**").authenticated()\r
61                 .and()\r
62                 .httpBasic()\r
63                 .authenticationEntryPoint(authenticationEntryPoint);\r
64 \r
65         http.csrf().disable();\r
66     }\r
67 \r
68     @Bean\r
69     public PasswordEncoder passwordEncoder() {\r
70         return new BCryptPasswordEncoder();\r
71     }\r
72 }