[ac25203] | 1 | package com.example.moviezone.config;
|
---|
| 2 |
|
---|
| 3 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 4 | import org.springframework.context.annotation.Configuration;
|
---|
| 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
---|
| 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
---|
| 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
---|
| 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
---|
| 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
---|
| 10 | import org.springframework.security.crypto.password.PasswordEncoder;
|
---|
[2269653] | 11 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
---|
[ac25203] | 12 |
|
---|
| 13 |
|
---|
| 14 | @Configuration
|
---|
| 15 | @EnableWebSecurity
|
---|
[2269653] | 16 | @EnableWebMvc
|
---|
[ac25203] | 17 | @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
|
---|
| 18 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
---|
| 19 |
|
---|
| 20 | private final PasswordEncoder passwordEncoder;
|
---|
| 21 | private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
|
---|
| 22 |
|
---|
| 23 | public WebSecurityConfig(PasswordEncoder passwordEncoder,
|
---|
| 24 | CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
|
---|
| 25 | this.passwordEncoder = passwordEncoder;
|
---|
| 26 | this.authenticationProvider = authenticationProvider;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Override
|
---|
| 30 | protected void configure(HttpSecurity http) throws Exception {
|
---|
| 31 |
|
---|
| 32 | http.csrf().disable()
|
---|
| 33 | .authorizeRequests()
|
---|
[1b0bd1e] | 34 | .antMatchers("/","/films","/home/projections","/home/events","/home/getProjections/**","/home/films","/home/getFilm/**","/getFilm/**","/home/getEvent/**","/getEvent/**","/login","/events","/projections" ,"/home", "/assets/**", "/register", "/registerWorker","/api/**").permitAll()
|
---|
[f214198] | 35 | .antMatchers("/","/finishRegister","/registerWorker","/films","/home/projections","/home/events","/home/getProjections/**","/home/films","/home/getFilm/**","/getFilm/**","/home/getEvent/**","/getEvent/**","redirect:/login","/login","/events","/projections" ,"/home", "/assets/**", "/register", "/api/**").permitAll()
|
---|
[1e7126f] | 36 | .antMatchers("/home/getSeats/**","/myTickets","/home/addInterestedEvent/**","/home/deleteInterestedEvent/**","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser","/cancelTicket/**").hasRole("USER")
|
---|
| 37 | .antMatchers("/profileWorker").hasRole("WORKER")
|
---|
[01a1ca6] | 38 | .antMatchers("/**").hasRole("ADMIN")
|
---|
[ac25203] | 39 | .anyRequest()
|
---|
| 40 | .authenticated()
|
---|
| 41 | .and()
|
---|
| 42 | .formLogin()
|
---|
| 43 | .loginPage("/login").permitAll()
|
---|
| 44 | .failureUrl("/login?error=BadCredentials")
|
---|
[b5ce654] | 45 | .defaultSuccessUrl("/home", true)
|
---|
[ac25203] | 46 | .and()
|
---|
| 47 | .logout()
|
---|
| 48 | .logoutUrl("/logout")
|
---|
[2269653] | 49 | .clearAuthentication(true)
|
---|
[ac25203] | 50 | .invalidateHttpSession(true)
|
---|
| 51 | .deleteCookies("JSESSIONID")
|
---|
| 52 | .logoutSuccessUrl("/login")
|
---|
| 53 | .and()
|
---|
| 54 | .exceptionHandling().accessDeniedPage("/access_denied");
|
---|
| 55 |
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @Override
|
---|
| 59 | protected void configure(AuthenticationManagerBuilder auth) {
|
---|
| 60 | //
|
---|
| 61 | auth.authenticationProvider(authenticationProvider);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | }
|
---|