【发布时间】:2013-07-06 12:11:26
【问题描述】:
在使用泛型的接口上使用带有 @PreAuthorize 注释的 Spring ACL 似乎不起作用。
例如;我有一个使用泛型的接口;
public interface MyService<T> {
@PreAuthorize("hasPermission(#objectToProtect, 'WRITE')")
void doStuff(T objectToProtect, UserIdentity... user);
}
还有一个实现;
public class MyServiceImpl implements MyService<MyObject> {
@Override
public synchronized void doStuff(MyObject objectToProtect, UserIdentity... userIdentity) {
// Do some stuff here... THis should be protected, the authenticated user should have write permissions.
}
}
我可以看到PrePostAnnotationSecurityMetadataSource 正在获取实现上的注释,但是它看起来在 AOP 传递中迷失了,并且在调用 acutal 方法时它从未使用过。如果我将注释添加到具体实现中(即在 MyServiceImpl 中的 doStuff 方法上),它会起作用。
如果我不在我的界面中使用泛型并使用Object 之类的东西,它似乎也可以正常工作。这是 Spring/Spring Security ACL 中的一个错误,还是我们可以不使用泛型并期望它们被代理。
我的注解的 Spring 配置如下所示;
<sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
<sec:expression-handler ref="expressionHandler" />
</sec:global-method-security>
我正在使用 Spring (3.2.3) 和 Spring Security (3.1.4) 的最新 GA 版本
【问题讨论】:
标签: java spring generics spring-security acl