2 * Copyright © 2017-2018 AT&T Intellectual Property.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.onap.ccsdk.apps.controllerblueprints.security;
\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
32 @SuppressWarnings("unused")
\r
35 public class ApplicationSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
\r
37 @Value("${basic-auth.user-name}")
\r
38 private String userName;
\r
40 @Value("${basic-auth.hashed-pwd}")
\r
41 private String userHashedPassword;
\r
43 private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationSecurityConfigurerAdapter.class);
\r
46 private ApplicationBasicAuthenticationEntryPoint authenticationEntryPoint;
\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
57 protected void configure(HttpSecurity http) throws Exception {
\r
58 http.authorizeRequests()
\r
59 .antMatchers("/actuator/health").permitAll()
\r
60 .antMatchers("/**").authenticated()
\r
63 .authenticationEntryPoint(authenticationEntryPoint);
\r
65 http.csrf().disable();
\r
69 public PasswordEncoder passwordEncoder() {
\r
70 return new BCryptPasswordEncoder();
\r