Skip to content

Commit 9b77151

Browse files
committed
Polish "Make UserDetailsService back off with AuthManagerResolver bean"
See gh-28361
1 parent 31cdfd5 commit 9b77151

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfigurationTests.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,12 @@
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.context.annotation.Configuration;
3232
import org.springframework.context.annotation.Import;
33-
import org.springframework.security.authentication.*;
33+
import org.springframework.security.authentication.AuthenticationManager;
34+
import org.springframework.security.authentication.AuthenticationManagerResolver;
35+
import org.springframework.security.authentication.AuthenticationProvider;
36+
import org.springframework.security.authentication.ProviderManager;
37+
import org.springframework.security.authentication.TestingAuthenticationProvider;
38+
import org.springframework.security.authentication.TestingAuthenticationToken;
3439
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
3540
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
3641
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -79,6 +84,12 @@ void defaultUserNotCreatedIfAuthenticationManagerBeanPresent(CapturedOutput outp
7984
});
8085
}
8186

87+
@Test
88+
void defaultUserNotCreatedIfAuthenticationManagerResolverBeanPresent(CapturedOutput output) {
89+
this.contextRunner.withUserConfiguration(TestAuthenticationManagerResolverConfiguration.class)
90+
.run((context) -> assertThat(output).doesNotContain("Using generated security password: "));
91+
}
92+
8293
@Test
8394
void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(CapturedOutput output) {
8495
this.contextRunner.withUserConfiguration(TestUserDetailsServiceConfiguration.class).run((context) -> {
@@ -151,12 +162,6 @@ void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed(Cap
151162
.run(((context) -> assertThat(output).doesNotContain("Using generated security password: ")));
152163
}
153164

154-
@Test
155-
void userDetailsServiceShouldNotBePresentWhenAuthenticationManagerResolverBeanIsPresent() {
156-
this.contextRunner.withUserConfiguration(TestAuthenticationManagerResolverConfiguration.class)
157-
.run(((context) -> assertThat(context).doesNotHaveBean(InMemoryUserDetailsManager.class)));
158-
}
159-
160165
private void testPasswordEncoding(Class<?> configClass, String providedPassword, String expectedPassword) {
161166
this.contextRunner.withUserConfiguration(configClass)
162167
.withPropertyValues("spring.security.user.password=" + providedPassword).run(((context) -> {
@@ -272,7 +277,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
272277
static class TestAuthenticationManagerResolverConfiguration {
273278

274279
@Bean
275-
AuthenticationManagerResolver<?> myAuthenticationManagerResolver() {
280+
AuthenticationManagerResolver<?> authenticationManagerResolver() {
276281
return mock(AuthenticationManagerResolver.class);
277282
}
278283

0 commit comments

Comments
 (0)