@@ -1369,16 +1369,17 @@ http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#jc
1369
1369
1370
1370
Spring Security also provides a convenient `AuthenticationManagerBuilder` which can be
1371
1371
used to build an `AuthenticationManager` with common options. The recommended way to
1372
- use this in a webapp is to inject it into a void method in a
1372
+ use this in a webapp is to inject it into a callback method in a
1373
1373
`WebSecurityConfigurerAdapter`, e.g.
1374
1374
1375
1375
[source,java,indent=0,subs="verbatim,quotes,attributes"]
1376
1376
----
1377
1377
@Configuration
1378
+ @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
1378
1379
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
1379
1380
1380
- @Autowired
1381
- public void configureGlobal (AuthenticationManagerBuilder auth) throws Exception {
1381
+ @Override
1382
+ public void configure (AuthenticationManagerBuilder auth) throws Exception {
1382
1383
auth.inMemoryAuthentication()
1383
1384
.withUser("barry").password("password").roles("USER"); // ... etc.
1384
1385
}
@@ -1393,6 +1394,22 @@ You will get the best results if you put this in a nested class, or a standalone
1393
1394
order of instantiation). The {github-code}/spring-boot-samples/spring-boot-sample-web-secure[secure web sample]
1394
1395
is a useful template to follow.
1395
1396
1397
+ If you experience instantiation issues (e.g. using JDBC or JPA for the
1398
+ user detail store) it might be worth extracting the
1399
+ `AuthenticationManagerBuilder` callback into a
1400
+ `GlobalAuthenticationConfigurerAdapter` (in the `init()` method so it
1401
+ happens before the authentication manager is needed elsewhere), e.g.
1402
+
1403
+ ```
1404
+ @Configuration
1405
+ public class AuthenticationManagerConfiguration extends
1406
+ GlobalAuthenticationConfigurerAdapter {
1407
+ @Override
1408
+ public void init(AuthenticationManagerBuilder auth) {
1409
+ auth.inMemoryAuthentication() // ... etc.
1410
+ }
1411
+ }
1412
+ ```
1396
1413
1397
1414
1398
1415
[[howto-enable-https]]
0 commit comments