mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	SEC-281: Modified to use Spring 1.2 compatible exception class for incorrect search results size.
This commit is contained in:
		
							parent
							
								
									02e7bbb982
								
							
						
					
					
						commit
						ee50d6e334
					
				| @ -16,7 +16,6 @@ | |||||||
| package org.acegisecurity.ldap; | package org.acegisecurity.ldap; | ||||||
| 
 | 
 | ||||||
| import org.springframework.dao.DataAccessException; | import org.springframework.dao.DataAccessException; | ||||||
| import org.springframework.dao.EmptyResultDataAccessException; |  | ||||||
| import org.springframework.dao.IncorrectResultSizeDataAccessException; | import org.springframework.dao.IncorrectResultSizeDataAccessException; | ||||||
| 
 | 
 | ||||||
| import org.springframework.util.Assert; | import org.springframework.util.Assert; | ||||||
| @ -234,8 +233,7 @@ public class LdapTemplate { | |||||||
|      * |      * | ||||||
|      * @return the object created by the mapper from the matching entry |      * @return the object created by the mapper from the matching entry | ||||||
|      * |      * | ||||||
|      * @throws EmptyResultDataAccessException if no results are found. |      * @throws IncorrectResultSizeDataAccessException if no results are found or the search returns more than one result. | ||||||
|      * @throws IncorrectResultSizeDataAccessException if the search returns more than one result. |  | ||||||
|      */ |      */ | ||||||
|     public Object searchForSingleEntry(final String base, final String filter, final Object[] params, |     public Object searchForSingleEntry(final String base, final String filter, final Object[] params, | ||||||
|         final LdapEntryMapper mapper) { |         final LdapEntryMapper mapper) { | ||||||
| @ -245,13 +243,14 @@ public class LdapTemplate { | |||||||
|                     NamingEnumeration results = ctx.search(base, filter, params, searchControls); |                     NamingEnumeration results = ctx.search(base, filter, params, searchControls); | ||||||
| 
 | 
 | ||||||
|                     if (!results.hasMore()) { |                     if (!results.hasMore()) { | ||||||
|                         throw new EmptyResultDataAccessException(1); |                         throw new IncorrectResultSizeDataAccessException(1, 0); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     SearchResult searchResult = (SearchResult) results.next(); |                     SearchResult searchResult = (SearchResult) results.next(); | ||||||
| 
 | 
 | ||||||
|                     if (results.hasMore()) { |                     if (results.hasMore()) { | ||||||
|                         throw new IncorrectResultSizeDataAccessException(1); |                         // We don't know how many results but set to 2 which is good enough | ||||||
|  |                         throw new IncorrectResultSizeDataAccessException(1, 2); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     // Work out the DN of the matched entry |                     // Work out the DN of the matched entry | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ import org.acegisecurity.userdetails.ldap.LdapUserDetailsMapper; | |||||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||||
| import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||||
| 
 | 
 | ||||||
| import org.springframework.dao.EmptyResultDataAccessException; | import org.springframework.dao.IncorrectResultSizeDataAccessException; | ||||||
| 
 | 
 | ||||||
| import org.springframework.util.Assert; | import org.springframework.util.Assert; | ||||||
| 
 | 
 | ||||||
| @ -123,8 +123,12 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch { | |||||||
|             user.setUsername(username); |             user.setUsername(username); | ||||||
| 
 | 
 | ||||||
|             return user.createUserDetails(); |             return user.createUserDetails(); | ||||||
|         } catch (EmptyResultDataAccessException notFound) { |         } catch (IncorrectResultSizeDataAccessException notFound) { | ||||||
|             throw new UsernameNotFoundException("User " + username + " not found in directory."); |             if(notFound.getActualSize() == 0) { | ||||||
|  |                 throw new UsernameNotFoundException("User " + username + " not found in directory."); | ||||||
|  |             } | ||||||
|  |             // Search should never return multiple results if properly configured, so just rethrow | ||||||
|  |             throw notFound; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user