Spring mvc Spring security如何添加自定义角色名
在spring security securityContext.xml中,我使用了不同的截取url模式Spring mvc Spring security如何添加自定义角色名,spring-mvc,Spring Mvc,在spring security securityContext.xml中,我使用了不同的截取url模式 <intercept-url pattern="/mod1/*" access="hasRole('Mod1_*)" /> <intercept-url pattern="/mod2/*" access="hasRole('Mod2_*)/> 如果您有以下多个角色,请尝试使用hasAnyRole([role1,role2..]) <intercept
<intercept-url pattern="/mod1/*" access="hasRole('Mod1_*)" />
<intercept-url pattern="/mod2/*" access="hasRole('Mod2_*)/>
如果您有以下多个角色,请尝试使用hasAnyRole([role1,role2..])
<intercept-url pattern="/mod1/*" access="hasAnyRole('Mod1_role1,mod1_role2)" />
下面是表达式的定义
hasRole([role])->如果当前主体具有指定的角色,则返回true。
hasAnyRole([role1,role2])->如果当前主体具有任何提供的角色(以逗号分隔的字符串列表形式给出),则返回true谢谢你的评论,但我有很多角色都是从Mod1开始的,所以我正在寻找RolePrefix或RoleVoter,但我不知道怎么做。有人能帮我找到一个解决方案吗..重新表述问题:Spring security应该只允许“Mod1”用户访问“/Mod1”url,而“/mod2”角色的用户可以访问“/mod2”