From 5d6ec8ed71318e6ee72c1a0e2c9f901da0b40afe Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 13 Mar 2008 16:49:19 +0000 Subject: [PATCH] SEC-702: Updated use of UsernameNotFoundException to set extraInformation property --- .../security/ldap/search/FilterBasedLdapUserSearch.java | 2 +- .../ldap/authenticator/PasswordComparisonAuthenticator.java | 2 +- .../security/userdetails/jdbc/JdbcDaoImpl.java | 4 ++-- .../springframework/security/userdetails/memory/UserMap.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/springframework/security/ldap/search/FilterBasedLdapUserSearch.java b/core/src/main/java/org/springframework/security/ldap/search/FilterBasedLdapUserSearch.java index d73fb0fa6b..ca411488b3 100644 --- a/core/src/main/java/org/springframework/security/ldap/search/FilterBasedLdapUserSearch.java +++ b/core/src/main/java/org/springframework/security/ldap/search/FilterBasedLdapUserSearch.java @@ -119,7 +119,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch { } catch (IncorrectResultSizeDataAccessException notFound) { if (notFound.getActualSize() == 0) { - throw new UsernameNotFoundException("User " + username + " not found in directory."); + throw new UsernameNotFoundException("User " + username + " not found in directory.", username); } // Search should never return multiple results if properly configured, so just rethrow throw notFound; diff --git a/core/src/main/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticator.java b/core/src/main/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticator.java index 1fb039b09d..3a68a9aca7 100644 --- a/core/src/main/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticator.java +++ b/core/src/main/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticator.java @@ -89,7 +89,7 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic } if (user == null) { - throw new UsernameNotFoundException(username); + throw new UsernameNotFoundException("User not found: " + username, username); } if (logger.isDebugEnabled()) { diff --git a/core/src/main/java/org/springframework/security/userdetails/jdbc/JdbcDaoImpl.java b/core/src/main/java/org/springframework/security/userdetails/jdbc/JdbcDaoImpl.java index 6f21f834a5..71cabeddc2 100644 --- a/core/src/main/java/org/springframework/security/userdetails/jdbc/JdbcDaoImpl.java +++ b/core/src/main/java/org/springframework/security/userdetails/jdbc/JdbcDaoImpl.java @@ -148,7 +148,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService { if (users.size() == 0) { throw new UsernameNotFoundException( - messages.getMessage("JdbcDaoImpl.notFound", new Object[]{username}, "Username {0} not found")); + messages.getMessage("JdbcDaoImpl.notFound", new Object[]{username}, "Username {0} not found"), username); } UserDetails user = (UserDetails) users.get(0); // contains no GrantedAuthority[] @@ -170,7 +170,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService { if (dbAuths.size() == 0) { throw new UsernameNotFoundException( messages.getMessage("JdbcDaoImpl.noAuthority", - new Object[] {username}, "User {0} has no GrantedAuthority")); + new Object[] {username}, "User {0} has no GrantedAuthority"), username); } GrantedAuthority[] arrayAuths = (GrantedAuthority[]) dbAuths.toArray(new GrantedAuthority[dbAuths.size()]); diff --git a/core/src/main/java/org/springframework/security/userdetails/memory/UserMap.java b/core/src/main/java/org/springframework/security/userdetails/memory/UserMap.java index d73c9c4f01..e790d38ce9 100644 --- a/core/src/main/java/org/springframework/security/userdetails/memory/UserMap.java +++ b/core/src/main/java/org/springframework/security/userdetails/memory/UserMap.java @@ -69,7 +69,7 @@ public class UserMap { UserDetails result = (UserDetails) this.userMap.get(username.toLowerCase()); if (result == null) { - throw new UsernameNotFoundException("Could not find user: " + username); + throw new UsernameNotFoundException("Could not find user: " + username, username); } return result;