|
@@ -15,6 +15,9 @@
|
|
|
|
|
|
package org.acegisecurity.providers.dao;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
import org.acegisecurity.AccountExpiredException;
|
|
@@ -32,18 +35,13 @@ import org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache;
|
|
|
import org.acegisecurity.providers.dao.cache.NullUserCache;
|
|
|
import org.acegisecurity.providers.dao.salt.SystemWideSaltSource;
|
|
|
import org.acegisecurity.providers.encoding.ShaPasswordEncoder;
|
|
|
-import org.acegisecurity.userdetails.UserDetailsService;
|
|
|
import org.acegisecurity.userdetails.User;
|
|
|
import org.acegisecurity.userdetails.UserDetails;
|
|
|
+import org.acegisecurity.userdetails.UserDetailsService;
|
|
|
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
|
|
-
|
|
|
-import org.springframework.context.support.StaticMessageSource;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.dao.DataRetrievalFailureException;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Tests {@link DaoAuthenticationProvider}.
|
|
@@ -67,7 +65,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"KOala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -84,7 +81,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"opal");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserPeterAccountExpired());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -101,7 +97,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"opal");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserPeterAccountLocked());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -118,7 +113,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"opal");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserPeterCredentialsExpired());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -146,7 +140,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"opal");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserPeter());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -163,7 +156,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoSimulateBackendError());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -180,7 +172,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -197,7 +188,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"INVALID_PASSWORD");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -214,7 +204,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setHideUserNotFoundExceptions(false); // we want UsernameNotFoundExceptions
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
@@ -232,7 +221,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
assertTrue(provider.isHideUserNotFoundExceptions());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
@@ -250,7 +238,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -268,7 +255,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
token.setDetails("192.168.0.1");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -292,7 +278,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
|
|
@@ -322,7 +307,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
salt.setSystemWideSalt("SYSTEM_SALT_VALUE");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissaWithSalt());
|
|
|
provider.setSaltSource(salt);
|
|
|
provider.setUserCache(new MockUserCache());
|
|
@@ -348,7 +332,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
provider.setUserCache(new MockUserCache());
|
|
|
provider.setForcePrincipalAsString(true);
|
|
@@ -370,7 +353,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
"koala");
|
|
|
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoReturnsNull());
|
|
|
|
|
|
try {
|
|
@@ -384,7 +366,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
|
|
|
public void testGettersSetters() {
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setPasswordEncoder(new ShaPasswordEncoder());
|
|
|
assertEquals(ShaPasswordEncoder.class,
|
|
|
provider.getPasswordEncoder().getClass());
|
|
@@ -409,7 +390,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
MockAuthenticationDaoUserMarissa authenticationDao = new MockAuthenticationDaoUserMarissa();
|
|
|
MockUserCache cache = new MockUserCache();
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(authenticationDao);
|
|
|
provider.setUserCache(cache);
|
|
|
|
|
@@ -436,7 +416,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
public void testStartupFailsIfNoAuthenticationDao()
|
|
|
throws Exception {
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
|
|
|
try {
|
|
|
provider.afterPropertiesSet();
|
|
@@ -448,7 +427,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
|
|
|
public void testStartupFailsIfNoUserCacheSet() throws Exception {
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
provider.setUserDetailsService(new MockAuthenticationDaoUserMarissa());
|
|
|
assertEquals(NullUserCache.class, provider.getUserCache().getClass());
|
|
|
provider.setUserCache(null);
|
|
@@ -463,7 +441,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
|
|
|
public void testStartupSuccess() throws Exception {
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
UserDetailsService dao = new MockAuthenticationDaoUserMarissa();
|
|
|
provider.setUserDetailsService(dao);
|
|
|
provider.setUserCache(new MockUserCache());
|
|
@@ -474,7 +451,6 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
|
|
|
|
|
public void testSupports() {
|
|
|
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
|
|
- provider.setMessageSource(new StaticMessageSource());
|
|
|
assertTrue(provider.supports(UsernamePasswordAuthenticationToken.class));
|
|
|
assertTrue(!provider.supports(TestingAuthenticationToken.class));
|
|
|
}
|