SEC-113 Provide MethodInvocationUtils.
This commit is contained in:
parent
863ba3f0a3
commit
731d7b2e89
|
@ -0,0 +1,134 @@
|
||||||
|
/* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.acegisecurity.util;
|
||||||
|
|
||||||
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static utility methods for creating <code>MethodInvocation</code>s usable
|
||||||
|
* within Acegi Security.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* All methods of this class return a {@link
|
||||||
|
* org.acegisecurity.util.SimpleMethodInvocation}.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Ben Alex
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class MethodInvocationUtils {
|
||||||
|
//~ Methods ================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a <code>MethodInvocation</code> for specified
|
||||||
|
* <code>methodName</code> on the passed object.
|
||||||
|
*
|
||||||
|
* @param object the object that will be used to find the relevant
|
||||||
|
* <code>Method</code>
|
||||||
|
* @param methodName the name of the method to find
|
||||||
|
*
|
||||||
|
* @return a <code>MethodInvocation</code>, or <code>null</code> if there
|
||||||
|
* was a problem
|
||||||
|
*/
|
||||||
|
public static MethodInvocation create(Object object, String methodName) {
|
||||||
|
return create(object, methodName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a <code>MethodInvocation</code> for specified
|
||||||
|
* <code>methodName</code> on the passed object, using the
|
||||||
|
* <code>args</code> to locate the method.
|
||||||
|
*
|
||||||
|
* @param object the object that will be used to find the relevant
|
||||||
|
* <code>Method</code>
|
||||||
|
* @param methodName the name of the method to find
|
||||||
|
* @param args arguments that are required as part of the method signature
|
||||||
|
*
|
||||||
|
* @return a <code>MethodInvocation</code>, or <code>null</code> if there
|
||||||
|
* was a problem
|
||||||
|
*/
|
||||||
|
public static MethodInvocation create(Object object, String methodName,
|
||||||
|
Object[] args) {
|
||||||
|
Assert.notNull(object, "Object required");
|
||||||
|
|
||||||
|
Class[] classArgs = null;
|
||||||
|
|
||||||
|
if (args != null) {
|
||||||
|
List list = new ArrayList();
|
||||||
|
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
list.add(args[i].getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
classArgs = (Class[]) list.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createFromClass(object.getClass(), methodName, classArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a <code>MethodInvocation</code> for specified
|
||||||
|
* <code>methodName</code> on the passed class.
|
||||||
|
*
|
||||||
|
* @param clazz the class of object that will be used to find the relevant
|
||||||
|
* <code>Method</code>
|
||||||
|
* @param methodName the name of the method to find
|
||||||
|
*
|
||||||
|
* @return a <code>MethodInvocation</code>, or <code>null</code> if there
|
||||||
|
* was a problem
|
||||||
|
*/
|
||||||
|
public static MethodInvocation createFromClass(Class clazz,
|
||||||
|
String methodName) {
|
||||||
|
return createFromClass(clazz, methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a <code>MethodInvocation</code> for specified
|
||||||
|
* <code>methodName</code> on the passed class, using the
|
||||||
|
* <code>args</code> to locate the method.
|
||||||
|
*
|
||||||
|
* @param clazz the class of object that will be used to find the relevant
|
||||||
|
* <code>Method</code>
|
||||||
|
* @param methodName the name of the method to find
|
||||||
|
* @param args arguments that are required as part of the method signature
|
||||||
|
*
|
||||||
|
* @return a <code>MethodInvocation</code>, or <code>null</code> if there
|
||||||
|
* was a problem
|
||||||
|
*/
|
||||||
|
public static MethodInvocation createFromClass(Class clazz,
|
||||||
|
String methodName, Class[] args) {
|
||||||
|
Assert.notNull(clazz, "Class required");
|
||||||
|
Assert.hasText(methodName, "MethodName required");
|
||||||
|
|
||||||
|
Method method;
|
||||||
|
|
||||||
|
try {
|
||||||
|
method = clazz.getMethod(methodName, args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SimpleMethodInvocation(method, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.acegisecurity;
|
package org.acegisecurity.util;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the AOP Alliance <code>MethodInvocation</code> secure object.
|
* Represents the AOP Alliance <code>MethodInvocation</code>.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class MockMethodInvocation implements MethodInvocation {
|
public class SimpleMethodInvocation implements MethodInvocation {
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
private Method method;
|
private Method method;
|
||||||
|
@ -35,12 +35,12 @@ public class MockMethodInvocation implements MethodInvocation {
|
||||||
|
|
||||||
//~ Constructors ===========================================================
|
//~ Constructors ===========================================================
|
||||||
|
|
||||||
public MockMethodInvocation(Method method, Object[] arguments) {
|
public SimpleMethodInvocation(Method method, Object[] arguments) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MockMethodInvocation() {}
|
public SimpleMethodInvocation() {}
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
|
@ -21,9 +21,9 @@ import org.acegisecurity.AccessDeniedException;
|
||||||
import org.acegisecurity.Authentication;
|
import org.acegisecurity.Authentication;
|
||||||
import org.acegisecurity.ConfigAttribute;
|
import org.acegisecurity.ConfigAttribute;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.intercept.web.FilterInvocation;
|
import org.acegisecurity.intercept.web.FilterInvocation;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -88,23 +88,23 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||||
attr4.addConfigAttribute(new SecurityConfig("NEVER_CAUSES_SWAP"));
|
attr4.addConfigAttribute(new SecurityConfig("NEVER_CAUSES_SWAP"));
|
||||||
|
|
||||||
assertEquals("swap1",
|
assertEquals("swap1",
|
||||||
manager.decide(null, new MockMethodInvocation(), attr1,
|
manager.decide(null, new SimpleMethodInvocation(), attr1,
|
||||||
"content-before-swapping"));
|
"content-before-swapping"));
|
||||||
|
|
||||||
assertEquals("swap2",
|
assertEquals("swap2",
|
||||||
manager.decide(null, new MockMethodInvocation(), attr2,
|
manager.decide(null, new SimpleMethodInvocation(), attr2,
|
||||||
"content-before-swapping"));
|
"content-before-swapping"));
|
||||||
|
|
||||||
assertEquals("swap3",
|
assertEquals("swap3",
|
||||||
manager.decide(null, new MockMethodInvocation(), attr3,
|
manager.decide(null, new SimpleMethodInvocation(), attr3,
|
||||||
"content-before-swapping"));
|
"content-before-swapping"));
|
||||||
|
|
||||||
assertEquals("content-before-swapping",
|
assertEquals("content-before-swapping",
|
||||||
manager.decide(null, new MockMethodInvocation(), attr4,
|
manager.decide(null, new SimpleMethodInvocation(), attr4,
|
||||||
"content-before-swapping"));
|
"content-before-swapping"));
|
||||||
|
|
||||||
assertEquals("swap3",
|
assertEquals("swap3",
|
||||||
manager.decide(null, new MockMethodInvocation(), attr2and3,
|
manager.decide(null, new SimpleMethodInvocation(), attr2and3,
|
||||||
"content-before-swapping"));
|
"content-before-swapping"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,13 @@ import junit.framework.TestCase;
|
||||||
import org.acegisecurity.AuthorizationServiceException;
|
import org.acegisecurity.AuthorizationServiceException;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockAclManager;
|
import org.acegisecurity.MockAclManager;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.acl.AclEntry;
|
import org.acegisecurity.acl.AclEntry;
|
||||||
import org.acegisecurity.acl.AclManager;
|
import org.acegisecurity.acl.AclManager;
|
||||||
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
||||||
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
@ -88,7 +88,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(0, filteredList.size());
|
assertEquals(0, filteredList.size());
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(0, filteredList.size());
|
assertEquals(0, filteredList.size());
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(1, filteredList.size());
|
assertEquals(1, filteredList.size());
|
||||||
assertEquals("belmont", filteredList.get(0));
|
assertEquals("belmont", filteredList.get(0));
|
||||||
|
@ -199,7 +199,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
String[] filteredList = (String[]) provider.decide(auth,
|
String[] filteredList = (String[]) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(1, filteredList.length);
|
assertEquals(1, filteredList.length);
|
||||||
assertEquals("belmont", filteredList[0]);
|
assertEquals("belmont", filteredList[0]);
|
||||||
|
@ -228,7 +228,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
try {
|
try {
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr,
|
provider.decide(auth, new SimpleMethodInvocation(), attr,
|
||||||
new String("RETURN_OBJECT_NOT_COLLECTION"));
|
new String("RETURN_OBJECT_NOT_COLLECTION"));
|
||||||
fail("Should have thrown AuthorizationServiceException");
|
fail("Should have thrown AuthorizationServiceException");
|
||||||
} catch (AuthorizationServiceException expected) {
|
} catch (AuthorizationServiceException expected) {
|
||||||
|
@ -259,7 +259,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, null);
|
new SimpleMethodInvocation(), attr, null);
|
||||||
|
|
||||||
assertNull(filteredList);
|
assertNull(filteredList);
|
||||||
}
|
}
|
||||||
|
@ -296,14 +296,14 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// As no matching config attrib, ensure provider doesn't change list
|
// As no matching config attrib, ensure provider doesn't change list
|
||||||
assertEquals(4,
|
assertEquals(4,
|
||||||
((List) provider.decide(auth, new MockMethodInvocation(), attr, list))
|
((List) provider.decide(auth, new SimpleMethodInvocation(), attr, list))
|
||||||
.size());
|
.size());
|
||||||
|
|
||||||
// Filter, this time with the conf attrib provider setup to answer
|
// Filter, this time with the conf attrib provider setup to answer
|
||||||
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_COLLECTION_ADMIN"));
|
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_COLLECTION_ADMIN"));
|
||||||
|
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(1, filteredList.size());
|
assertEquals(1, filteredList.size());
|
||||||
assertEquals("sydney", filteredList.get(0));
|
assertEquals("sydney", filteredList.get(0));
|
||||||
|
@ -341,7 +341,7 @@ public class BasicAclEntryAfterInvocationCollectionFilteringProviderTests
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
List filteredList = (List) provider.decide(auth,
|
List filteredList = (List) provider.decide(auth,
|
||||||
new MockMethodInvocation(), attr, list);
|
new SimpleMethodInvocation(), attr, list);
|
||||||
|
|
||||||
assertEquals(1, filteredList.size());
|
assertEquals(1, filteredList.size());
|
||||||
assertEquals("sydney", filteredList.get(0));
|
assertEquals("sydney", filteredList.get(0));
|
||||||
|
|
|
@ -20,13 +20,13 @@ import junit.framework.TestCase;
|
||||||
import org.acegisecurity.AccessDeniedException;
|
import org.acegisecurity.AccessDeniedException;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockAclManager;
|
import org.acegisecurity.MockAclManager;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.acl.AclEntry;
|
import org.acegisecurity.acl.AclEntry;
|
||||||
import org.acegisecurity.acl.AclManager;
|
import org.acegisecurity.acl.AclManager;
|
||||||
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
||||||
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "belmont");
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont");
|
||||||
fail("Should have thrown AccessDeniedException");
|
fail("Should have thrown AccessDeniedException");
|
||||||
} catch (AccessDeniedException expected) {
|
} catch (AccessDeniedException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
@ -104,7 +104,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "belmont");
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont");
|
||||||
fail("Should have thrown AccessDeniedException");
|
fail("Should have thrown AccessDeniedException");
|
||||||
} catch (AccessDeniedException expected) {
|
} catch (AccessDeniedException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
@ -135,7 +135,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
assertEquals("belmont",
|
assertEquals("belmont",
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "belmont"));
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "belmont"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGrantsAccessIfReturnedObjectIsNull()
|
public void testGrantsAccessIfReturnedObjectIsNull()
|
||||||
|
@ -160,7 +160,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_READ"));
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
assertNull(provider.decide(auth, new MockMethodInvocation(), attr, null));
|
assertNull(provider.decide(auth, new SimpleMethodInvocation(), attr, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRespectsModificationsToProcessConfigAttribute()
|
public void testRespectsModificationsToProcessConfigAttribute()
|
||||||
|
@ -185,12 +185,12 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
|
|
||||||
// As no matching config attrib, ensure provider returns original obj
|
// As no matching config attrib, ensure provider returns original obj
|
||||||
assertEquals("sydney",
|
assertEquals("sydney",
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "sydney"));
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||||
|
|
||||||
// Filter, this time with the conf attrib provider setup to answer
|
// Filter, this time with the conf attrib provider setup to answer
|
||||||
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_ADMIN"));
|
attr.addConfigAttribute(new SecurityConfig("AFTER_ACL_ADMIN"));
|
||||||
assertEquals("sydney",
|
assertEquals("sydney",
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "sydney"));
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRespectsModificationsToRequirePermissions()
|
public void testRespectsModificationsToRequirePermissions()
|
||||||
|
@ -217,7 +217,7 @@ public class BasicAclEntryAfterInvocationProviderTests extends TestCase {
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
assertEquals("sydney",
|
assertEquals("sydney",
|
||||||
provider.decide(auth, new MockMethodInvocation(), attr, "sydney"));
|
provider.decide(auth, new SimpleMethodInvocation(), attr, "sydney"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStartupDetectsMissingAclManager() throws Exception {
|
public void testStartupDetectsMissingAclManager() throws Exception {
|
||||||
|
|
|
@ -18,13 +18,13 @@ package org.acegisecurity.context.rmi;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.Authentication;
|
import org.acegisecurity.Authentication;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.TargetObject;
|
import org.acegisecurity.TargetObject;
|
||||||
import org.acegisecurity.context.SecurityContextHolder;
|
import org.acegisecurity.context.SecurityContextHolder;
|
||||||
import org.acegisecurity.context.SecurityContextImpl;
|
import org.acegisecurity.context.SecurityContextImpl;
|
||||||
import org.acegisecurity.context.rmi.ContextPropagatingRemoteInvocation;
|
import org.acegisecurity.context.rmi.ContextPropagatingRemoteInvocation;
|
||||||
import org.acegisecurity.context.rmi.ContextPropagatingRemoteInvocationFactory;
|
import org.acegisecurity.context.rmi.ContextPropagatingRemoteInvocationFactory;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
|
||||||
Class clazz = TargetObject.class;
|
Class clazz = TargetObject.class;
|
||||||
Method method = clazz.getMethod("makeLowerCase",
|
Method method = clazz.getMethod("makeLowerCase",
|
||||||
new Class[] {String.class});
|
new Class[] {String.class});
|
||||||
MethodInvocation mi = new MockMethodInvocation(method,
|
MethodInvocation mi = new SimpleMethodInvocation(method,
|
||||||
new Object[] {"SOME_STRING"});
|
new Object[] {"SOME_STRING"});
|
||||||
|
|
||||||
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
|
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
|
||||||
|
|
|
@ -19,7 +19,7 @@ import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.AuthenticationCredentialsNotFoundException;
|
import org.acegisecurity.AuthenticationCredentialsNotFoundException;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +56,7 @@ public class AuthenticationCredentialsNotFoundEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthenticationCredentialsNotFoundEvent(new MockMethodInvocation(),
|
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(),
|
||||||
null, new AuthenticationCredentialsNotFoundException("test"));
|
null, new AuthenticationCredentialsNotFoundException("test"));
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
|
@ -64,7 +64,7 @@ public class AuthenticationCredentialsNotFoundEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthenticationCredentialsNotFoundEvent(new MockMethodInvocation(),
|
new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(),
|
||||||
new ConfigAttributeDefinition(), null);
|
new ConfigAttributeDefinition(), null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
|
|
|
@ -19,9 +19,9 @@ import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.AccessDeniedException;
|
import org.acegisecurity.AccessDeniedException;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.event.authorization.AuthorizationFailureEvent;
|
import org.acegisecurity.event.authorization.AuthorizationFailureEvent;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +59,7 @@ public class AuthorizationFailureEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthorizationFailureEvent(new MockMethodInvocation(), null,
|
new AuthorizationFailureEvent(new SimpleMethodInvocation(), null,
|
||||||
new UsernamePasswordAuthenticationToken("foo", "bar"),
|
new UsernamePasswordAuthenticationToken("foo", "bar"),
|
||||||
new AccessDeniedException("error"));
|
new AccessDeniedException("error"));
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
|
@ -68,7 +68,7 @@ public class AuthorizationFailureEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthorizationFailureEvent(new MockMethodInvocation(),
|
new AuthorizationFailureEvent(new SimpleMethodInvocation(),
|
||||||
new ConfigAttributeDefinition(), null,
|
new ConfigAttributeDefinition(), null,
|
||||||
new AccessDeniedException("error"));
|
new AccessDeniedException("error"));
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
|
@ -77,7 +77,7 @@ public class AuthorizationFailureEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthorizationFailureEvent(new MockMethodInvocation(),
|
new AuthorizationFailureEvent(new SimpleMethodInvocation(),
|
||||||
new ConfigAttributeDefinition(),
|
new ConfigAttributeDefinition(),
|
||||||
new UsernamePasswordAuthenticationToken("foo", "bar"), null);
|
new UsernamePasswordAuthenticationToken("foo", "bar"), null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
|
|
|
@ -18,8 +18,8 @@ package org.acegisecurity.event.authorization;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +55,7 @@ public class AuthorizedEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthorizedEvent(new MockMethodInvocation(), null,
|
new AuthorizedEvent(new SimpleMethodInvocation(), null,
|
||||||
new UsernamePasswordAuthenticationToken("foo", "bar"));
|
new UsernamePasswordAuthenticationToken("foo", "bar"));
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
|
@ -63,7 +63,7 @@ public class AuthorizedEventTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new AuthorizedEvent(new MockMethodInvocation(),
|
new AuthorizedEvent(new SimpleMethodInvocation(),
|
||||||
new ConfigAttributeDefinition(), null);
|
new ConfigAttributeDefinition(), null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
|
|
|
@ -20,9 +20,9 @@ import junit.framework.TestCase;
|
||||||
import org.acegisecurity.MockAccessDecisionManager;
|
import org.acegisecurity.MockAccessDecisionManager;
|
||||||
import org.acegisecurity.MockAfterInvocationManager;
|
import org.acegisecurity.MockAfterInvocationManager;
|
||||||
import org.acegisecurity.MockAuthenticationManager;
|
import org.acegisecurity.MockAuthenticationManager;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.MockRunAsManager;
|
import org.acegisecurity.MockRunAsManager;
|
||||||
import org.acegisecurity.intercept.method.MockMethodDefinitionSource;
|
import org.acegisecurity.intercept.method.MockMethodDefinitionSource;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +60,7 @@ public class AbstractSecurityInterceptorTests extends TestCase {
|
||||||
si.setObjectDefinitionSource(new MockMethodDefinitionSource(false, true));
|
si.setObjectDefinitionSource(new MockMethodDefinitionSource(false, true));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
si.beforeInvocation(new MockMethodInvocation());
|
si.beforeInvocation(new SimpleMethodInvocation());
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
assertTrue(expected.getMessage().startsWith("Security invocation attempted for object"));
|
assertTrue(expected.getMessage().startsWith("Security invocation attempted for object"));
|
||||||
|
|
|
@ -18,9 +18,9 @@ package org.acegisecurity.intercept;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class InterceptorStatusTokenTests extends TestCase {
|
||||||
ConfigAttributeDefinition attr = new ConfigAttributeDefinition();
|
ConfigAttributeDefinition attr = new ConfigAttributeDefinition();
|
||||||
attr.addConfigAttribute(new SecurityConfig("FOO"));
|
attr.addConfigAttribute(new SecurityConfig("FOO"));
|
||||||
|
|
||||||
MethodInvocation mi = new MockMethodInvocation();
|
MethodInvocation mi = new SimpleMethodInvocation();
|
||||||
|
|
||||||
InterceptorStatusToken token = new InterceptorStatusToken(new UsernamePasswordAuthenticationToken(
|
InterceptorStatusToken token = new InterceptorStatusToken(new UsernamePasswordAuthenticationToken(
|
||||||
"marissa", "koala"), true, attr, mi);
|
"marissa", "koala"), true, attr, mi);
|
||||||
|
|
|
@ -17,7 +17,7 @@ package org.acegisecurity.intercept.method;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class AbstractMethodDefinitionSourceTests extends TestCase {
|
||||||
true);
|
true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mds.getAttributes(new MockMethodInvocation());
|
mds.getAttributes(new SimpleMethodInvocation());
|
||||||
fail("Should have thrown UnsupportedOperationException");
|
fail("Should have thrown UnsupportedOperationException");
|
||||||
} catch (UnsupportedOperationException expected) {
|
} catch (UnsupportedOperationException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
|
|
@ -22,13 +22,13 @@ import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.GrantedAuthority;
|
import org.acegisecurity.GrantedAuthority;
|
||||||
import org.acegisecurity.GrantedAuthorityImpl;
|
import org.acegisecurity.GrantedAuthorityImpl;
|
||||||
import org.acegisecurity.ITargetObject;
|
import org.acegisecurity.ITargetObject;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.OtherTargetObject;
|
import org.acegisecurity.OtherTargetObject;
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.TargetObject;
|
import org.acegisecurity.TargetObject;
|
||||||
import org.acegisecurity.acl.basic.SomeDomain;
|
import org.acegisecurity.acl.basic.SomeDomain;
|
||||||
import org.acegisecurity.context.SecurityContextHolder;
|
import org.acegisecurity.context.SecurityContextHolder;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
@ -209,7 +209,7 @@ public class MethodDefinitionAttributesTests extends TestCase {
|
||||||
MethodDefinitionAttributes source = new MethodDefinitionAttributes();
|
MethodDefinitionAttributes source = new MethodDefinitionAttributes();
|
||||||
source.setAttributes(new MockAttributes());
|
source.setAttributes(new MockAttributes());
|
||||||
|
|
||||||
ConfigAttributeDefinition config = source.getAttributes(new MockMethodInvocation() {
|
ConfigAttributeDefinition config = source.getAttributes(new SimpleMethodInvocation() {
|
||||||
public Method getMethod() {
|
public Method getMethod() {
|
||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@ import junit.framework.TestCase;
|
||||||
import org.acegisecurity.AuthorizationServiceException;
|
import org.acegisecurity.AuthorizationServiceException;
|
||||||
import org.acegisecurity.ConfigAttributeDefinition;
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.MockAclManager;
|
import org.acegisecurity.MockAclManager;
|
||||||
import org.acegisecurity.MockMethodInvocation;
|
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
import org.acegisecurity.acl.AclEntry;
|
import org.acegisecurity.acl.AclEntry;
|
||||||
import org.acegisecurity.acl.AclManager;
|
import org.acegisecurity.acl.AclManager;
|
||||||
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
import org.acegisecurity.acl.basic.MockAclObjectIdentity;
|
||||||
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.util.SimpleMethodInvocation;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||||
Class clazz = String.class;
|
Class clazz = String.class;
|
||||||
Method method = clazz.getMethod("toString", new Class[] {});
|
Method method = clazz.getMethod("toString", new Class[] {});
|
||||||
|
|
||||||
MethodInvocation mi = new MockMethodInvocation(method,
|
MethodInvocation mi = new SimpleMethodInvocation(method,
|
||||||
new Object[] {domainObject});
|
new Object[] {domainObject});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -462,7 +462,7 @@ public class BasicAclEntryVoterTests extends TestCase {
|
||||||
Method method = clazz.getMethod("someServiceMethod",
|
Method method = clazz.getMethod("someServiceMethod",
|
||||||
new Class[] {SomeDomainObject.class});
|
new Class[] {SomeDomainObject.class});
|
||||||
|
|
||||||
return new MockMethodInvocation(method, new Object[] {domainObject});
|
return new SimpleMethodInvocation(method, new Object[] {domainObject});
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Inner Classes ==========================================================
|
//~ Inner Classes ==========================================================
|
||||||
|
|
Loading…
Reference in New Issue