Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc Spring security如何添加自定义角色名_Spring Mvc - Fatal编程技术网

Spring mvc Spring security如何添加自定义角色名

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

在spring security securityContext.xml中,我使用了不同的截取url模式

  <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”