|
34 | 34 | import org.springframework.security.authentication.ProviderManager;
|
35 | 35 | import org.springframework.security.authentication.TestingAuthenticationProvider;
|
36 | 36 | import org.springframework.security.authentication.TestingAuthenticationToken;
|
| 37 | +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
37 | 38 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
| 39 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
38 | 40 | import org.springframework.security.core.userdetails.User;
|
39 | 41 | import org.springframework.security.core.userdetails.UserDetailsService;
|
40 | 42 | import org.springframework.security.crypto.password.PasswordEncoder;
|
@@ -149,6 +151,14 @@ public void userDetailsServiceWhenClientRegistrationRepositoryBeanPresent() {
|
149 | 151 | .doesNotHaveBean(InMemoryUserDetailsManager.class)));
|
150 | 152 | }
|
151 | 153 |
|
| 154 | + @Test |
| 155 | + public void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed() { |
| 156 | + this.contextRunner |
| 157 | + .withUserConfiguration(TestConfigWithAuthenticationManagerBuilder.class) |
| 158 | + .run(((context) -> assertThat(this.outputCapture.toString()) |
| 159 | + .doesNotContain("Using generated security password: "))); |
| 160 | + } |
| 161 | + |
152 | 162 | private void testPasswordEncoding(Class<?> configClass, String providedPassword,
|
153 | 163 | String expectedPassword) {
|
154 | 164 | this.contextRunner.withUserConfiguration(configClass)
|
@@ -227,4 +237,23 @@ public ClientRegistrationRepository clientRegistrationRepository() {
|
227 | 237 |
|
228 | 238 | }
|
229 | 239 |
|
| 240 | + @Configuration |
| 241 | + @Import(TestSecurityConfiguration.class) |
| 242 | + protected static class TestConfigWithAuthenticationManagerBuilder { |
| 243 | + |
| 244 | + @Bean |
| 245 | + public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() { |
| 246 | + return new WebSecurityConfigurerAdapter() { |
| 247 | + @Override |
| 248 | + protected void configure(AuthenticationManagerBuilder auth) |
| 249 | + throws Exception { |
| 250 | + auth.inMemoryAuthentication().withUser("hero").password("{noop}hero") |
| 251 | + .roles("HERO", "USER").and().withUser("user") |
| 252 | + .password("{noop}user").roles("USER"); |
| 253 | + } |
| 254 | + }; |
| 255 | + } |
| 256 | + |
| 257 | + } |
| 258 | + |
230 | 259 | }
|
0 commit comments