-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSecurityConfigure.java
More file actions
72 lines (63 loc) · 2.67 KB
/
WebSecurityConfigure.java
File metadata and controls
72 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.kdt.yun.configures;
import org.apache.commons.io.file.NoopPathVisitor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
/**
* Created by yunyun on 2021/11/11.
*/
@Configuration
@EnableWebSecurity
public class WebSecurityConfigure extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
//super.configure(auth);
auth.inMemoryAuthentication()
.withUser("user")
.password("{noop}user123")
.roles("USER");
auth.inMemoryAuthentication()
.withUser("admin")
.password("{noop}admin123")
.roles("ADMIN");
}
@Override
public void configure(WebSecurity web){
web.ignoring().antMatchers("/assets/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.antMatchers("/me").hasAnyRole("USER","ADMIN")
.anyRequest().permitAll()
.and()
.formLogin()
.defaultSuccessUrl("/")
.permitAll()
.and()
.rememberMe()
.rememberMeParameter("remember-me")
.tokenValiditySeconds(5 * 60)
//.alwaysRemember(true)
.and()
.logout()
//.logoutUrl("/logout")
//.deleteCookies("JSESSIONID", "remember-me")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.invalidateHttpSession(true) // 기본 값이 true 이다.
.clearAuthentication(true); // 기본 값이 true 이다.
}
// @Bean
// public PasswordEncoder passwordEncoder(){
// return NoOpPasswordEncoder.getInstance();
// }
}