(转)实现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集成进系统....
心中谨记基于接口编程的指导,考虑到我们的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集成进系统....
相关文章推荐
- 实现struts2的CRUD中的权限控制(二)
- 实现struts2的CRUD中的权限控制(一)
- (转)实现struts2的CRUD中的权限控制(二)
- 实现struts2的CRUD中的权限控制(一)
- struts2 实现权限控制拦截器
- Struts2实现登录权限访问控制
- struts2的CRUD中的权限控制初探
- struts2的CRUD中的权限控制初探(转)
- 利用struts2拦截器加自定义注解实现权限控制
- 6、Struts2拦截器实现权限控制
- struts2中用interceptor实现权限控制
- struts2 使用注解、反射、拦截器实现基于方法的权限控制
- Struts2拦截器 实现未登录拦截和权限控制
- Struts2拦截器实现细颗粒权限控制
- 自定义注解+Struts2拦截器实现简单权限控制
- struts2中用interceptor实现权限控制
- Struts2拦截器 实现未登录拦截和权限控制
- 通过继承Struts2标签,实现页面元素的显示权限控制
- [转载]Struts2拦截器 实现未登录拦截和权限控制
- struts2通过拦截器,实现权限控制功能