Polish "Make UserDetailsService back off with AuthManagerResolver bean"
See gh-28361
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,12 @@ import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.security.authentication.*;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.AuthenticationManagerResolver;
|
||||
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;
|
||||
@@ -79,6 +84,12 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUserNotCreatedIfAuthenticationManagerResolverBeanPresent(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestAuthenticationManagerResolverConfiguration.class)
|
||||
.run((context) -> assertThat(output).doesNotContain("Using generated security password: "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestUserDetailsServiceConfiguration.class).run((context) -> {
|
||||
@@ -151,12 +162,6 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
.run(((context) -> assertThat(output).doesNotContain("Using generated security password: ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void userDetailsServiceShouldNotBePresentWhenAuthenticationManagerResolverBeanIsPresent() {
|
||||
this.contextRunner.withUserConfiguration(TestAuthenticationManagerResolverConfiguration.class)
|
||||
.run(((context) -> assertThat(context).doesNotHaveBean(InMemoryUserDetailsManager.class)));
|
||||
}
|
||||
|
||||
private void testPasswordEncoding(Class<?> configClass, String providedPassword, String expectedPassword) {
|
||||
this.contextRunner.withUserConfiguration(configClass)
|
||||
.withPropertyValues("spring.security.user.password=" + providedPassword).run(((context) -> {
|
||||
@@ -272,7 +277,7 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
static class TestAuthenticationManagerResolverConfiguration {
|
||||
|
||||
@Bean
|
||||
AuthenticationManagerResolver<?> myAuthenticationManagerResolver() {
|
||||
AuthenticationManagerResolver<?> authenticationManagerResolver() {
|
||||
return mock(AuthenticationManagerResolver.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user