2
0
Ben Alex 21 жил өмнө
parent
commit
8b9f02e2e7

+ 30 - 0
core/src/test/java/org/acegisecurity/providers/dao/DaoAuthenticationProviderTests.java

@@ -172,6 +172,32 @@ public class DaoAuthenticationProviderTests extends TestCase {
         assertEquals("ROLE_TWO", castResult.getAuthorities()[1].getAuthority());
     }
 
+    public void testAuthenticatesASecondTime() {
+        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("marissa",
+                "koala");
+
+        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
+        provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
+        provider.setUserCache(new MockUserCache());
+
+        Authentication result = provider.authenticate(token);
+
+        if (!(result instanceof UsernamePasswordAuthenticationToken)) {
+            fail(
+                "Should have returned instance of UsernamePasswordAuthenticationToken");
+        }
+
+        // Now try to authenticate with the previous result (with its UserDetails)
+        Authentication result2 = provider.authenticate(result);
+
+        if (!(result2 instanceof UsernamePasswordAuthenticationToken)) {
+            fail(
+                "Should have returned instance of UsernamePasswordAuthenticationToken");
+        }
+
+        assertEquals(result.getCredentials(), result2.getCredentials());
+    }
+
     public void testAuthenticatesWhenASaltIsUsed() {
         UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("marissa",
                 "koala");
@@ -213,6 +239,10 @@ public class DaoAuthenticationProviderTests extends TestCase {
         provider.setUserCache(new EhCacheBasedUserCache());
         assertEquals(EhCacheBasedUserCache.class,
             provider.getUserCache().getClass());
+
+        assertFalse(provider.isForcePrincipalAsString());
+        provider.setForcePrincipalAsString(true);
+        assertTrue(provider.isForcePrincipalAsString());
     }
 
     public void testStartupFailsIfNoAuthenticationDao()

+ 17 - 0
core/src/test/java/org/acegisecurity/ui/AbstractIntegrationFilterTests.java

@@ -152,6 +152,23 @@ public class AbstractIntegrationFilterTests extends TestCase {
         }
     }
 
+    public void testSecureContextSettersGetters() throws Exception {
+        MockAbstractIntegrationFilterImpl filter = new MockAbstractIntegrationFilterImpl(null);
+
+        // check the default
+        assertEquals(SecureContextImpl.class, filter.getSecureContext());
+
+        // check null causes exception
+        filter.setSecureContext(null);
+
+        try {
+            filter.afterPropertiesSet();
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+            assertTrue(true);
+        }
+    }
+
     public void testSuccessWhenConcreteClassReturnsValidAuthenticationObject()
         throws Exception {
         PrincipalAcegiUserToken principal = new PrincipalAcegiUserToken("key",