source: source/MovieZilla-master/src/main/java/com/example/demo/config/WebSecurityConfig.java

Last change on this file was fc7ec52, checked in by darkopopovski <darkopopovski39@…>, 2 years ago

all files

  • Property mode set to 100644
File size: 3.4 KB
Line 
1package com.example.demo.config;
2
3import org.springframework.context.annotation.Configuration;
4import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
5import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
6import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9import org.springframework.security.crypto.password.PasswordEncoder;
10import org.thymeleaf.TemplateEngine;
11
12
13@Configuration
14@EnableWebSecurity
15@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
16public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
17
18
19
20 private final PasswordEncoder passwordEncoder;
21 private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
22
23 public WebSecurityConfig(
24 PasswordEncoder passwordEncoder, 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()
34// .antMatchers("/").permitAll()
35 .antMatchers("/login","/projections","/**","/auditoriums","/reserve/add","/css/**",
36 "/tests/reserve/projection/add","/reserve","/reserve/projection/**",
37 "/view/movies/**","/","/movie/projections/detailed-preview/","/tests","/home/videos/**",
38 "/videos/**","/projections/view","/movies/view/**", "/home",
39 "/home/**" ,"/assets/**", "/register","/movies", "/api/**","/logout").permitAll()
40 .antMatchers("/admin/**","/projections/add-form","/movies/add-form").hasRole("EMPLOYEE")
41 .anyRequest().authenticated()
42 .and()
43 .formLogin()
44 //.loginPage("/login").permitAll()
45 .failureUrl("/login?error=BadCredentials")
46 .defaultSuccessUrl("/movies", true)
47 .and()
48 .logout()
49 .logoutUrl("/logout")
50 .clearAuthentication(true)
51 .invalidateHttpSession(true)
52 .deleteCookies("JSESSIONID")
53 .logoutSuccessUrl("/login")
54 .and()
55 .exceptionHandling().accessDeniedPage("/access_denied");
56
57 }
58
59 @Override
60 protected void configure(AuthenticationManagerBuilder auth) throws Exception {
61// auth.inMemoryAuthentication()
62// .withUser("kostadin.mishev")
63// .password(passwordEncoder.encode("km"))
64// .authorities("ROLE_USER")
65// .and()
66// .withUser("admin")
67// .password(passwordEncoder.encode("admin"))
68// .authorities("ROLE_ADMIN");
69 auth.authenticationProvider(authenticationProvider);
70 }
71// @Override
72// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
73// auth.inMemoryAuthentication()
74// .withUser("admin")
75// .password(passwordEncoder.encode("admin")).authorities("ROLE_EMPLOYEE");
76// }
77
78
79}
Note: See TracBrowser for help on using the repository browser.