Shiro注解

点点圈 提交于 2020-02-01 22:21:45

@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...";
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!