|
@@ -286,6 +286,22 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
assertEquals("marissa", castResult.getPrincipal());
|
|
assertEquals("marissa", castResult.getPrincipal());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testDetectsNullBeingReturnedFromAuthenticationDao() {
|
|
|
|
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("marissa",
|
|
|
|
+ "koala");
|
|
|
|
+
|
|
|
|
+ DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
|
+ provider.setAuthenticationDao(new MockAuthenticationDaoReturnsNull());
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ provider.authenticate(token);
|
|
|
|
+ fail("Should have thrown AuthenticationServiceException");
|
|
|
|
+ } catch (AuthenticationServiceException expected) {
|
|
|
|
+ assertEquals("AuthenticationDao returned null, which is an interface contract violation",
|
|
|
|
+ expected.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testGettersSetters() {
|
|
public void testGettersSetters() {
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
provider.setPasswordEncoder(new ShaPasswordEncoder());
|
|
provider.setPasswordEncoder(new ShaPasswordEncoder());
|
|
@@ -384,6 +400,13 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
|
|
|
//~ Inner Classes ==========================================================
|
|
//~ Inner Classes ==========================================================
|
|
|
|
|
|
|
|
+ private class MockAuthenticationDaoReturnsNull implements AuthenticationDao {
|
|
|
|
+ public UserDetails loadUserByUsername(String username)
|
|
|
|
+ throws UsernameNotFoundException, DataAccessException {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private class MockAuthenticationDaoSimulateBackendError
|
|
private class MockAuthenticationDaoSimulateBackendError
|
|
implements AuthenticationDao {
|
|
implements AuthenticationDao {
|
|
public UserDetails loadUserByUsername(String username)
|
|
public UserDetails loadUserByUsername(String username)
|