diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeAuthenticationProviderBeanManagerConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeAuthenticationProviderBeanManagerConfigurer.java index c2365acf2e..bcf1189902 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeAuthenticationProviderBeanManagerConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeAuthenticationProviderBeanManagerConfigurer.java @@ -76,8 +76,8 @@ class InitializeAuthenticationProviderBeanManagerConfigurer extends GlobalAuthen + "using the DSL.", authenticationProviders.size(), beanNames)); return; } - var authenticationProvider = authenticationProviders.get(0).getBean(); - var authenticationProviderBeanName = authenticationProviders.get(0).getName(); + AuthenticationProvider authenticationProvider = authenticationProviders.get(0).getBean(); + String authenticationProviderBeanName = authenticationProviders.get(0).getName(); auth.authenticationProvider(authenticationProvider); this.logger.info(LogMessage.format( @@ -85,19 +85,6 @@ class InitializeAuthenticationProviderBeanManagerConfigurer extends GlobalAuthen authenticationProviderBeanName)); } - /** - * @return a bean of the requested class if there's just a single registered - * component, null otherwise. - */ - private T getBeanOrNull(Class type) { - String[] beanNames = InitializeAuthenticationProviderBeanManagerConfigurer.this.context - .getBeanNamesForType(type); - if (beanNames.length != 1) { - return null; - } - return InitializeAuthenticationProviderBeanManagerConfigurer.this.context.getBean(beanNames[0], type); - } - /** * @return a list of beans of the requested class, along with their names. If * there are no registered beans of that type, the list is empty. diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java index 3594258907..7af1f4b0c5 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java @@ -89,8 +89,8 @@ class InitializeUserDetailsBeanManagerConfigurer extends GlobalAuthenticationCon beanNames)); return; } - var userDetailsService = userDetailsServices.get(0).getBean(); - var userDetailsServiceBeanName = userDetailsServices.get(0).getName(); + UserDetailsService userDetailsService = userDetailsServices.get(0).getBean(); + String userDetailsServiceBeanName = userDetailsServices.get(0).getName(); PasswordEncoder passwordEncoder = getBeanOrNull(PasswordEncoder.class); UserDetailsPasswordService passwordManager = getBeanOrNull(UserDetailsPasswordService.class); CompromisedPasswordChecker passwordChecker = getBeanOrNull(CompromisedPasswordChecker.class); diff --git a/config/src/test/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessorTests.java b/config/src/test/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessorTests.java index 232f732b5f..f02375507e 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessorTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/configuration/AutowireBeanFactoryObjectPostProcessorTests.java @@ -20,6 +20,7 @@ import java.lang.reflect.Modifier; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockedStatic; import org.mockito.Mockito; import org.springframework.aop.framework.ProxyFactory; @@ -141,7 +142,7 @@ public class AutowireBeanFactoryObjectPostProcessorTests { @Test void postProcessWhenObjectIsCgLibProxyAndInNativeImageThenUseExistingBean() { - try (var detector = Mockito.mockStatic(NativeDetector.class)) { + try (MockedStatic detector = Mockito.mockStatic(NativeDetector.class)) { given(NativeDetector.inNativeImage()).willReturn(true); ProxyFactory proxyFactory = new ProxyFactory(new MyClass()); @@ -158,7 +159,7 @@ public class AutowireBeanFactoryObjectPostProcessorTests { @Test void postProcessWhenObjectIsCgLibProxyAndInNativeImageAndBeanDoesNotExistsThenIllegalStateException() { - try (var detector = Mockito.mockStatic(NativeDetector.class)) { + try (MockedStatic detector = Mockito.mockStatic(NativeDetector.class)) { given(NativeDetector.inNativeImage()).willReturn(true); ProxyFactory proxyFactory = new ProxyFactory(new MyClass()); diff --git a/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManagerTests.java b/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManagerTests.java index 78d999232a..0a53171efb 100644 --- a/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManagerTests.java +++ b/ldap/src/integration-test/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManagerTests.java @@ -267,7 +267,7 @@ public class LdapUserDetailsManagerTests { @Test public void testRoleNamesStartWithCustomRolePrefix() { - var customPrefix = "GROUP_"; + String customPrefix = "GROUP_"; this.mgr.setRolePrefix(customPrefix); this.mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));