如果用acegi acl,你什么发现在定义objectDefinitionSource时被拦截的方法参数必须与投票器定义的processDomainObjectClass一致,如果你想deleteById就会出错,所以重写了AbstractAclVoter下的getDomainObjectInstance。在这增加对deleteById的处理方法。
for (int i = 0; i < params.length; i++) {
if (processDomainObjectClass.isAssignableFrom(params[i])) {
return args[i];
}
else {
Object o;
try {
o = processDomainObjectClass.newInstance();
Method setIdMethod = processDomainObjectClass.getMethod("setId", new Class[]{Integer.class});
setIdMethod.invoke(o, new Object[]{Integer.parseInt(args[0].toString())});
return o;
} catch (InstantiationException e) {
throw new AuthorizationServiceException("不能创建'" + processDomainObjectClass + "'的实例." + e.getMessage());
} catch (IllegalAccessException e) {
throw new AuthorizationServiceException("不能创建setId方法,在实体类中必须提供setId(Integer)方法." + e.getMessage());
} catch (SecurityException e) {
throw new AuthorizationServiceException(e.getMessage());
} catch (NoSuchMethodException e) {
throw new AuthorizationServiceException("没有找到setId(Integer)方法." + e.getMessage());
} catch (IllegalArgumentException e) {
throw new AuthorizationServiceException("setId(Integer)方法参数必须为Integer类型." + e.getMessage());
} catch (InvocationTargetException e) {
throw new AuthorizationServiceException("调用setId(Integer)方法出错." + e.getMessage());
}
}
}
for (int i = 0; i < params.length; i++) {
if (processDomainObjectClass.isAssignableFrom(params[i])) {
return args[i];
}
else {
Object o;
try {
o = processDomainObjectClass.newInstance();
Method setIdMethod = processDomainObjectClass.getMethod("setId", new Class[]{Integer.class});
setIdMethod.invoke(o, new Object[]{Integer.parseInt(args[0].toString())});
return o;
} catch (InstantiationException e) {
throw new AuthorizationServiceException("不能创建'" + processDomainObjectClass + "'的实例." + e.getMessage());
} catch (IllegalAccessException e) {
throw new AuthorizationServiceException("不能创建setId方法,在实体类中必须提供setId(Integer)方法." + e.getMessage());
} catch (SecurityException e) {
throw new AuthorizationServiceException(e.getMessage());
} catch (NoSuchMethodException e) {
throw new AuthorizationServiceException("没有找到setId(Integer)方法." + e.getMessage());
} catch (IllegalArgumentException e) {
throw new AuthorizationServiceException("setId(Integer)方法参数必须为Integer类型." + e.getMessage());
} catch (InvocationTargetException e) {
throw new AuthorizationServiceException("调用setId(Integer)方法出错." + e.getMessage());
}
}
}