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.builders.WebSecurity;
|
---|
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
---|
9 |
|
---|
10 | @Configuration
|
---|
11 | public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
---|
12 | private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
|
---|
13 |
|
---|
14 | public SecurityConfig(CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
|
---|
15 | this.authenticationProvider = authenticationProvider;
|
---|
16 | }
|
---|
17 |
|
---|
18 | @Override
|
---|
19 | public void configure(WebSecurity web) throws Exception {
|
---|
20 | web.ignoring().antMatchers("/*.jpg");
|
---|
21 | web.ignoring().antMatchers("/*.png");
|
---|
22 | web.ignoring().antMatchers("/*.css");
|
---|
23 | web.ignoring().antMatchers("/*.js");
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public void configure(HttpSecurity http) throws Exception {
|
---|
28 | // TODO: If you are implementing the security requirements, remove this following line
|
---|
29 | http.csrf().disable()
|
---|
30 | .authorizeRequests()
|
---|
31 | .antMatchers("/movies","/movies/**/","/actors","/persons/**/","/directors","/discussions","/discussions/**/","/discussions/all/**/","/replies","/register","/genres", "/css/**", "/js/**").permitAll()
|
---|
32 | .anyRequest()
|
---|
33 | .authenticated()
|
---|
34 | .and()
|
---|
35 | .formLogin()
|
---|
36 | .loginPage("/login")
|
---|
37 | .permitAll()
|
---|
38 | .failureUrl("/login?error=BadCredentials")
|
---|
39 | .defaultSuccessUrl("/movies", true)
|
---|
40 | .and()
|
---|
41 | .logout()
|
---|
42 | .logoutUrl("/logout")
|
---|
43 | .clearAuthentication(true)
|
---|
44 | .invalidateHttpSession(true)
|
---|
45 | .deleteCookies("JSESSIONID")
|
---|
46 | .logoutSuccessUrl("/movies");
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
---|
52 | auth.authenticationProvider(authenticationProvider);
|
---|
53 | }
|
---|
54 | }
|
---|