source: sources/app/src/main/java/parkup/configs/WebSecurityConfig.java@ 3a58bd6

Last change on this file since 3a58bd6 was ce6ad22, checked in by DavidTrajkovski <davidtrajkovski11@…>, 3 years ago

v1 initial prototype

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package parkup.configs;
2
3import org.springframework.context.annotation.Bean;
4import org.springframework.context.annotation.Configuration;
5import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
6import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11import parkup.services.AdministratorService;
12
13@Configuration
14@EnableWebSecurity
15public 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}
Note: See TracBrowser for help on using the repository browser.