source: Git/src/main/java/com/wediscussmovies/project/configuration/SecurityConfig.java@ 5b447b0

main
Last change on this file since 5b447b0 was 5b447b0, checked in by Test <matonikolov77@…>, 2 years ago

Adding models and resources

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package com.wediscussmovies.project.configuration;
2
3
4import org.springframework.context.annotation.Configuration;
5import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
6import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
8
9@Configuration
10public 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}
Note: See TracBrowser for help on using the repository browser.