SEC-56: Add localisation support.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -81,6 +82,7 @@ public class AuthByAdapterTests extends TestCase {
|
||||
public void testAuthByAdapterProviderNonAuthenticationMethods()
|
||||
throws Exception {
|
||||
AuthByAdapterProvider provider = new AuthByAdapterProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
provider.afterPropertiesSet();
|
||||
@@ -99,6 +101,7 @@ public class AuthByAdapterTests extends TestCase {
|
||||
public void testAuthByAdapterProviderOnlyAcceptsAuthByAdapterImplementations()
|
||||
throws Exception {
|
||||
AuthByAdapterProvider provider = new AuthByAdapterProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setKey("my_password");
|
||||
|
||||
// Should fail as UsernamePassword is not interface of AuthByAdapter
|
||||
@@ -119,6 +122,7 @@ public class AuthByAdapterTests extends TestCase {
|
||||
public void testAuthByAdapterProviderRequiresCorrectKey()
|
||||
throws Exception {
|
||||
AuthByAdapterProvider provider = new AuthByAdapterProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setKey("my_password");
|
||||
|
||||
// Should fail as PrincipalAcegiUserToken has different key
|
||||
|
||||
+10
@@ -27,6 +27,7 @@ import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
||||
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
SimpleAclEntry.ADMINISTRATION)});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
provider.afterPropertiesSet();
|
||||
|
||||
@@ -94,6 +96,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
new MockAclObjectIdentity(), null, SimpleAclEntry.DELETE)});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
provider.afterPropertiesSet();
|
||||
|
||||
@@ -123,6 +126,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
new MockAclObjectIdentity(), null, SimpleAclEntry.DELETE)});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
assertEquals(aclManager, provider.getAclManager());
|
||||
provider.afterPropertiesSet();
|
||||
@@ -150,6 +154,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
new MockAclObjectIdentity(), null, SimpleAclEntry.DELETE), new MockAclEntry()});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
provider.afterPropertiesSet();
|
||||
|
||||
@@ -171,6 +176,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
new MockAclObjectIdentity(), null, SimpleAclEntry.READ), new MockAclEntry()});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
assertEquals("AFTER_ACL_READ", provider.getProcessConfigAttribute());
|
||||
provider.setProcessConfigAttribute("AFTER_ACL_ADMIN");
|
||||
@@ -202,6 +208,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
SimpleAclEntry.ADMINISTRATION), new MockAclEntry()});
|
||||
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAclManager(aclManager);
|
||||
assertEquals(SimpleAclEntry.READ, provider.getRequirePermission()[0]);
|
||||
provider.setRequirePermission(new int[] {SimpleAclEntry.ADMINISTRATION});
|
||||
@@ -222,6 +229,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
|
||||
public void testStartupDetectsMissingAclManager() throws Exception {
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
provider.afterPropertiesSet();
|
||||
@@ -234,6 +242,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
public void testStartupDetectsMissingProcessConfigAttribute()
|
||||
throws Exception {
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
AclManager aclManager = new MockAclManager("sydney", "marissa",
|
||||
new AclEntry[] {new SimpleAclEntry("marissa",
|
||||
new MockAclObjectIdentity(), null,
|
||||
@@ -254,6 +263,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||
public void testStartupDetectsMissingRequirePermission()
|
||||
throws Exception {
|
||||
BasicAclEntryAfterInvocationProvider provider = new BasicAclEntryAfterInvocationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
AclManager aclManager = new MockAclManager("sydney", "marissa",
|
||||
new AclEntry[] {new SimpleAclEntry("marissa",
|
||||
new MockAclObjectIdentity(), null,
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.ui.WebAuthenticationDetails;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
|
||||
@@ -39,6 +40,7 @@ public class ConcurrentSessionControllerImplTests extends TestCase {
|
||||
ConcurrentSessionControllerImpl sc = new ConcurrentSessionControllerImpl();
|
||||
SessionRegistry registry = new SessionRegistryImpl();
|
||||
sc.setSessionRegistry(registry);
|
||||
sc.setMessageSource(new StaticMessageSource());
|
||||
|
||||
// Attempt to authenticate - it should be successful
|
||||
Authentication auth = createAuthentication("bob", "1212");
|
||||
|
||||
+13
@@ -41,6 +41,7 @@ import org.acegisecurity.runas.RunAsManagerImpl;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -177,6 +178,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testRejectsAccessDecisionManagersThatDoNotSupportMethodInvocation()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManagerWhichOnlySupportsStrings());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setObjectDefinitionSource(new MockMethodDefinitionSource(false, true));
|
||||
@@ -212,6 +214,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testRejectsCallsWhenObjectDefinitionSourceDoesNotSupportObject()
|
||||
throws Throwable {
|
||||
MethodSecurityInterceptor interceptor = new MethodSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setObjectDefinitionSource(new MockObjectDefinitionSourceWhichOnlySupportsStrings());
|
||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
@@ -228,6 +231,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
|
||||
public void testRejectsCallsWhenObjectIsNull() throws Throwable {
|
||||
MethodSecurityInterceptor interceptor = new MethodSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
interceptor.invoke(null);
|
||||
@@ -240,6 +244,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testRejectsRunAsManagersThatDoNotSupportMethodInvocation()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setObjectDefinitionSource(new MockMethodDefinitionSource(false, true));
|
||||
@@ -258,6 +263,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testStartupCheckForAccessDecisionManager()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setAfterInvocationManager(new MockAfterInvocationManager());
|
||||
@@ -276,6 +282,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testStartupCheckForAuthenticationManager()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
si.setAfterInvocationManager(new MockAfterInvocationManager());
|
||||
@@ -294,6 +301,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testStartupCheckForMethodDefinitionSource()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
|
||||
@@ -308,6 +316,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
|
||||
public void testStartupCheckForRunAsManager() throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setRunAsManager(null); // Overriding the default
|
||||
@@ -325,6 +334,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testStartupCheckForValidAfterInvocationManager()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setAfterInvocationManager(new MockAfterInvocationManagerWhichOnlySupportsStrings());
|
||||
@@ -342,6 +352,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testValidationFailsIfInvalidAttributePresented()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
si.setRunAsManager(new RunAsManagerImpl());
|
||||
@@ -361,6 +372,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testValidationNotAttemptedIfIsValidateConfigAttributesSetToFalse()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
|
||||
@@ -376,6 +388,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
public void testValidationNotAttemptedIfMethodDefinitionSourceCannotReturnIterator()
|
||||
throws Exception {
|
||||
MethodSecurityInterceptor si = new MethodSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setRunAsManager(new MockRunAsManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
|
||||
+3
@@ -30,6 +30,7 @@ import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.intercept.method.MethodDefinitionMap;
|
||||
import org.acegisecurity.intercept.method.MethodDefinitionSourceEditor;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -64,6 +65,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
||||
public void testCallbackIsInvokedWhenPermissionGranted()
|
||||
throws Exception {
|
||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
@@ -100,6 +102,7 @@ public class AspectJSecurityInterceptorTests extends TestCase {
|
||||
public void testCallbackIsNotInvokedWhenPermissionDenied()
|
||||
throws Exception {
|
||||
AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
|
||||
si.setMessageSource(new StaticMessageSource());
|
||||
si.setApplicationEventPublisher(MockApplicationContext.getContext());
|
||||
si.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
si.setAuthenticationManager(new MockAuthenticationManager());
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContextImpl;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
@@ -77,6 +78,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
public void testEnsuresAccessDecisionManagerSupportsFilterInvocationClass()
|
||||
throws Exception {
|
||||
FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setObjectDefinitionSource(new RegExpBasedFilterInvocationDefinitionMap());
|
||||
interceptor.setRunAsManager(new MockRunAsManager());
|
||||
@@ -110,6 +112,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
public void testEnsuresRunAsManagerSupportsFilterInvocationClass()
|
||||
throws Exception {
|
||||
FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setObjectDefinitionSource(new RegExpBasedFilterInvocationDefinitionMap());
|
||||
@@ -144,6 +147,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
throws Throwable {
|
||||
// Setup the FilterSecurityInterceptor
|
||||
FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setRunAsManager(new MockRunAsManager());
|
||||
@@ -183,6 +187,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
|
||||
public void testNormalStartupAndGetter() throws Exception {
|
||||
FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
|
||||
@@ -203,6 +208,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||
public void testSuccessfulInvocation() throws Throwable {
|
||||
// Setup the FilterSecurityInterceptor
|
||||
FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
|
||||
interceptor.setMessageSource(new StaticMessageSource());
|
||||
interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
|
||||
interceptor.setAuthenticationManager(new MockAuthenticationManager());
|
||||
interceptor.setRunAsManager(new MockRunAsManager());
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.acegisecurity.concurrent.NullConcurrentSessionController;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -182,8 +183,8 @@ public class ProviderManagerTests extends TestCase {
|
||||
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
mgr.setProviders(providers);
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
|
||||
mgr.afterPropertiesSet();
|
||||
return mgr;
|
||||
}
|
||||
|
||||
+7
@@ -22,6 +22,7 @@ import org.acegisecurity.BadCredentialsException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsAnInvalidKey() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("WRONG_KEY",
|
||||
@@ -71,6 +73,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
aap.afterPropertiesSet();
|
||||
@@ -82,6 +85,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testGettersSetters() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
aap.afterPropertiesSet();
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
@@ -89,6 +93,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testIgnoresClassesItDoesNotSupport() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("user",
|
||||
@@ -102,6 +107,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
|
||||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("qwerty",
|
||||
@@ -116,6 +122,7 @@ public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testSupports() {
|
||||
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
assertTrue(aap.supports(AnonymousAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
}
|
||||
|
||||
+14
@@ -28,6 +28,7 @@ import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.providers.cas.ticketvalidator.AbstractTicketValidator;
|
||||
import org.acegisecurity.providers.dao.User;
|
||||
import org.acegisecurity.ui.cas.CasProcessingFilter;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -64,6 +65,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testAuthenticateStateful() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider(true));
|
||||
cap.setKey("qwerty");
|
||||
@@ -108,6 +110,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testAuthenticateStateless() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider(true));
|
||||
cap.setKey("qwerty");
|
||||
@@ -144,6 +147,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsAMissingTicketId() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider(true));
|
||||
cap.setKey("qwerty");
|
||||
@@ -167,6 +171,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsAnInvalidKey() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider(true));
|
||||
cap.setKey("qwerty");
|
||||
@@ -193,6 +198,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
public void testDetectsMissingAuthoritiesPopulator()
|
||||
throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setKey("qwerty");
|
||||
cap.setStatelessTicketCache(new MockStatelessTicketCache());
|
||||
@@ -209,6 +215,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setStatelessTicketCache(new MockStatelessTicketCache());
|
||||
@@ -225,6 +232,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingProxyDecider() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setKey("qwerty");
|
||||
cap.setStatelessTicketCache(new MockStatelessTicketCache());
|
||||
@@ -241,6 +249,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
public void testDetectsMissingStatelessTicketCache()
|
||||
throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setKey("qwerty");
|
||||
@@ -257,6 +266,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingTicketValidator() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider(true));
|
||||
cap.setKey("qwerty");
|
||||
@@ -272,6 +282,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testGettersSetters() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setKey("qwerty");
|
||||
@@ -288,6 +299,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testIgnoresClassesItDoesNotSupport() throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setKey("qwerty");
|
||||
@@ -307,6 +319,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
public void testIgnoresUsernamePasswordAuthenticationTokensWithoutCasIdentifiersAsPrincipal()
|
||||
throws Exception {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
cap.setCasAuthoritiesPopulator(new MockAuthoritiesPopulator());
|
||||
cap.setCasProxyDecider(new MockProxyDecider());
|
||||
cap.setKey("qwerty");
|
||||
@@ -322,6 +335,7 @@ public class CasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testSupports() {
|
||||
CasAuthenticationProvider cap = new CasAuthenticationProvider();
|
||||
cap.setMessageSource(new StaticMessageSource());
|
||||
assertTrue(cap.supports(UsernamePasswordAuthenticationToken.class));
|
||||
assertTrue(cap.supports(CasAuthenticationToken.class));
|
||||
}
|
||||
|
||||
+14
-8
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,15 +19,14 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.acegisecurity.providers.cas.ProxyUntrustedException;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link NamedCasProxyDecider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class NamedCasProxyDeciderTests extends TestCase {
|
||||
//~ Constructors ===========================================================
|
||||
@@ -42,17 +41,18 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(NamedCasProxyDeciderTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAcceptsIfNearestProxyIsAuthorized()
|
||||
throws Exception {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
// Build the ticket returned from CAS
|
||||
List proxyList = new Vector();
|
||||
@@ -72,6 +72,8 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
|
||||
public void testAcceptsIfNoProxiesInTicket() {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
List proxyList = new Vector(); // no proxies in list
|
||||
|
||||
proxyDecider.confirmProxyListTrusted(proxyList);
|
||||
@@ -80,6 +82,7 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingValidProxiesList() throws Exception {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
proxyDecider.afterPropertiesSet();
|
||||
@@ -92,6 +95,7 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
|
||||
public void testDoesNotAcceptNull() {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
proxyDecider.confirmProxyListTrusted(null);
|
||||
@@ -103,6 +107,7 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
|
||||
public void testGettersSetters() {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
// Build the list of valid nearest proxies
|
||||
List validProxies = new Vector();
|
||||
@@ -117,6 +122,7 @@ public class NamedCasProxyDeciderTests extends TestCase {
|
||||
public void testRejectsIfNearestProxyIsNotAuthorized()
|
||||
throws Exception {
|
||||
NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
// Build the ticket returned from CAS
|
||||
List proxyList = new Vector();
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.acegisecurity.providers.cas.proxy;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.acegisecurity.providers.cas.ProxyUntrustedException;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -71,6 +72,7 @@ public class RejectProxyTicketsTests extends TestCase {
|
||||
|
||||
public void testRejectsIfAnyProxyInList() {
|
||||
RejectProxyTickets proxyDecider = new RejectProxyTickets();
|
||||
proxyDecider.setMessageSource(new StaticMessageSource());
|
||||
List proxyList = new Vector();
|
||||
proxyList.add("https://localhost/webApp/j_acegi_cas_security_check");
|
||||
|
||||
|
||||
+23
@@ -34,6 +34,7 @@ import org.acegisecurity.providers.dao.cache.NullUserCache;
|
||||
import org.acegisecurity.providers.dao.salt.SystemWideSaltSource;
|
||||
import org.acegisecurity.providers.encoding.ShaPasswordEncoder;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
|
||||
@@ -63,6 +64,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"KOala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -79,6 +81,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"opal");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserPeterAccountExpired());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -95,6 +98,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"opal");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserPeterAccountLocked());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -111,6 +115,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"opal");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserPeterCredentialsExpired());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -138,6 +143,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"opal");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserPeter());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -154,6 +160,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoSimulateBackendError());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -170,6 +177,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -186,6 +194,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"INVALID_PASSWORD");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -202,6 +211,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setHideUserNotFoundExceptions(false); // we want UsernameNotFoundExceptions
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
@@ -219,6 +229,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
assertTrue(provider.isHideUserNotFoundExceptions());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
@@ -236,6 +247,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -253,6 +265,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
token.setDetails("192.168.0.1");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -276,6 +289,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
|
||||
@@ -305,6 +319,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
salt.setSystemWideSalt("SYSTEM_SALT_VALUE");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissaWithSalt());
|
||||
provider.setSaltSource(salt);
|
||||
provider.setUserCache(new MockUserCache());
|
||||
@@ -330,6 +345,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
provider.setUserCache(new MockUserCache());
|
||||
provider.setForcePrincipalAsString(true);
|
||||
@@ -351,6 +367,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
"koala");
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoReturnsNull());
|
||||
|
||||
try {
|
||||
@@ -364,6 +381,7 @@ 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());
|
||||
@@ -388,6 +406,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
MockAuthenticationDaoUserMarissa authenticationDao = new MockAuthenticationDaoUserMarissa();
|
||||
MockUserCache cache = new MockUserCache();
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(authenticationDao);
|
||||
provider.setUserCache(cache);
|
||||
|
||||
@@ -414,6 +433,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
public void testStartupFailsIfNoAuthenticationDao()
|
||||
throws Exception {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
provider.afterPropertiesSet();
|
||||
@@ -425,6 +445,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testStartupFailsIfNoUserCacheSet() throws Exception {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setAuthenticationDao(new MockAuthenticationDaoUserMarissa());
|
||||
assertEquals(NullUserCache.class, provider.getUserCache().getClass());
|
||||
provider.setUserCache(null);
|
||||
@@ -439,6 +460,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testStartupSuccess() throws Exception {
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
AuthenticationDao dao = new MockAuthenticationDaoUserMarissa();
|
||||
provider.setAuthenticationDao(dao);
|
||||
provider.setUserCache(new MockUserCache());
|
||||
@@ -449,6 +471,7 @@ 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));
|
||||
}
|
||||
|
||||
+6
@@ -22,6 +22,7 @@ import org.acegisecurity.BadCredentialsException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsAnInvalidKey() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("WRONG_KEY",
|
||||
@@ -71,6 +73,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
aap.afterPropertiesSet();
|
||||
@@ -82,6 +85,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testGettersSetters() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
aap.afterPropertiesSet();
|
||||
assertEquals("qwerty", aap.getKey());
|
||||
@@ -102,6 +106,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
aap.setKey("qwerty");
|
||||
|
||||
RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("qwerty",
|
||||
@@ -116,6 +121,7 @@ public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testSupports() {
|
||||
RememberMeAuthenticationProvider aap = new RememberMeAuthenticationProvider();
|
||||
aap.setMessageSource(new StaticMessageSource());
|
||||
assertTrue(aap.supports(RememberMeAuthenticationToken.class));
|
||||
assertFalse(aap.supports(TestingAuthenticationToken.class));
|
||||
}
|
||||
|
||||
+6
@@ -20,6 +20,7 @@ import junit.framework.TestCase;
|
||||
import org.acegisecurity.*;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.acegisecurity.providers.dao.User;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class X509AuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testAuthenticationIsNullWithUnsupportedToken() {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
Authentication request = new UsernamePasswordAuthenticationToken("dummy",
|
||||
"dummy");
|
||||
Authentication result = provider.authenticate(request);
|
||||
@@ -57,6 +59,7 @@ public class X509AuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testFailsWithNullCertificate() {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(false));
|
||||
|
||||
@@ -70,6 +73,7 @@ public class X509AuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(false));
|
||||
provider.afterPropertiesSet();
|
||||
@@ -82,6 +86,7 @@ public class X509AuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testPopulatorRejectionCausesFailure() throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
provider.setX509AuthoritiesPopulator(new MockAuthoritiesPopulator(true));
|
||||
|
||||
try {
|
||||
@@ -94,6 +99,7 @@ public class X509AuthenticationProviderTests extends TestCase {
|
||||
|
||||
public void testRequiresPopulator() throws Exception {
|
||||
X509AuthenticationProvider provider = new X509AuthenticationProvider();
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
provider.afterPropertiesSet();
|
||||
|
||||
+7
@@ -26,6 +26,7 @@ import org.acegisecurity.providers.dao.User;
|
||||
import org.acegisecurity.providers.dao.UsernameNotFoundException;
|
||||
import org.acegisecurity.providers.x509.X509TestUtils;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
@@ -56,6 +57,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
public void testDefaultCNPatternMatch() throws Exception {
|
||||
X509Certificate cert = X509TestUtils.buildTestCertificate();
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
|
||||
populator.setAuthenticationDao(new MockAuthenticationDaoMatchesNameOrEmail());
|
||||
populator.afterPropertiesSet();
|
||||
@@ -65,6 +67,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
public void testEmailPatternMatch() throws Exception {
|
||||
X509Certificate cert = X509TestUtils.buildTestCertificate();
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
|
||||
populator.setAuthenticationDao(new MockAuthenticationDaoMatchesNameOrEmail());
|
||||
populator.setSubjectDNRegex("emailAddress=(.*?),");
|
||||
@@ -74,6 +77,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
|
||||
public void testInvalidRegexFails() throws Exception {
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
populator.setAuthenticationDao(new MockAuthenticationDaoMatchesNameOrEmail());
|
||||
populator.setSubjectDNRegex("CN=(.*?,"); // missing closing bracket on group
|
||||
|
||||
@@ -88,6 +92,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
public void testMatchOnShoeSizeFieldInDNFails() throws Exception {
|
||||
X509Certificate cert = X509TestUtils.buildTestCertificate();
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
|
||||
populator.setAuthenticationDao(new MockAuthenticationDaoMatchesNameOrEmail());
|
||||
populator.setSubjectDNRegex("shoeSize=(.*?),");
|
||||
@@ -104,6 +109,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
public void testPatternWithNoGroupFails() throws Exception {
|
||||
X509Certificate cert = X509TestUtils.buildTestCertificate();
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
|
||||
populator.setAuthenticationDao(new MockAuthenticationDaoMatchesNameOrEmail());
|
||||
populator.setSubjectDNRegex("CN=.*?,");
|
||||
@@ -120,6 +126,7 @@ public class DaoX509AuthoritiesPopulatorTests extends TestCase {
|
||||
|
||||
public void testRequiresDao() throws Exception {
|
||||
DaoX509AuthoritiesPopulator populator = new DaoX509AuthoritiesPopulator();
|
||||
populator.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
populator.afterPropertiesSet();
|
||||
|
||||
+9
-8
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,15 +21,15 @@ import org.acegisecurity.Authentication;
|
||||
import org.acegisecurity.BadCredentialsException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link RunAsImplAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RunAsImplAuthenticationProviderTests extends TestCase {
|
||||
//~ Constructors ===========================================================
|
||||
@@ -44,14 +44,14 @@ public class RunAsImplAuthenticationProviderTests extends TestCase {
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(RunAsImplAuthenticationProviderTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAuthenticationFailDueToWrongKey() {
|
||||
RunAsUserToken token = new RunAsUserToken("WRONG_PASSWORD", "Test",
|
||||
"Password",
|
||||
@@ -59,6 +59,7 @@ public class RunAsImplAuthenticationProviderTests extends TestCase {
|
||||
"ROLE_TWO")}, UsernamePasswordAuthenticationToken.class);
|
||||
RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider();
|
||||
provider.setKey("hello_world");
|
||||
provider.setMessageSource(new StaticMessageSource());
|
||||
|
||||
try {
|
||||
provider.authenticate(token);
|
||||
|
||||
+13
@@ -31,6 +31,7 @@ import org.acegisecurity.providers.dao.User;
|
||||
import org.acegisecurity.providers.dao.UsernameNotFoundException;
|
||||
import org.acegisecurity.util.MockFilterChain;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -74,6 +75,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
"user-that-doesnt-exist");
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
|
||||
try {
|
||||
@@ -97,6 +99,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
"mcgarrett");
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
|
||||
try {
|
||||
@@ -122,6 +125,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
"wofat");
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
|
||||
try {
|
||||
@@ -147,6 +151,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
"steve");
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
|
||||
try {
|
||||
@@ -169,6 +174,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
"jacklord");
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
|
||||
Authentication result = filter.attemptSwitchUser(request);
|
||||
@@ -177,6 +183,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
|
||||
public void testBadConfigMissingAuthenticationDao() {
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||
filter.setExitUserUrl("/j_acegi_exit_user");
|
||||
filter.setTargetUrl("/main.jsp");
|
||||
@@ -191,6 +198,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
|
||||
public void testBadConfigMissingTargetUrl() {
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||
filter.setExitUserUrl("/j_acegi_exit_user");
|
||||
@@ -206,6 +214,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
public void testDefaultProcessesFilterUrlWithPathParameter() {
|
||||
MockHttpServletRequest request = createMockSwitchRequest();
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||
|
||||
request.setRequestURI(
|
||||
@@ -238,6 +247,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
|
||||
// setup filter
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
filter.setExitUserUrl("/j_acegi_exit_user");
|
||||
|
||||
@@ -266,6 +276,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
|
||||
// setup filter
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
filter.setExitUserUrl("/j_acegi_exit_user");
|
||||
|
||||
@@ -294,6 +305,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
MockFilterChain chain = new MockFilterChain(true);
|
||||
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||
filter.setTargetUrl("/webapp/someOtherUrl");
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
@@ -343,6 +355,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
|
||||
|
||||
// setup filter
|
||||
SwitchUserProcessingFilter filter = new SwitchUserProcessingFilter();
|
||||
filter.setMessageSource(new StaticMessageSource());
|
||||
filter.setAuthenticationDao(new MockAuthenticationDaoUserJackLord());
|
||||
filter.setSwitchUserUrl("/j_acegi_switch_user");
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
import org.acegisecurity.SecurityConfig;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -143,6 +144,7 @@ public class AffirmativeBasedTests extends TestCase {
|
||||
|
||||
private AffirmativeBased makeDecisionManager() {
|
||||
AffirmativeBased decisionManager = new AffirmativeBased();
|
||||
decisionManager.setMessageSource(new StaticMessageSource());
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
import org.acegisecurity.SecurityConfig;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -164,6 +165,7 @@ public class ConsensusBasedTests extends TestCase {
|
||||
|
||||
private ConsensusBased makeDecisionManager() {
|
||||
ConsensusBased decisionManager = new ConsensusBased();
|
||||
decisionManager.setMessageSource(new StaticMessageSource());
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
import org.acegisecurity.SecurityConfig;
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -59,6 +60,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant
|
||||
@@ -76,6 +78,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
config.addConfigAttribute(new SecurityConfig("ROLE_2")); // grant
|
||||
@@ -88,6 +91,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
config.addConfigAttribute(new SecurityConfig("ROLE_WE_DO_NOT_HAVE")); // deny
|
||||
@@ -103,6 +107,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
public void testRoleVoterPrefixObserved() throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestTokenWithFooBarPrefix();
|
||||
UnanimousBased mgr = makeDecisionManagerWithFooBarPrefix();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
config.addConfigAttribute(new SecurityConfig("FOOBAR_1")); // grant
|
||||
@@ -116,6 +121,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
assertTrue(!mgr.isAllowIfAllAbstainDecisions()); // check default
|
||||
|
||||
@@ -135,6 +141,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setAllowIfAllAbstainDecisions(true);
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
assertTrue(mgr.isAllowIfAllAbstainDecisions()); // check changed
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
@@ -148,6 +155,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
throws Exception {
|
||||
TestingAuthenticationToken auth = makeTestToken();
|
||||
UnanimousBased mgr = makeDecisionManager();
|
||||
mgr.setMessageSource(new StaticMessageSource());
|
||||
|
||||
ConfigAttributeDefinition config = new ConfigAttributeDefinition();
|
||||
config.addConfigAttribute(new SecurityConfig("ROLE_1")); // grant
|
||||
@@ -159,6 +167,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
|
||||
private UnanimousBased makeDecisionManager() {
|
||||
UnanimousBased decisionManager = new UnanimousBased();
|
||||
decisionManager.setMessageSource(new StaticMessageSource());
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
@@ -173,6 +182,7 @@ public class UnanimousBasedTests extends TestCase {
|
||||
|
||||
private UnanimousBased makeDecisionManagerWithFooBarPrefix() {
|
||||
UnanimousBased decisionManager = new UnanimousBased();
|
||||
decisionManager.setMessageSource(new StaticMessageSource());
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
roleVoter.setRolePrefix("FOOBAR_");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user