Spring Security3.0升级至3.2.4版本注意事项

引用:http://www.blogjava.net/SpartaYew/archive/2011/06/15/350630.html

根据《Spring Security3十五日研究》进行配置Spring Security实现用户-角色-权限-资源四层管理,文中采用的版本是3.0版本,升级到3.2.4版本时需要注意如下:

1、配置文件修改,样式改为http://www.springframework.org/schema/security/spring-security-3.2.xsd

2、代码修改,在3.2.4版本中没有UrlMatcher和AntUrlPathMatcher,自定义类MyInvocationSecurityMetadataSourceService需要使用RequestMatcher和AntPathRequestMatcher作为替代。

原代码:

String url = ((FilterInvocation) object).getRequestUrl();
  
        int firstQuestionMarkIndex = url.indexOf("?");

        if (firstQuestionMarkIndex != -1) {
            url = url.substring(0, firstQuestionMarkIndex);
        }

  Iterator<String> ite = resourceMap.keySet().iterator();

  while (ite.hasNext()) {
   String resURL = ite.next();
   
   if (urlMatcher.pathMatchesUrl(url, resURL)) {

    return resourceMap.get(resURL);

修改后:

FilterInvocation fi = ((FilterInvocation) object);
		Iterator<String> ite = resourceMap.keySet().iterator();
		while (ite.hasNext()) {
			   String resURL = ite.next();
			   RequestMatcher requestMatcher = new AntPathRequestMatcher(resURL);
			   if(requestMatcher.matches(fi.getHttpRequest()))
			   {
				   return resourceMap.get(resURL);
			   }
		}





暂未遇到其他问题,我的版本为spring 4.0.6+hibernate4.3.6+spring security 3.2.4


你可能感兴趣的:(spring,升级,3.2.4,Security3.0)