|
|
|
@ -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;
|
|
|
|
@ -93,7 +95,7 @@ public class UserDetailsServiceAutoConfigurationTests {
|
|
|
|
|
UserDetailsService userDetailsService = context
|
|
|
|
|
.getBean(UserDetailsService.class);
|
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
|
.doesNotContain("Using generated security password: ");
|
|
|
|
|
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -106,7 +108,7 @@ public class UserDetailsServiceAutoConfigurationTests {
|
|
|
|
|
AuthenticationProvider provider = context
|
|
|
|
|
.getBean(AuthenticationProvider.class);
|
|
|
|
|
assertThat(this.outputCapture.toString())
|
|
|
|
|
.doesNotContain("Using default security password: ");
|
|
|
|
|
.doesNotContain("Using generated security password: ");
|
|
|
|
|
TestingAuthenticationToken token = new TestingAuthenticationToken(
|
|
|
|
|
"foo", "bar");
|
|
|
|
|
assertThat(provider.authenticate(token)).isNotNull();
|
|
|
|
@ -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");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|