Change code to use dmaap microservice
[appc.git] / services / appc-dmaap-service / appc-dmaap-event-service / src / main / java / org / onap / appc / services / dmaapService / AuthenticationConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * 
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.services.dmaapService;
23
24 import java.util.Properties;
25
26 import org.onap.appc.configuration.ConfigurationFactory;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
30 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
31 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
32 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
33 import org.springframework.security.crypto.password.PasswordEncoder;
34
35 @Configuration
36 public class AuthenticationConfig extends WebSecurityConfigurerAdapter {
37     
38     private final String PROPERTIES_PREFIX = "appc.srvcomm.messaging";
39     private final String DEFAULT_USER = "appc";
40     private final String DEFAULT_PASSWORD = "onapappc";
41
42     @Override
43     protected void configure(HttpSecurity http) throws Exception {
44         http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();
45     }
46     
47     @Override
48     protected void configure(AuthenticationManagerBuilder auth) throws Exception {
49         org.onap.appc.configuration.Configuration configuration = ConfigurationFactory.getConfiguration();
50         Properties props = configuration.getProperties();
51         String user = props.getProperty(PROPERTIES_PREFIX + ".user");
52         String pass = props.getProperty(PROPERTIES_PREFIX + ".pass");
53         if(user == null) {
54             user = DEFAULT_USER;
55         }
56         if(pass == null) {
57             pass = DEFAULT_PASSWORD;
58         }
59         auth.inMemoryAuthentication().withUser(user).password(encoder().encode(pass)).roles("USER");
60     }
61     
62     @Bean
63     public PasswordEncoder encoder() {
64         return new BCryptPasswordEncoder();
65     }
66
67 }