Fix for SO-2598
[so.git] / common / src / main / java / org / onap / so / security / SoWebSecurityConfigurerAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.security;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.context.annotation.Configuration;
26 import org.springframework.context.annotation.Profile;
27 import org.springframework.core.annotation.Order;
28 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
29 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
30 import org.springframework.security.config.annotation.web.builders.WebSecurity;
31 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
32 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
33 import org.springframework.security.core.userdetails.UserDetailsService;
34 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
35 import org.springframework.security.web.firewall.StrictHttpFirewall;
36
37 /**
38  * @author Waqas Ikram (waqas.ikram@est.tech)
39  *
40  */
41 @EnableWebSecurity
42 @Configuration
43 @Order(1)
44 @Profile({"basic", "test"})
45 public class SoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
46     private static final Logger LOGGER = LoggerFactory.getLogger(SoWebSecurityConfigurerAdapter.class);
47
48     @Autowired
49     private HttpSecurityConfigurer httpSecurityConfigurer;
50
51     @Autowired
52     private UserDetailsService userDetailsService;
53
54     @Autowired
55     private BCryptPasswordEncoder passwordEncoder;
56
57     @Override
58     protected void configure(final HttpSecurity http) throws Exception {
59         LOGGER.debug("Injecting {} configuration ...", httpSecurityConfigurer.getClass());
60
61         httpSecurityConfigurer.configure(http);
62     }
63
64     @Override
65     public void configure(final WebSecurity web) throws Exception {
66         super.configure(web);
67         final StrictHttpFirewall firewall = new MSOSpringFirewall();
68         web.httpFirewall(firewall);
69     }
70
71     @Override
72     protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
73         auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
74     }
75 }