1 | package parkup.configs;
|
---|
2 |
|
---|
3 | import org.springframework.context.annotation.Bean;
|
---|
4 | import org.springframework.context.annotation.Configuration;
|
---|
5 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
---|
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
---|
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
---|
8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
---|
9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
---|
10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
---|
11 | import parkup.services.AdministratorService;
|
---|
12 |
|
---|
13 | @Configuration
|
---|
14 | @EnableWebSecurity
|
---|
15 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
---|
16 |
|
---|
17 | private final AdministratorService administratorService;
|
---|
18 | private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
---|
19 |
|
---|
20 | public WebSecurityConfig(AdministratorService administratorService, BCryptPasswordEncoder bCryptPasswordEncoder) {
|
---|
21 | this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
---|
22 | this.administratorService = administratorService;
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | protected void configure(HttpSecurity http) throws Exception {
|
---|
27 | http
|
---|
28 | .csrf().disable()
|
---|
29 | .authorizeRequests()
|
---|
30 | .antMatchers("/administrator/registration/**")
|
---|
31 | .permitAll()
|
---|
32 | .anyRequest()
|
---|
33 | .authenticated().and()
|
---|
34 | .formLogin();
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
---|
39 | auth.authenticationProvider(daoAuthenticationProvider());
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Bean
|
---|
43 | public DaoAuthenticationProvider daoAuthenticationProvider(){
|
---|
44 | DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
---|
45 | provider.setPasswordEncoder(bCryptPasswordEncoder);
|
---|
46 | provider.setUserDetailsService(administratorService);
|
---|
47 | return provider;
|
---|
48 | }
|
---|
49 | } |
---|