1 | package parkup.configs.webConfigs;
|
---|
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.RegistriranParkiracService;
|
---|
12 | import parkup.services.VrabotenService;
|
---|
13 |
|
---|
14 | @EnableWebSecurity
|
---|
15 | @Configuration
|
---|
16 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
---|
17 | private final VrabotenService vrabotenService;
|
---|
18 | private final BCryptPasswordEncoder bCryptPasswordEncoder;
|
---|
19 | private final RegistriranParkiracService registriranParkiracService;
|
---|
20 |
|
---|
21 | public WebSecurityConfig(VrabotenService vrabotenService, BCryptPasswordEncoder bCryptPasswordEncoder, RegistriranParkiracService registriranParkiracService) {
|
---|
22 | this.vrabotenService = vrabotenService;
|
---|
23 | this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
---|
24 | this.registriranParkiracService = registriranParkiracService;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | protected void configure(HttpSecurity http) throws Exception {
|
---|
29 | http
|
---|
30 | .csrf().disable()
|
---|
31 | .authorizeRequests()
|
---|
32 | .antMatchers("/registriranParkirac/registration/**")
|
---|
33 | .permitAll()
|
---|
34 | .anyRequest()
|
---|
35 | .authenticated().and().formLogin();//ruta na viktor
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
---|
40 | auth.authenticationProvider(daoAuthenticationProviderW());
|
---|
41 | auth.authenticationProvider(daoAuthenticationProviderRP());
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Bean
|
---|
45 | public DaoAuthenticationProvider daoAuthenticationProviderW() {
|
---|
46 | DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
---|
47 | provider.setPasswordEncoder(bCryptPasswordEncoder);
|
---|
48 | provider.setUserDetailsService(vrabotenService);
|
---|
49 | return provider;
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Bean
|
---|
53 | public DaoAuthenticationProvider daoAuthenticationProviderRP(){
|
---|
54 | DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
---|
55 | provider.setPasswordEncoder(bCryptPasswordEncoder);
|
---|
56 | provider.setUserDetailsService(registriranParkiracService);
|
---|
57 | return provider;
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|