Skip to content

Commit 993c769

Browse files
author
Dave Syer
committed
Fix recommended authentication configuration to match samples
1 parent 3382882 commit 993c769

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,16 +1369,17 @@ http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#jc
13691369

13701370
Spring Security also provides a convenient `AuthenticationManagerBuilder` which can be
13711371
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
13731373
`WebSecurityConfigurerAdapter`, e.g.
13741374

13751375
[source,java,indent=0,subs="verbatim,quotes,attributes"]
13761376
----
13771377
@Configuration
1378+
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
13781379
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
13791380
1380-
@Autowired
1381-
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
1381+
@Override
1382+
public void configure(AuthenticationManagerBuilder auth) throws Exception {
13821383
auth.inMemoryAuthentication()
13831384
.withUser("barry").password("password").roles("USER"); // ... etc.
13841385
}
@@ -1393,6 +1394,22 @@ You will get the best results if you put this in a nested class, or a standalone
13931394
order of instantiation). The {github-code}/spring-boot-samples/spring-boot-sample-web-secure[secure web sample]
13941395
is a useful template to follow.
13951396

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+
```
13961413

13971414

13981415
[[howto-enable-https]]

0 commit comments

Comments
 (0)