用Hibernate 实现 FilterInvocationDefinitionSource(Acegi)

整个工程在附件中,去掉了lib 目录,需要的jar包在jar.jpg。带有数据脚本,还有好多去完善,有空会更新
下面的代码缓存好像没有起作用。以后在调试,如果那位调试缓存起作用,请回复
[code]public class RdbmsFilterInvocationDefinitionSource extends AbstractFilterInvocationDefinitionSource
implements InitializingBean {
protected static final Log logger = LogFactory.getLog(RdbmsFilterInvocationDefinitionSource.class);
public BaseDao baseDao;
private Cache webresdbCache;
private PathMatcher pathMatcher = new AntPathMatcher();
public void afterPropertiesSet() throws Exception {
Assert.notNull(baseDao,"baseDao : 不能为空");
}

@Override
public ConfigAttributeDefinition lookupAttributes(String url) {
Map map = this.getConfigAttributeDefinitionMap();
if (map == null || map.size() == 0)
return null;

int firstQuestionMarkIndex = url.indexOf("?");
if (firstQuestionMarkIndex != -1) {
url = url.substring(0, firstQuestionMarkIndex);
}
Iterator iterator = map.keySet().iterator();
String key = null;
while(iterator.hasNext())
{
key = (String)iterator.next();
boolean matched = pathMatcher.match(key, url);
if (logger.isDebugEnabled()) {
logger.debug("匹配到如下URL: '" + url + ";模式为 " + key + ";是否被匹配:" + matched);
}

if (matched) {
return (ConfigAttributeDefinition)map.get(url);
}
}
return null;
}

public Iterator getConfigAttributeDefinitions() {
Set set = new HashSet();
Map map = getConfigAttributeDefinitionMap();
Iterator iterator = map.keySet().iterator();
String url = null;
while(iterator.hasNext())
{
url = (String)iterator.next();
set.add(map.get(url));
}
return set.iterator();
}

//可以缓存这个方法。减少访问数据库
private Map getConfigAttributeDefinitionMap()
{
Element element = this.webresdbCache.get("webres");
Map map = new HashMap<String,ConfigAttributeDefinition>();
List weburlList = baseDao.findAll(Weburl.class);
Role role = null;
WeburlRole weburlRole =null;
String url = null;
if(element != null){
return (Map)element.getValue();
}
for(int i = 0; i < weburlList.size(); ++i)
{
url = ((Weburl)weburlList.get(i)).getUrl();
ConfigAttributeDefinition cad = new ConfigAttributeDefinition();
Set weburl = ((Weburl)weburlList.get(i)).getWeburlRole();
Iterator roleSet = weburl.iterator();
while(roleSet.hasNext())
{
weburlRole = (WeburlRole)roleSet.next();
role = weburlRole.getRole();
cad.addConfigAttribute(new SecurityConfig(role.getRoleName()));
}
map.put(url, cad);
}
Element elem = new Element("webres", map);
this.webresdbCache.put(elem);
return map;
}

public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseDao;
}

public void setWebresdbCache(Cache webresdbCache) {
this.webresdbCache = webresdbCache;
}
}
[/code]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值