1.在realm中進行授權
2.使用shiro的方法註解方式權限控制
第一步:在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註解
第三步:在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>