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