diff --git a/docs/manual/src/docs/asciidoc/index.adoc b/docs/manual/src/docs/asciidoc/index.adoc index 728947ba5c..aeb52501ed 100644 --- a/docs/manual/src/docs/asciidoc/index.adoc +++ b/docs/manual/src/docs/asciidoc/index.adoc @@ -445,7 +445,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public UserDetailsService userDetailsService() throws Exception { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); + manager.createUser(User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build()); return manager; } } @@ -777,9 +777,11 @@ We have already seen an example of configuring in-memory authentication for a si ---- @Bean public UserDetailsService userDetailsService() throws Exception { + // ensure the passwords are encoded properly + UserBuilder users = User.withDefaultPasswordEncoder(); InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); - manager.createUser(User.withUsername("admin").password("password").roles("USER","ADMIN").build()); + manager.createUser(users.username("user").password("password").roles("USER").build()); + manager.createUser(users.username("admin").password("password").roles("USER","ADMIN").build()); return manager; } ---- @@ -796,12 +798,14 @@ private DataSource dataSource; @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + // ensure the passwords are encoded properly + UserBuilder users = User.withDefaultPasswordEncoder(); auth .jdbcAuthentication() .dataSource(dataSource) .withDefaultSchema() - .withUser("user").password("password").roles("USER").and() - .withUser("admin").password("password").roles("USER", "ADMIN"); + .withUser(users.username("user").password("password").roles("USER")) + .withUser(users.username("admin").password("password").roles("USER","ADMIN")); } ---- @@ -924,9 +928,11 @@ We can configure multiple HttpSecurity instances just as we can have multiple `< public class MultiHttpSecurityConfig { @Bean <1> public UserDetailsService userDetailsService() throws Exception { + // ensure the passwords are encoded properly + UserBuilder users = User.withDefaultPasswordEncoder(); InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user").password("password").roles("USER").build()); - manager.createUser(User.withUsername("admin").password("password").roles("USER","ADMIN").build()); + manager.createUser(users.username("user").password("password").roles("USER").build()); + manager.createUser(users.username("admin").password("password").roles("USER","ADMIN").build()); return manager; } @@ -1298,13 +1304,39 @@ To add some users, you can define a set of test data directly in the namespace: - - + + + ---- +This is an example of a secure way of storing the same passwords. The password is prefixed +with `{bcrypt}` to instruct `DelegatingPasswordEncoder`, which supports any configured +`PasswordEncoder` for matching, that the passwords are hashed using +BCrypt: + +[source,xml] +---- + + + + + + + + + + +---- + + + [subs="quotes"] **** If you are familiar with pre-namespace versions of the framework, you can probably already guess roughly what's going on here. The `` element is responsible for creating a `FilterChainProxy` and the filter beans which it uses. Common problems like incorrect filter ordering are no longer an issue as the filter positions are predefined. @@ -1448,9 +1480,9 @@ Passwords should always be encoded using a secure hashing algorithm designed for - - @@ -2441,11 +2473,15 @@ Is easy to use create a custom `UserDetailsService` implementation that extracts [source,xml] ---- - - + + + ---- + This also supports the use of an external properties file: [source,xml] @@ -6224,7 +6260,10 @@ Next you need to add a `CasAuthenticationProvider` and its collaborators: - + + ... ----