source: src/main/java/com/example/autopartz/config/WebSecurityConfig.java

main
Last change on this file was c79897f, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 20 months ago

Sredeni zabeleshki po diskusii

  • Property mode set to 100644
File size: 2.8 KB
Line 
1package com.example.autopartz.config;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
5import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
6import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9import org.springframework.security.crypto.password.PasswordEncoder;
10
11@Configuration
12@EnableWebSecurity
13@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
14public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
15
16 private final PasswordEncoder passwordEncoder;
17 private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
18
19 public WebSecurityConfig(PasswordEncoder passwordEncoder,
20 CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
21 this.passwordEncoder = passwordEncoder;
22 this.authenticationProvider = authenticationProvider;
23 }
24
25 @Override
26 protected void configure(HttpSecurity http) throws Exception {
27
28 http.csrf().disable()
29 .authorizeRequests()
30 .antMatchers("/", "/products", "/services", "/filtered", "/login", "/register","/registerWarehouseman","/finishRegister","/test/*","/access_denied","/carCategoryReport","/partManufacturersReport","/mostPurchasedPart","/part/*").permitAll()
31 .antMatchers("/orders","/repairs","/reviews","/currentOrder","/addCarSampleForUser","/repairs/addReview/*").hasRole("CLIENT")
32 .antMatchers("/viewUsers","/approve/*","/addPart","/addCarManufacturer","/addPartManufacturer","/addCategory","/addCar","/addRepairShop","/addWarehouse").hasRole("ADMIN")
33 .antMatchers("/myWarehouseReport","myWarehouse").hasRole("WAREHOUSEMAN")
34 .anyRequest()
35 .authenticated()
36 .and()
37 .formLogin()
38 .loginPage("/login").permitAll()
39 .failureUrl("/login?error=BadCredentials")
40 .defaultSuccessUrl("/", true)
41 .and()
42 .logout()
43 .logoutUrl("/logout")
44 .clearAuthentication(true)
45 .invalidateHttpSession(true)
46 .deleteCookies("JSESSIONID")
47 .logoutSuccessUrl("/")
48 .and()
49 .exceptionHandling().accessDeniedPage("/access_denied");
50
51 }
52
53 @Override
54 protected void configure(AuthenticationManagerBuilder auth) {
55 auth.authenticationProvider(authenticationProvider);
56 }
57
58
59
60}
61
62
Note: See TracBrowser for help on using the repository browser.