package com.example.moviezone.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @Configuration @EnableWebSecurity @EnableWebMvc @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { private final PasswordEncoder passwordEncoder; private final CustomUsernamePasswordAuthenticationProvider authenticationProvider; public WebSecurityConfig(PasswordEncoder passwordEncoder, CustomUsernamePasswordAuthenticationProvider authenticationProvider) { this.passwordEncoder = passwordEncoder; this.authenticationProvider = authenticationProvider; } @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .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() .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() .antMatchers("/home/getSeats/**","/myTickets","/home/addInterestedEvent/**","/home/deleteInterestedEvent/**","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser","/cancelTicket/**").hasRole("USER") .antMatchers("/profileWorker").hasRole("WORKER") .antMatchers("/**").hasRole("ADMIN") .anyRequest() .authenticated() .and() .formLogin() .loginPage("/login").permitAll() .failureUrl("/login?error=BadCredentials") .defaultSuccessUrl("/home", true) .and() .logout() .logoutUrl("/logout") .clearAuthentication(true) .invalidateHttpSession(true) .deleteCookies("JSESSIONID") .logoutSuccessUrl("/login") .and() .exceptionHandling().accessDeniedPage("/access_denied"); } @Override protected void configure(AuthenticationManagerBuilder auth) { // auth.authenticationProvider(authenticationProvider); } }