I came up with the following. I'm not sure it is the best implementation but it works for me. ClassUtils refers to the code i referenced above.
Code:
/**
* This method is a copy of getDomainObjectInstance in AbstractAclVoter. It calls out
* to ClassUtils in order to be able to determine the type of generic type arguments.
* @param secureObject the object to determine the type of
* @return the domain object instance
*/
@SuppressWarnings("unchecked")
public Object getGenericDomainObjectInstance(Object secureObject) {
Object[] args;
Class[] params;
if (secureObject instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) secureObject;
params = invocation.getMethod().getParameterTypes();
args = invocation.getArguments();
} else {
JoinPoint jp = (JoinPoint) secureObject;
params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes();
args = jp.getArgs();
}
for (int i = 0; i < params.length; i++) {
Class actualObjectType = ClassUtils.getClass(args[i].getClass());
if (getProcessDomainObjectClass().isAssignableFrom(actualObjectType)) {
return args[i];
}
}
throw new AuthorizationServiceException("Secure object: " + secureObject
+ " did not provide any argument of type: " + getProcessDomainObjectClass());
}