Spring Expression Language and Spring Security 3: accessing bean reference in @PreAuthorize

后端 未结 3 1281
鱼传尺愫
鱼传尺愫 2020-12-16 03:12

I\'m trying to access a bean reference in a @PreAuthorize annotation as follows:

@PreAuthorize(\"@testBean.getTestValue()\")
public String testSpEL() {
    .         


        
3条回答
  •  一生所求
    2020-12-16 03:56

    For anyone stuck on Spring Security 3.0.x I have a somewhat simple workaround. Add this class in your application-securityContext.xml (or whatever):

    https://gist.github.com/3340059

    It injects a BeanFactoryResolver into the Spring Security code, which is all the Spring Security 3.1.x fix has. Support for the syntax is already in 3.0.x. It allows you to use the syntax from 3.1.x, ala:

    @PreAuthorize("@controller.theProperty")

提交回复
热议问题