您的位置:首页 > 编程语言 > Java开发

(转)实现struts2的CRUD中的权限控制(一)

2008-01-28 09:16 441 查看
继上篇《struts2的CRUD中的权限控制初探 》文章后,我们来实现具体的代码实现,在struts2中我们可以自定义拦截器。

心中谨记基于接口编程的指导,考虑到我们的CRUD操作涉及到load,store,remove,list四个方法,而且要记录操作者的角色,我们提取了接口IRoleAndCRUD,内容如下:

<package name="admin" extends="struts-default" namespace="/admin">

<!-- 定义拦截器 -->

<interceptors>

<interceptor name ="auth" class ="com.waimai.utils.AuthorizationInterceptor" />

</interceptors >

<action name="List" class="com.waimai.web.CaiTypeAction" method="list">

<!-- 调用拦截器 -->

<interceptor-ref name ="auth"/>

<result>listCaiType.jsp</result>

</action>

<action name="Edit" class="com.waimai.web.CaiTypeAction" method="load">

<!-- 调用拦截器 -->

<interceptor-ref name ="auth"/>

<result>editCaiType.jsp</result>

</action>

<action name="Store" class="com.waimai.web.CaiTypeAction" method="store">

<!-- 调用拦截器 -->

<interceptor-ref name ="auth"/>

<result name="input" type="dispatcher">editCaiType.jsp</result>

<result type="redirect">List.action</result>

</action>

<action name="Remove" class="com.waimai.web.CaiTypeAction" method="remove">

<!-- 调用拦截器 -->

<interceptor-ref name ="auth"/>

<result type="redirect">List.action</result>

</action>

</package>

这样在调用这些定义了拦截器的action时都会检查用户权限。在我们的系统中,我们的crud相关的action的继承关系如下:具体action继承于AbstractCRUDAction实现IRoleAndCRUD接口,但是所有的需要权限控制的action方法都要在配制文件中加入<interceptor-ref name ="auth"/> 这么一行,真是很不爽呀,不知道能不能给接口设置拦截器,由于自己对struts2还不是很了解,查了一些资料没有好的解决方案,如果谁有好的解决方案请告知我。感觉要做到伸缩性强,维护性强的权限系统还是需要使用acegi集成进系统....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: