2006-12-08

Spring框架下实现基于组的用户权限管理

来源: 本站收集整理 作者:佚名 评论 0 条
 
    mav.addObject("errorMsg", "授权失败! 你不在 <b>" group "</b> 组!");
    throw new ModelAndViewDefiningException(mav);
   } return true;
  }
 }
 /* * 查看
 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.lookupHandler()
 * Ant模式的最长子串匹配法.
 */
 private String lookupGroup(String url){
  String group = groupMappings.getProperty(url);
  if (group == null) {
   String bestPathMatch = null;
   for (Iterator it = this.groupMappings.keySet().iterator();it.hasNext();) {
    String registeredPath = (String) it.next();
    if (this.pathMatcher.match(registeredPath, url) && (bestPathMatch == null || bestPathMatch.length() <= registeredPath.length())) {
     group = this.groupMappings.getProperty(registeredPath);
     bestPathMatch = registeredPath;
    }
   }
  }
  return group;
 }
}

  下面我们需要在Spring的应用上下文配置文件中设置:

<bean id="authorizeInterceptor" class="net.ideawu.AuthorizeInterceptor">
 <property name="groupMappings">
  <value>
   <!-- Attach URL paths to group -->
    /admin/*=admin
  </value>
 </property>
</bean>
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 <property name="interceptors">
  <list>
  <ref bean="authorizeInterceptor" /> </list>
 </property>
 <property name="mappings">
  <value>
   /index.do=indexController /browse.do=browseController /admin/removeArticle.do=removeArticleController
  </value>
 </property>
</bean>

  注重到"/admin/*=admin", 所以/admin目录下的所有资源只有在admin组的用户才能访问, 这样就不用担心普通访客删除文章了。使用这种方法, 你不需要在removeArticleController中作身份验证和权限治理, 一切都交给AuthorizeInterceptor。
共2页: 上一页 [1] 2 下一页
(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:C#中使用存储过程中的返回值  
下一篇:C#实现类似qq的屏幕截图程序
    评论加载中…
 热门排行
 推荐文章
     

 相关文章
网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号