| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.intercept.method; |
| 17 |
|
|
| 18 |
|
import org.acegisecurity.ConfigAttributeDefinition; |
| 19 |
|
|
| 20 |
|
import org.aopalliance.intercept.MethodInvocation; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.logging.Log; |
| 23 |
|
import org.apache.commons.logging.LogFactory; |
| 24 |
|
|
| 25 |
|
import org.aspectj.lang.JoinPoint; |
| 26 |
|
import org.aspectj.lang.reflect.CodeSignature; |
| 27 |
|
|
| 28 |
|
import org.springframework.util.Assert; |
| 29 |
|
|
| 30 |
|
import java.lang.reflect.Method; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
55 |
public abstract class AbstractMethodDefinitionSource implements MethodDefinitionSource { |
| 40 |
|
|
| 41 |
|
|
| 42 |
4 |
private static final Log logger = LogFactory.getLog(AbstractMethodDefinitionSource.class); |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
public ConfigAttributeDefinition getAttributes(Object object) |
| 47 |
|
throws IllegalArgumentException { |
| 48 |
59 |
Assert.notNull(object, "Object cannot be null"); |
| 49 |
|
|
| 50 |
59 |
if (object instanceof MethodInvocation) { |
| 51 |
56 |
return this.lookupAttributes(((MethodInvocation) object).getMethod()); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
3 |
if (object instanceof JoinPoint) { |
| 55 |
3 |
JoinPoint jp = (JoinPoint) object; |
| 56 |
3 |
Class targetClazz = jp.getTarget().getClass(); |
| 57 |
3 |
String targetMethodName = jp.getStaticPart().getSignature().getName(); |
| 58 |
3 |
Class[] types = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes(); |
| 59 |
|
|
| 60 |
3 |
if (logger.isDebugEnabled()) { |
| 61 |
0 |
logger.debug("Target Class: " + targetClazz); |
| 62 |
0 |
logger.debug("Target Method Name: " + targetMethodName); |
| 63 |
|
|
| 64 |
0 |
for (int i = 0; i < types.length; i++) { |
| 65 |
0 |
if (logger.isDebugEnabled()) { |
| 66 |
0 |
logger.debug("Target Method Arg #" + i + ": " + types[i]); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
try { |
| 72 |
3 |
return this.lookupAttributes(targetClazz.getMethod(targetMethodName, types)); |
| 73 |
0 |
} catch (NoSuchMethodException nsme) { |
| 74 |
0 |
throw new IllegalArgumentException("Could not obtain target method from JoinPoint: " + jp); |
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
|
| 78 |
0 |
throw new IllegalArgumentException("Object must be a MethodInvocation or JoinPoint"); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
protected abstract ConfigAttributeDefinition lookupAttributes(Method method); |
| 92 |
|
|
| 93 |
|
public boolean supports(Class clazz) { |
| 94 |
24 |
return (MethodInvocation.class.isAssignableFrom(clazz) || JoinPoint.class.isAssignableFrom(clazz)); |
| 95 |
|
} |
| 96 |
|
} |