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
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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.AuthenticationManagerResolver;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.ObjectPostProcessor;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
@@ -56,7 +57,8 @@ import org.springframework.util.StringUtils;
|
||||
@ConditionalOnClass(AuthenticationManager.class)
|
||||
@ConditionalOnBean(ObjectPostProcessor.class)
|
||||
@ConditionalOnMissingBean(
|
||||
value = { AuthenticationManager.class, AuthenticationProvider.class, UserDetailsService.class },
|
||||
value = { AuthenticationManager.class, AuthenticationProvider.class, UserDetailsService.class,
|
||||
AuthenticationManagerResolver.class },
|
||||
type = { "org.springframework.security.oauth2.jwt.JwtDecoder",
|
||||
"org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector" })
|
||||
public class UserDetailsServiceAutoConfiguration {
|
||||
|
||||
@@ -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.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
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;
|
||||
@@ -83,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) -> {
|
||||
@@ -266,4 +273,14 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TestAuthenticationManagerResolverConfiguration {
|
||||
|
||||
@Bean
|
||||
AuthenticationManagerResolver<?> authenticationManagerResolver() {
|
||||
return mock(AuthenticationManagerResolver.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user