码迷,mamicode.com
首页 > Web开发 > 详细

jsp的权限控制思路

时间:2015-12-21 10:31:55      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:

这两天接触的一个项目的权限控制思路,控制页面权限、action权限、页面内容权限

1用户

2角色

3权限组

4权限

5菜单

权限控制的5个基本模块: 

  • 用户: 用户与角色关联
  • 角色: 角色与权限关联
    •   给角色赋予权限:将所有权限列出:
      • 技术分享

         技术分享

  • 权限组:用于归类权限
  • 权限:
    • 权限可以是一个菜单(当权限的url和菜单的url相同时即为菜单权限)
      • 获取菜单列表时根据权限过滤菜单:
      •   if (menuUrl.equals(auth.getUrl()) || (user!=null && user.getId().equals(1L))) { //或者为超级用户的话也显示
        			menuJson.setIsHidden(false);// 有权限,显示
    • 也可以为页面内容权限(当权限的url为”#***“的标识为功能权限,使用自”定义标签控制“页面内容权限的显示隐藏)
      •   JSP页面:
        1 <auth:showhtml url="#hpgg">
        2         <%--自定义标签..需要根据权限显示隐藏的内容--%>
        3 </auth:showhtml>
    • 也可以是action权限(将每一个action都加到权限中,使用struts的拦截器判断action是否有url权限)
      •   配置拦截器:
      • <interceptor name="authInterceptor" class="*************.AuthInterceptor" />    
      • 拦截器代码:

      • 技术分享
         1 @SuppressWarnings("serial")
         2 public class AuthInterceptor extends MethodFilterInterceptor {
         3 
         4     @SuppressWarnings("unchecked")
         5     @Override
         6     protected String doIntercept(ActionInvocation invocation) throws Exception {
         7         String url = invocation.getProxy().getActionName().trim() + "!"
         8                 + invocation.getProxy().getMethod().trim();
         9 
        10         Map map = invocation.getInvocationContext().getSession();
        11 
        12         User_info user = (User_info) map.get("user");
        13 
        14         boolean i = false;
        15         Set<Role> roles = user.getRoles();
        16         if (roles == null || roles.size() == 0) { // 无角色不能访问
        17 
        18             return "noAuth";
        19         }
        20 
        21         for (Role role : roles) {
        22 
        23             for (Auth auth : role.getAuths()) {
        24                 if (url.equals(auth.getUrl())) {
        25                     i = true;
        26                     break;
        27                 }
        28             }
        29             if (i == true) {
        30                 break;
        31             }
        32 
        33         }
        34 
        35         if (i) {
        36             return invocation.invoke();
        37         } else {
        38             return "noAuth";
        39         }
        40 
        41     }
        42 
        43 }
        View Code

         

      •   权限列表:
    • 技术分享

jsp的权限控制思路

标签:

原文地址:http://www.cnblogs.com/xulisha123/p/java.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!