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

main
Last change on this file since 1bd8d1e was 1bd8d1e, checked in by andrejtodorovski <82031894+andrejtodorovski@…>, 18 months ago

Added views and functionalities for deliveryman, warehouseman and admin

  • Property mode set to 100644
File size: 2.5 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").permitAll()
31 .antMatchers("/orders","/repairs","/reviews","/part/*","/currentOrder").hasRole("CLIENT")
32 .antMatchers("/viewUsers","/approve/*").hasRole("ADMIN")
33 .anyRequest()
34 .authenticated()
35 .and()
36 .formLogin()
37 .loginPage("/login").permitAll()
38 .failureUrl("/login?error=BadCredentials")
39 .defaultSuccessUrl("/", true)
40 .and()
41 .logout()
42 .logoutUrl("/logout")
43 .clearAuthentication(true)
44 .invalidateHttpSession(true)
45 .deleteCookies("JSESSIONID")
46 .logoutSuccessUrl("/")
47 .and()
48 .exceptionHandling().accessDeniedPage("/access_denied");
49
50 }
51
52 @Override
53 protected void configure(AuthenticationManagerBuilder auth) {
54 auth.authenticationProvider(authenticationProvider);
55 }
56
57
58
59}
60
61
Note: See TracBrowser for help on using the repository browser.