source: src/main/java/com/example/fooddeliverysystem/configuration/WebSecurityConfiguration.java@ 8d11f8c

Last change on this file since 8d11f8c was 8d11f8c, checked in by jovanmanchev <jovanmanchev3003@…>, 18 months ago

code added, trial 2

  • Property mode set to 100644
File size: 2.5 KB
Line 
1package com.example.fooddeliverysystem.configuration;
2
3import org.springframework.context.annotation.Bean;
4import org.springframework.context.annotation.Configuration;
5import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7import org.springframework.security.crypto.password.PasswordEncoder;
8import org.springframework.security.web.SecurityFilterChain;
9
10
11@Configuration
12@EnableWebSecurity
13public class WebSecurityConfiguration {
14
15 private final PasswordEncoder passwordEncoder;
16 private final UsernameAndPasswordAuthProvider usernameAndPasswordAuthProvider;
17
18 public WebSecurityConfiguration(PasswordEncoder passwordEncoder, UsernameAndPasswordAuthProvider usernameAndPasswordAuthProvider) {
19 this.passwordEncoder = passwordEncoder;
20 this.usernameAndPasswordAuthProvider = usernameAndPasswordAuthProvider;
21 }
22
23 @Bean
24 public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
25 http.csrf()
26 .disable()
27 .authorizeHttpRequests()
28 .requestMatchers("/salePlaces").hasAnyRole("ADMIN", "CONSUMER")
29 .requestMatchers("/checkOrderStatus").hasAnyRole("ADMIN", "CONSUMER")
30 .requestMatchers("/salePlace/Orders").hasAnyRole("ADMIN", "SALEPLACEEMPLOYEE")
31 .requestMatchers("/salePlace/**").hasAnyRole("ADMIN", "CONSUMER")
32 .requestMatchers("/checkOrderStatus").hasAnyRole("ADMIN", "CONSUMER")
33 .requestMatchers("/deliveryOrders").hasAnyRole("ADMIN", "DELIVER")
34 .requestMatchers("/takeOrder/*").hasAnyRole("ADMIN", "DELIVER")
35 .requestMatchers("/showOrderDeliverer").hasAnyRole("ADMIN", "DELIVER")
36 .requestMatchers("/orderPayment/*").hasAnyRole("ADMIN", "DELIVER")
37 .requestMatchers("/reports/**").hasRole("ADMIN")
38 .requestMatchers("/images/**","/home","/").permitAll()
39 .anyRequest()
40 .authenticated()
41 .and()
42 .formLogin()
43 .permitAll()
44 .failureUrl("/login?error=BadCredentials")
45 .defaultSuccessUrl("/home", true)
46 .and()
47 .logout()
48 .logoutUrl("/logout")
49 .clearAuthentication(true)
50 .invalidateHttpSession(true)
51 .deleteCookies("JSESSIONID")
52 .logoutSuccessUrl("/home");
53
54
55 return http.build();
56
57 }
58}
Note: See TracBrowser for help on using the repository browser.