一、方法注解权限控制
第一步:在spring配置文件中开启shiro注解支持
<!-- 开启shiro框架注解支持 -->
<bean id=\"defaultAdvisorAutoProxyCreator\"
class=\"org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator\">
<!-- 必须使用cglib方式为Action对象创建代理对象 -->
<property name=\"proxyTargetClass\" value=\"true\"/>
</bean>
<!-- 配置shiro框架提供的切面类,用于创建代理对象 -->
<bean class=\"org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor\"/>
第二步:在Action的方法上使用shiro注解
/**
* 取派员批量删除
*/
@RequiresPermissions(\"staff-delete\")//执行这个方法,需要当前用户具有staff-delete这个权限
public String deleteBatch(){
staffService.deleteBatch(ids);
return LIST;
}
第三步:在struts.xml中配置全局异常捕获,当shiro框架抛出权限不足异常时,跳转到权限不足提示页面
<!-- 全局结果集定义 -->
<global-results>
<result name=\"login\">/login.jsp</result>
<result name=\"unauthorized\">/unauthorized.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result=\"unauthorized\"
exception=\"org.apache.shiro.authz.UnauthorizedException\"></exception-mapping>
</global-exception-mappings>
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。

