source: src/main/java/com/example/moviezone/config/WebSecurityConfig.java@ eb226b2

Last change on this file since eb226b2 was eb226b2, checked in by DenicaKj <dkorvezir@…>, 22 months ago

Fixing errors

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package com.example.moviezone.config;
2
3import org.springframework.beans.factory.annotation.Autowired;
4import org.springframework.context.annotation.Configuration;
5import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
6import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
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.password.PasswordEncoder;
11
12
13@Configuration
14@EnableWebSecurity
15@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
16public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
17
18 private final PasswordEncoder passwordEncoder;
19 private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
20
21 public WebSecurityConfig(PasswordEncoder passwordEncoder,
22 CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
23 this.passwordEncoder = passwordEncoder;
24 this.authenticationProvider = authenticationProvider;
25 }
26
27 @Override
28 protected void configure(HttpSecurity http) throws Exception {
29
30 http.csrf().disable()
31 .authorizeRequests()
32 .antMatchers("/", "/home", "/assets/**", "/register", "/api/**").permitAll()
33 .antMatchers("/admin/**").hasRole("ADMIN")
34 .anyRequest()
35 .authenticated()
36 .and()
37 .formLogin()
38 .loginPage("/login").permitAll()
39 .failureUrl("/login?error=BadCredentials")
40 .defaultSuccessUrl("/products", true)
41 .and()
42 .logout()
43 .logoutUrl("/logout")
44 .invalidateHttpSession(true)
45 .deleteCookies("JSESSIONID")
46 .logoutSuccessUrl("/login")
47 .and()
48 .exceptionHandling().accessDeniedPage("/access_denied");
49
50 }
51
52 @Override
53 protected void configure(AuthenticationManagerBuilder auth) {
54//
55 auth.authenticationProvider(authenticationProvider);
56 }
57
58
59
60}
Note: See TracBrowser for help on using the repository browser.