source: sources/app/src/main/java/parkup/configs/webConfigs/WebSecurityConfig.java@ e8b1076

Last change on this file since e8b1076 was e8b1076, checked in by DavidTrajkovski <davidtrajkovski11@…>, 2 years ago

guest login

  • Property mode set to 100644
File size: 3.8 KB
Line 
1package parkup.configs.webConfigs;
2
3import org.springframework.context.annotation.Bean;
4import org.springframework.context.annotation.Configuration;
5import org.springframework.security.authentication.AuthenticationManager;
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 org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
12import org.springframework.web.cors.CorsConfiguration;
13import parkup.configs.CustomAuthenticationFilter;
14import parkup.configs.CustomAuthorizationFilter;
15import parkup.services.AdministratorService;
16import parkup.services.GuestService;
17import parkup.services.RegisteredUserService;
18import parkup.services.WorkerService;
19
20import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
21
22@EnableWebSecurity
23@Configuration
24public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
25 private final WorkerService workerService;
26 private final BCryptPasswordEncoder bCryptPasswordEncoder;
27 private final RegisteredUserService registeredUserService;
28 private final AdministratorService administratorService;
29 private final GuestService guestService;
30
31 public WebSecurityConfig(WorkerService workerService, BCryptPasswordEncoder bCryptPasswordEncoder, RegisteredUserService registeredUserService, AdministratorService administratorService, GuestService guestService) {
32 this.workerService = workerService;
33 this.bCryptPasswordEncoder = bCryptPasswordEncoder;
34 this.registeredUserService = registeredUserService;
35 this.administratorService = administratorService;
36 this.guestService = guestService;
37 }
38
39 @Override
40 protected void configure(AuthenticationManagerBuilder auth) throws Exception {
41 auth.userDetailsService(registeredUserService).passwordEncoder(bCryptPasswordEncoder);
42 auth.userDetailsService(workerService).passwordEncoder(bCryptPasswordEncoder);
43 auth.userDetailsService(administratorService).passwordEncoder(bCryptPasswordEncoder);
44 auth.userDetailsService(guestService);
45 }
46
47 @Override
48 protected void configure(HttpSecurity http) throws Exception {
49 CustomAuthenticationFilter customAuthenticationFilter = new CustomAuthenticationFilter(authenticationManagerBean());
50 customAuthenticationFilter.setFilterProcessesUrl("/api/login");
51 http.csrf().disable();
52 http.cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues());
53 http.sessionManagement().sessionCreationPolicy(STATELESS);
54 http.authorizeRequests().antMatchers("/**").permitAll();
55// http.authorizeRequests().antMatchers("/user/registration/**", "/home/markers","/home/getLocation/**","/api/login/**","/home").permitAll();
56// http.authorizeRequests().antMatchers( "/user/setFavourite/**","user/favourites").hasAuthority("ROLE_USER");
57// http.authorizeRequests().antMatchers( "/home/**").hasAuthority("ROLE_ADMIN");
58// http.authorizeRequests().anyRequest().authenticated();
59 http.addFilter(customAuthenticationFilter);
60 http.addFilterBefore(new CustomAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
61 }
62
63 @Bean
64 @Override
65 public AuthenticationManager authenticationManagerBean() throws Exception {
66 return super.authenticationManagerBean();
67 }
68
69
70 }
Note: See TracBrowser for help on using the repository browser.