@requirespermissions 无效问题原因

给角色赋予了权限,放在Controller里无效

@RequestMapping(value = "/save",method = RequestMethod.GET)
@RequiresPermissions("test:save")
public String toSave(){
    return "/test/add";
}

但是,放在service里有效,会提示报,没有权限错误

org.apache.shiro.authz.UnauthorizedException: Subject does not have permission [test:save]

产生原因是因为拦截在 spring 容器中,而不是拦截在springMVC容器中,所以才会注解无效。

要在 springMVC 的配置文件里最上方进进行配置

注意:

不要在spring的配置里面进行配置

不要在spring的配置里面进行配置

不要在spring的配置里面进行配置

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
      depends-on="lifecycleBeanPostProcessor" />
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
    <property name="securityManager" ref="securityManager" />
</bean>

猜你喜欢

转载自my.oschina.net/lwbldy/blog/1634644