19
19
import java .util .Date ;
20
20
import java .util .Map ;
21
21
22
- import javax .sql .DataSource ;
23
-
24
22
import org .springframework .beans .factory .annotation .Autowired ;
25
23
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
26
24
import org .springframework .boot .autoconfigure .security .SecurityProperties ;
27
25
import org .springframework .boot .builder .SpringApplicationBuilder ;
28
- import org .springframework .context .annotation .Bean ;
29
26
import org .springframework .context .annotation .ComponentScan ;
30
- import org .springframework .core . Ordered ;
27
+ import org .springframework .context . annotation . Configuration ;
31
28
import org .springframework .core .annotation .Order ;
32
29
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
33
- import org .springframework .security .config .annotation .authentication .configurers .GlobalAuthenticationConfigurerAdapter ;
34
30
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
35
31
import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
36
32
import org .springframework .stereotype .Controller ;
@@ -65,16 +61,7 @@ public void addViewControllers(ViewControllerRegistry registry) {
65
61
registry .addViewController ("/login" ).setViewName ("login" );
66
62
}
67
63
68
- @ Bean
69
- public ApplicationSecurity applicationSecurity () {
70
- return new ApplicationSecurity ();
71
- }
72
-
73
- @ Bean
74
- public AuthenticationSecurity authenticationSecurity () {
75
- return new AuthenticationSecurity ();
76
- }
77
-
64
+ @ Configuration
78
65
@ Order (SecurityProperties .ACCESS_OVERRIDE_ORDER )
79
66
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
80
67
@@ -86,20 +73,12 @@ protected void configure(HttpSecurity http) throws Exception {
86
73
http .authorizeRequests ().anyRequest ().fullyAuthenticated ().and ().formLogin ()
87
74
.loginPage ("/login" ).failureUrl ("/login?error" ).permitAll ();
88
75
}
89
- }
90
-
91
- @ Order (Ordered .HIGHEST_PRECEDENCE + 10 )
92
- protected static class AuthenticationSecurity extends
93
- GlobalAuthenticationConfigurerAdapter {
94
-
95
- @ Autowired
96
- private DataSource dataSource ;
97
76
98
77
@ Override
99
- public void init (AuthenticationManagerBuilder auth ) throws Exception {
100
- auth .jdbcAuthentication ().dataSource ( this . dataSource ). withUser ("admin" )
101
- .password ( "admin" ). roles ("ADMIN" , "USER" ).and ().withUser ("user" )
102
- .password ( "user" ). roles ("USER" );
78
+ public void configure (AuthenticationManagerBuilder auth ) throws Exception {
79
+ auth .inMemoryAuthentication ().withUser ( "admin" ). password ("admin" )
80
+ .roles ("ADMIN" , "USER" ).and ().withUser ( "user" ). password ("user" )
81
+ .roles ("USER" );
103
82
}
104
83
105
84
}
0 commit comments