1
1
package com .us .example .config ;
2
2
3
3
import com .us .example .security .CustomUserService ;
4
- import com .us .example .util .MD5Util ;
5
4
import org .springframework .beans .factory .annotation .Autowired ;
6
- import org .springframework .context .annotation .Bean ;
7
5
import org .springframework .context .annotation .Configuration ;
8
6
import org .springframework .http .HttpMethod ;
9
7
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
10
8
import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
11
9
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
12
10
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
13
11
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
14
- import org .springframework .security .config .annotation .web .servlet .configuration .EnableWebMvcSecurity ;
15
- import org .springframework .security .core .userdetails .UserDetailsService ;
16
12
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
17
- import org .springframework .security .crypto .password .PasswordEncoder ;
18
- import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
19
13
20
14
/**
21
15
* Created by yangyibo on 17/1/18.
@@ -31,17 +25,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
31
25
32
26
@ Autowired
33
27
protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
34
- auth .userDetailsService (customUserService ).passwordEncoder (new PasswordEncoder (){
35
-
36
- @ Override
37
- public String encode (CharSequence rawPassword ) {
38
- return MD5Util .encode ((String )rawPassword );
39
- }
40
-
41
- @ Override
42
- public boolean matches (CharSequence rawPassword , String encodedPassword ) {
43
- return encodedPassword .equals (MD5Util .encode ((String )rawPassword ));
44
- }}); //user Details Service验证
28
+ auth .userDetailsService (customUserService ).passwordEncoder (new BCryptPasswordEncoder ());
45
29
}
46
30
47
31
@ Override
0 commit comments