1 | package com.wediscussmovies.project.configuration;
|
---|
2 |
|
---|
3 |
|
---|
4 | import org.springframework.context.annotation.Configuration;
|
---|
5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
---|
6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
---|
7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
---|
8 |
|
---|
9 | @Configuration
|
---|
10 | public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
---|
11 | private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
|
---|
12 |
|
---|
13 | public SecurityConfig(CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
|
---|
14 | this.authenticationProvider = authenticationProvider;
|
---|
15 | }
|
---|
16 |
|
---|
17 |
|
---|
18 | @Override
|
---|
19 | public void configure(HttpSecurity http) throws Exception {
|
---|
20 | // TODO: If you are implementing the security requirements, remove this following line
|
---|
21 | http.csrf().disable()
|
---|
22 | .authorizeRequests()
|
---|
23 | .antMatchers("/movies","/actors","/directors","/discussions","/replies","/register","/genres").permitAll()
|
---|
24 | .anyRequest()
|
---|
25 | .authenticated()
|
---|
26 | .and()
|
---|
27 | .formLogin()
|
---|
28 | .loginPage("/login")
|
---|
29 | .permitAll()
|
---|
30 | .failureUrl("/login?error=BadCredentials")
|
---|
31 | .defaultSuccessUrl("/movies", true)
|
---|
32 | .and()
|
---|
33 | .logout()
|
---|
34 | .logoutUrl("/logout")
|
---|
35 | .clearAuthentication(true)
|
---|
36 | .invalidateHttpSession(true)
|
---|
37 | .deleteCookies("JSESSIONID")
|
---|
38 | .logoutSuccessUrl("/movies");
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
---|
44 | auth.authenticationProvider(authenticationProvider);
|
---|
45 | }
|
---|
46 | }
|
---|