source: Git/src/main/java/com/wediscussmovies/project/configuration/SecurityConfig.java@ 2efe93e

main
Last change on this file since 2efe93e was 2efe93e, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago

Improved Front-End, added card view of movies

  • Property mode set to 100644
File size: 2.2 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.builders.WebSecurity;
8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9
10@Configuration
11public 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}
Note: See TracBrowser for help on using the repository browser.