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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.security;
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;
38 * @author Waqas Ikram (waqas.ikram@est.tech)
44 @Profile({"basic", "test"})
45 public class SoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
46 private static final Logger LOGGER = LoggerFactory.getLogger(SoWebSecurityConfigurerAdapter.class);
49 private HttpSecurityConfigurer httpSecurityConfigurer;
52 private UserDetailsService userDetailsService;
55 private BCryptPasswordEncoder passwordEncoder;
58 protected void configure(final HttpSecurity http) throws Exception {
59 LOGGER.debug("Injecting {} configuration ...", httpSecurityConfigurer.getClass());
61 httpSecurityConfigurer.configure(http);
65 public void configure(final WebSecurity web) throws Exception {
67 final StrictHttpFirewall firewall = new MSOSpringFirewall();
68 web.httpFirewall(firewall);
72 protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
73 auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);