Skip to content

Commit 4839f0e

Browse files
committed
Merge pull request #28361 from bartoszJaszczak
* gh-28361: Polish "Make UserDetailsService back off with AuthManagerResolver bean" Make UserDetailsService back off with AuthManagerResolver bean Closes gh-28361
2 parents 791f3f5 + 9b77151 commit 4839f0e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 4 additions & 2 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.
@@ -32,6 +32,7 @@
3232
import org.springframework.context.annotation.Configuration;
3333
import org.springframework.context.annotation.Lazy;
3434
import org.springframework.security.authentication.AuthenticationManager;
35+
import org.springframework.security.authentication.AuthenticationManagerResolver;
3536
import org.springframework.security.authentication.AuthenticationProvider;
3637
import org.springframework.security.config.annotation.ObjectPostProcessor;
3738
import org.springframework.security.core.userdetails.User;
@@ -56,7 +57,8 @@
5657
@ConditionalOnClass(AuthenticationManager.class)
5758
@ConditionalOnBean(ObjectPostProcessor.class)
5859
@ConditionalOnMissingBean(
59-
value = { AuthenticationManager.class, AuthenticationProvider.class, UserDetailsService.class },
60+
value = { AuthenticationManager.class, AuthenticationProvider.class, UserDetailsService.class,
61+
AuthenticationManagerResolver.class },
6062
type = { "org.springframework.security.oauth2.jwt.JwtDecoder",
6163
"org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector" })
6264
public class UserDetailsServiceAutoConfiguration {

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

Lines changed: 18 additions & 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.
@@ -31,6 +31,7 @@
3131
import org.springframework.context.annotation.Configuration;
3232
import org.springframework.context.annotation.Import;
3333
import org.springframework.security.authentication.AuthenticationManager;
34+
import org.springframework.security.authentication.AuthenticationManagerResolver;
3435
import org.springframework.security.authentication.AuthenticationProvider;
3536
import org.springframework.security.authentication.ProviderManager;
3637
import org.springframework.security.authentication.TestingAuthenticationProvider;
@@ -83,6 +84,12 @@ void defaultUserNotCreatedIfAuthenticationManagerBeanPresent(CapturedOutput outp
8384
});
8485
}
8586

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+
8693
@Test
8794
void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(CapturedOutput output) {
8895
this.contextRunner.withUserConfiguration(TestUserDetailsServiceConfiguration.class).run((context) -> {
@@ -266,4 +273,14 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
266273

267274
}
268275

276+
@Configuration(proxyBeanMethods = false)
277+
static class TestAuthenticationManagerResolverConfiguration {
278+
279+
@Bean
280+
AuthenticationManagerResolver<?> authenticationManagerResolver() {
281+
return mock(AuthenticationManagerResolver.class);
282+
}
283+
284+
}
285+
269286
}

0 commit comments

Comments
 (0)