@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...";
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/81652.html