1 | package com.example.baziproekt.config;
|
---|
2 |
|
---|
3 |
|
---|
4 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
5 | import org.springframework.context.annotation.Configuration;
|
---|
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
---|
7 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
---|
8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
---|
9 | import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
---|
10 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
---|
11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
---|
12 | import org.springframework.security.core.userdetails.UserDetailsService;
|
---|
13 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
---|
14 |
|
---|
15 |
|
---|
16 | @Configuration
|
---|
17 | public 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 | } |
---|