Skip to content

Commit 7627e09

Browse files
committed
Add @Nullable to changePassword parameters in UserDetailsManager
Closes: gh-18257 Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
1 parent 29b9dc6 commit 7627e09

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

core/src/main/java/org/springframework/security/provisioning/InMemoryUserDetailsManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* system isn't required.
5252
*
5353
* @author Luke Taylor
54+
* @author Andrey Litvitski
5455
* @since 3.1
5556
*/
5657
public class InMemoryUserDetailsManager implements UserDetailsManager, UserDetailsPasswordService {
@@ -130,7 +131,7 @@ public boolean userExists(String username) {
130131
}
131132

132133
@Override
133-
public void changePassword(String oldPassword, String newPassword) {
134+
public void changePassword(@Nullable String oldPassword, @Nullable String newPassword) {
134135
Authentication currentUser = this.securityContextHolderStrategy.getContext().getAuthentication();
135136
if (currentUser == null) {
136137
// This would indicate bad coding somewhere

core/src/main/java/org/springframework/security/provisioning/JdbcUserDetailsManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
*
6868
* @author Luke Taylor
6969
* @author Junhyeok Lee
70+
* @author Andrey Litvitski
7071
* @since 2.0
7172
*/
7273
public class JdbcUserDetailsManager extends JdbcDaoImpl
@@ -308,7 +309,8 @@ private void deleteUserAuthorities(String username) {
308309
}
309310

310311
@Override
311-
public void changePassword(String oldPassword, String newPassword) throws AuthenticationException {
312+
public void changePassword(@Nullable String oldPassword, @Nullable String newPassword)
313+
throws AuthenticationException {
312314
Authentication currentUser = this.securityContextHolderStrategy.getContext().getAuthentication();
313315
if (currentUser == null) {
314316
// This would indicate bad coding somewhere
@@ -335,7 +337,7 @@ public void changePassword(String oldPassword, String newPassword) throws Authen
335337
this.userCache.removeUserFromCache(username);
336338
}
337339

338-
protected Authentication createNewAuthentication(Authentication currentAuth, String newPassword) {
340+
protected Authentication createNewAuthentication(Authentication currentAuth, @Nullable String newPassword) {
339341
UserDetails user = loadUserByUsername(currentAuth.getName());
340342
UsernamePasswordAuthenticationToken newAuthentication = UsernamePasswordAuthenticationToken.authenticated(user,
341343
null, user.getAuthorities());

core/src/main/java/org/springframework/security/provisioning/UserDetailsManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.provisioning;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.security.core.userdetails.UserDetails;
2022
import org.springframework.security.core.userdetails.UserDetailsService;
2123

@@ -49,7 +51,7 @@ public interface UserDetailsManager extends UserDetailsService {
4951
* @param oldPassword current password (for re-authentication if required)
5052
* @param newPassword the password to change to
5153
*/
52-
void changePassword(String oldPassword, String newPassword);
54+
void changePassword(@Nullable String oldPassword, @Nullable String newPassword);
5355

5456
/**
5557
* Check if a user with the supplied login name exists in the system.

0 commit comments

Comments
 (0)