Skip to content

Commit bc5e6da

Browse files
Remove deprecated elements from DaoAuthenticationProvider
Closes gh-17298 Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 42e24aa commit bc5e6da

File tree

13 files changed

+76
-136
lines changed

13 files changed

+76
-136
lines changed

config/src/main/java/org/springframework/security/config/authentication/AbstractUserDetailsServiceBeanDefinitionParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.beans.factory.BeanDefinitionStoreException;
2222
import org.springframework.beans.factory.config.BeanDefinition;
23+
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
2324
import org.springframework.beans.factory.config.RuntimeBeanReference;
2425
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
2526
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -73,8 +74,10 @@ private String resolveId(Element element, AbstractBeanDefinition definition, Par
7374
if (!StringUtils.hasText(id)) {
7475
id = pc.getReaderContext().generateBeanName(definition);
7576
}
77+
ValueHolder userDetailsServiceValueHolder = new ValueHolder(new RuntimeBeanReference(id));
78+
userDetailsServiceValueHolder.setName("userDetailsService");
7679
BeanDefinition container = pc.getContainingBeanDefinition();
77-
container.getPropertyValues().add("userDetailsService", new RuntimeBeanReference(id));
80+
container.getConstructorArgumentValues().addGenericArgumentValue(userDetailsServiceValueHolder);
7881
}
7982
if (StringUtils.hasText(id)) {
8083
return id;

config/src/main/java/org/springframework/security/config/authentication/AuthenticationProviderBeanDefinitionParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.beans.BeanMetadataElement;
2222
import org.springframework.beans.factory.config.BeanDefinition;
23+
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
2324
import org.springframework.beans.factory.config.RuntimeBeanReference;
2425
import org.springframework.beans.factory.support.RootBeanDefinition;
2526
import org.springframework.beans.factory.xml.BeanDefinitionParser;
@@ -64,7 +65,9 @@ public BeanDefinition parse(Element element, ParserContext pc) {
6465
+ "elements '" + Elements.USER_SERVICE + "', '" + Elements.JDBC_USER_SERVICE + "' or '"
6566
+ Elements.LDAP_USER_SERVICE + "'", element);
6667
}
67-
authProvider.getPropertyValues().add("userDetailsService", new RuntimeBeanReference(ref));
68+
ValueHolder userDetailsServiceValueHolder = new ValueHolder(new RuntimeBeanReference(ref));
69+
userDetailsServiceValueHolder.setName("userDetailsService");
70+
authProvider.getConstructorArgumentValues().addGenericArgumentValue(userDetailsServiceValueHolder);
6871
}
6972
else {
7073
// Use the child elements to create the UserDetailsService

config/src/test/java/org/springframework/security/config/annotation/authentication/AuthenticationManagerBuilderTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -241,8 +241,7 @@ AuthenticationManager authenticationManager() throws Exception {
241241

242242
@Bean
243243
AuthenticationProvider authenticationProvider() throws Exception {
244-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
245-
provider.setUserDetailsService(userDetailsService());
244+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(userDetailsService());
246245
return provider;
247246
}
248247

config/src/test/java/org/springframework/security/config/annotation/authentication/NamespaceAuthenticationProviderTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -74,9 +74,7 @@ void configure(AuthenticationManagerBuilder auth) {
7474

7575
@Bean
7676
DaoAuthenticationProvider authenticationProvider() {
77-
DaoAuthenticationProvider result = new DaoAuthenticationProvider();
78-
result.setUserDetailsService(new InMemoryUserDetailsManager(PasswordEncodedUser.user()));
79-
return result;
77+
return new DaoAuthenticationProvider(new InMemoryUserDetailsManager(PasswordEncodedUser.user()));
8078
}
8179

8280
}

config/src/test/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfigurationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -503,8 +503,7 @@ public void configure(AuthenticationManagerBuilder auth) {
503503
UserDetails user = User.withUserDetails(PasswordEncodedUser.user()).username("boot").build();
504504
List<UserDetails> users = Arrays.asList(user);
505505
InMemoryUserDetailsManager inMemory = new InMemoryUserDetailsManager(users);
506-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
507-
provider.setUserDetailsService(inMemory);
506+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(inMemory);
508507
auth.authenticationProvider(provider);
509508
}
510509

config/src/test/java/org/springframework/security/config/annotation/web/configurers/RememberMeConfigurerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -378,8 +378,8 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
378378
@Autowired
379379
void configure(AuthenticationManagerBuilder auth) {
380380
User user = (User) PasswordEncodedUser.user();
381-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
382-
provider.setUserDetailsService(new InMemoryUserDetailsManager(Collections.singletonList(user)));
381+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(
382+
new InMemoryUserDetailsManager(Collections.singletonList(user)));
383383
// @formatter:off
384384
auth
385385
.authenticationProvider(provider);

config/src/test/java/org/springframework/security/config/annotation/web/configurers/ServletApiConfigurerTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -269,8 +269,7 @@ UserDetailsService userDetailsService() {
269269

270270
@Bean
271271
AuthenticationManager customAuthenticationManager(UserDetailsService userDetailsService) {
272-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
273-
provider.setUserDetailsService(userDetailsService);
272+
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(userDetailsService);
274273
return provider::authenticate;
275274
}
276275

config/src/test/resources/org/springframework/security/config/http/MiscHttpConfigTests-Sec750.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</authentication-manager>
3535

3636
<b:bean name="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
37-
<b:property name="userDetailsService" ref="userService"/>
37+
<b:constructor-arg name="userDetailsService" ref="userService"/>
3838
</b:bean>
3939

4040
<b:bean name="userService" class="org.mockito.Mockito" factory-method="mock">

core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,11 @@ public class DaoAuthenticationProvider extends AbstractUserDetailsAuthentication
6868

6969
private CompromisedPasswordChecker compromisedPasswordChecker;
7070

71-
/**
72-
* @deprecated Please provide the {@link UserDetailsService} in the constructor
73-
*/
74-
@Deprecated
75-
public DaoAuthenticationProvider() {
76-
}
77-
7871
public DaoAuthenticationProvider(UserDetailsService userDetailsService) {
79-
setUserDetailsService(userDetailsService);
80-
}
81-
82-
/**
83-
* Creates a new instance using the provided {@link PasswordEncoder}
84-
* @param passwordEncoder the {@link PasswordEncoder} to use. Cannot be null.
85-
* @since 6.0.3
86-
* @deprecated Please provide the {@link UserDetailsService} in the constructor
87-
* followed by {@link #setPasswordEncoder(PasswordEncoder)} instead
88-
*/
89-
@Deprecated
90-
public DaoAuthenticationProvider(PasswordEncoder passwordEncoder) {
91-
setPasswordEncoder(passwordEncoder);
72+
this.userDetailsService = userDetailsService;
9273
}
9374

9475
@Override
95-
@SuppressWarnings("deprecation")
9676
protected void additionalAuthenticationChecks(UserDetails userDetails,
9777
UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
9878
if (authentication.getCredentials() == null) {
@@ -185,15 +165,6 @@ protected PasswordEncoder getPasswordEncoder() {
185165
return this.passwordEncoder.get();
186166
}
187167

188-
/**
189-
* @param userDetailsService
190-
* @deprecated Please provide the {@link UserDetailsService} in the constructor
191-
*/
192-
@Deprecated
193-
public void setUserDetailsService(UserDetailsService userDetailsService) {
194-
this.userDetailsService = userDetailsService;
195-
}
196-
197168
protected UserDetailsService getUserDetailsService() {
198169
return this.userDetailsService;
199170
}

0 commit comments

Comments
 (0)