2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.services.dmaapService;
24 import java.util.Properties;
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;
36 public class AuthenticationConfig extends WebSecurityConfigurerAdapter {
38 private final String PROPERTIES_PREFIX = "appc.srvcomm.messaging";
39 private final String DEFAULT_USER = "appc";
40 private final String DEFAULT_PASSWORD = "onapappc";
43 protected void configure(HttpSecurity http) throws Exception {
44 http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic();
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");
57 pass = DEFAULT_PASSWORD;
59 auth.inMemoryAuthentication().withUser(user).password(encoder().encode(pass)).roles("USER");
63 public PasswordEncoder encoder() {
64 return new BCryptPasswordEncoder();