Spring Security使用通配符授权访问角色

bee*_*alo 3 spring-security

是否可以在<sec:authorize />标签的access属性中使用通配符.

目前我有 <sec:authorize access="hasRole('TICKET_VIEW') or hasRole('TICKET_EDIT')">

但我希望能够使用 <sec:authorize access="hasRole('TICKET_*')">

这是可能的,还是有人知道一个可以完成同样事情的解决方案?

谢谢

Jay*_*kov 6

从Spring 3.x开始,它可以在Spring EL中运行.你正在寻找的表达方式是hasAnyRole(..).

所以看起来应该是这样的:

<sec:authorize access="hasAnyRole('TICKET_VIEW', 'TICKET_EDIT')">
    ...
</sec:authorize>
Run Code Online (Sandbox Code Playgroud)

这里有一些Spring EL表达式的链接:http: //static.springsource.org/spring-security/site/docs/3.0.x/reference/el-access.html