@RequiresRoles和@RequiresPermissions
第一步:引入依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
第二步:SpringMVC开启aop,加入授权生效的对象
<aop:config proxy-target-class="true" />
<bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor" >
<property name="securityManager" ref="securityManager" />
</bean>
第三步:测试
@RequiresRoles("admin")
@RequestMapping(path="/test", method = RequestMethod.GET)
@ResponseBody
public String test(){
return "test success...";
}
@RequiresRoles("admin1")
@RequestMapping(path="/test2", method = RequestMethod.GET)
@ResponseBody
public String test1(){
return "test2 success...";
}
@RequiresPermissions(value = {"user:select"})
@RequestMapping(path="/test3", method = RequestMethod.GET)
@ResponseBody
public String test1(){
return "test3 success...";
}
来源:CSDN
作者:lmchhh
链接:https://blog.csdn.net/lmchhh/article/details/104134750