|
|
|
@ -34,7 +34,9 @@ import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
|
|
import org.springframework.security.authentication.ProviderManager;
|
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationProvider;
|
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
|
import org.springframework.security.core.userdetails.User;
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
@ -149,6 +151,14 @@ public class UserDetailsServiceAutoConfigurationTests {
|
|
|
|
|
.doesNotHaveBean(InMemoryUserDetailsManager.class)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed() {
|
|
|
|
|
this.contextRunner
|
|
|
|
|
.withUserConfiguration(TestConfigWithAuthenticationManagerBuilder.class)
|
|
|
|
|
.run(((context) -> assertThat(this.outputCapture.toString())
|
|
|
|
|
.doesNotContain("Using generated security password: ")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testPasswordEncoding(Class<?> configClass, String providedPassword,
|
|
|
|
|
String expectedPassword) {
|
|
|
|
|
this.contextRunner.withUserConfiguration(configClass)
|
|
|
|
@ -227,4 +237,23 @@ public class UserDetailsServiceAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@Import(TestSecurityConfiguration.class)
|
|
|
|
|
protected static class TestConfigWithAuthenticationManagerBuilder {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
|
|
|
|
|
return new WebSecurityConfigurerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
protected void configure(AuthenticationManagerBuilder auth)
|
|
|
|
|
throws Exception {
|
|
|
|
|
auth.inMemoryAuthentication().withUser("hero").password("{noop}hero")
|
|
|
|
|
.roles("HERO", "USER").and().withUser("user")
|
|
|
|
|
.password("{noop}user").roles("USER");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|