File tree 2 files changed +22
-3
lines changed
src/main/java/com/pyr/security 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .pyr .security .config ;
2
2
3
+ import com .pyr .security .service .MyUserService ;
4
+ import org .springframework .beans .factory .annotation .Autowired ;
3
5
import org .springframework .context .annotation .Configuration ;
4
6
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
5
7
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
6
8
import org .springframework .security .config .annotation .web .builders .WebSecurity ;
7
9
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
8
10
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
9
- import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
10
11
11
12
@ Configuration
12
13
@ EnableWebSecurity
13
14
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
14
15
16
+ @ Autowired
17
+ private MyUserService myUserService ;
18
+
15
19
@ Override
16
20
protected void configure (AuthenticationManagerBuilder auth ) throws Exception {
17
- auth .inMemoryAuthentication ().passwordEncoder (new BCryptPasswordEncoder ()).withUser ("admin" ).password (new BCryptPasswordEncoder ().encode ("111" )).roles ("ADMIN" );
18
- auth .inMemoryAuthentication ().passwordEncoder (new BCryptPasswordEncoder ()).withUser ("pyr" ).password (new BCryptPasswordEncoder ().encode ("pyr" )).roles ("USER" );
21
+ //auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("admin").password(new BCryptPasswordEncoder().encode("111")).roles("ADMIN");
22
+ //auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("pyr").password(new BCryptPasswordEncoder().encode("pyr")).roles("USER");
23
+ auth .userDetailsService (myUserService );
19
24
}
20
25
21
26
@ Override
Original file line number Diff line number Diff line change
1
+ package com .pyr .security .service ;
2
+
3
+ import org .springframework .security .core .userdetails .UserDetails ;
4
+ import org .springframework .security .core .userdetails .UserDetailsService ;
5
+ import org .springframework .security .core .userdetails .UsernameNotFoundException ;
6
+ import org .springframework .stereotype .Component ;
7
+
8
+ @ Component
9
+ public class MyUserService implements UserDetailsService {
10
+ @ Override
11
+ public UserDetails loadUserByUsername (String username ) throws UsernameNotFoundException {
12
+ return null ;
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments