|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
39 | 39 | * @EnableGlobalAuthentication
|
40 | 40 | * public class MyGlobalAuthenticationConfiguration {
|
41 | 41 | *
|
42 |
| - * @Autowired |
43 |
| - * public void configureGlobal(AuthenticationManagerBuilder auth) { |
44 |
| - * auth.inMemoryAuthentication().withUser("user").password("password").roles("USER") |
45 |
| - * .and().withUser("admin").password("password").roles("USER", "ADMIN"); |
| 42 | + * @Bean |
| 43 | + * public UserDetailsService userDetailsService() { |
| 44 | + * UserDetails user = User.withDefaultPasswordEncoder() |
| 45 | + * .username("user") |
| 46 | + * .password("password") |
| 47 | + * .roles("USER") |
| 48 | + * .build(); |
| 49 | + * UserDetails admin = User.withDefaultPasswordEncoder() |
| 50 | + * .username("admin") |
| 51 | + * .password("password") |
| 52 | + * .roles("ADMIN", "USER") |
| 53 | + * .build(); |
| 54 | + * return new InMemoryUserDetailsManager(user, admin); |
46 | 55 | * }
|
47 | 56 | * }
|
48 | 57 | * </pre>
|
|
54 | 63 | * <pre class="code">
|
55 | 64 | * @Configuration
|
56 | 65 | * @EnableWebSecurity
|
57 |
| - * public class MyWebSecurityConfiguration extends WebSecurityConfigurerAdapter { |
| 66 | + * public class MyWebSecurityConfiguration { |
58 | 67 | *
|
59 |
| - * @Autowired |
60 |
| - * public void configureGlobal(AuthenticationManagerBuilder auth) { |
61 |
| - * auth.inMemoryAuthentication().withUser("user").password("password").roles("USER") |
62 |
| - * .and().withUser("admin").password("password").roles("USER", "ADMIN"); |
| 68 | + * @Bean |
| 69 | + * public UserDetailsService userDetailsService() { |
| 70 | + * UserDetails user = User.withDefaultPasswordEncoder() |
| 71 | + * .username("user") |
| 72 | + * .password("password") |
| 73 | + * .roles("USER") |
| 74 | + * .build(); |
| 75 | + * UserDetails admin = User.withDefaultPasswordEncoder() |
| 76 | + * .username("admin") |
| 77 | + * .password("password") |
| 78 | + * .roles("ADMIN", "USER") |
| 79 | + * .build(); |
| 80 | + * return new InMemoryUserDetailsManager(user, admin); |
63 | 81 | * }
|
64 | 82 | *
|
65 |
| - * // Possibly overridden methods ... |
| 83 | + * // Possibly more bean methods ... |
66 | 84 | * }
|
67 | 85 | * </pre>
|
68 | 86 | *
|
|
0 commit comments