source: src/main/java/com/example/baziproekt/config/WebSecurityConfig.java@ 0e4d807

Last change on this file since 0e4d807 was 0e4d807, checked in by Ivona <ivonatapshanovska@…>, 10 months ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package com.example.baziproekt.config;
2
3
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.context.annotation.Configuration;
6import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
8import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9import org.springframework.security.config.annotation.web.builders.WebSecurity;
10import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
11import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12import org.springframework.security.core.userdetails.UserDetailsService;
13import org.springframework.web.servlet.config.annotation.EnableWebMvc;
14
15
16@Configuration
17public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
18
19 /* @Override
20 public void configure(WebSecurity web) throws Exception {
21 web.ignoring().antMatchers("/**");
22 }
23*/
24
25
26
27 private final CustomUsernamePasswordAuthenticationProvider authenticationProvider;
28
29 public WebSecurityConfig(CustomUsernamePasswordAuthenticationProvider authenticationProvider) {
30 this.authenticationProvider = authenticationProvider;
31 }
32
33
34 @Override
35 protected void configure(HttpSecurity http) throws Exception {
36
37 http.csrf().disable()
38 .authorizeRequests()
39 .antMatchers("/**").permitAll()
40 .anyRequest()
41 .authenticated()
42 .and()
43 .formLogin()
44 .loginPage("/login").permitAll()
45 .failureUrl("/login?error=BadCredentials")
46 .defaultSuccessUrl("/home", 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("/");
56
57 }
58
59
60 @Override
61 protected void configure(AuthenticationManagerBuilder auth) {
62
63 auth.authenticationProvider(authenticationProvider);
64
65
66 }
67
68}
Note: See TracBrowser for help on using the repository browser.