Spring security @PreAuthorize hasRole() properties injection

后端 未结 3 1730
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 15:49

Assuming that my Spring Security and properties are configured properly, I would like to use role name from property like

@PreAuthorize(\"hasRole(\'${role.ro         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 16:22

    I've found that you can just grab the propertyResolver and pull values directly from that, instead of writing your own class as was suggested by @Maksym.

    Exammple:

    @PreAuthorize("hasRole(@environment.getProperty('role.rolename')")
    public void method() {}
    

提交回复
热议问题