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

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

Added admin view of pending roles and approve functionality

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