在使用泛型的接口上使用带有@PreAuthorize注释的Spring ACL似乎不起作用。
EG;我有一个使用泛型的界面;
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中的一个错误,或者我们不能使用泛型并期望它们被代理。
注释的My Spring配置如下所示;
<sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
<sec:expression-handler ref="expressionHandler" />
</sec:global-method-security>
我正在使用最新的GA版本的Spring(3.2.3)和Spring Security(3.1.4)