Java tutorial
/** * Copyright (c) 2005-2009 springside.org.cn * * Licensed under the Apache License, Version 2.0 (the "License"); * * $Id: DefinitionSourceFactoryBean.java,v 1.1 2009/09/22 00:55:47 test Exp $ */ package com.xyz.system.service.impl; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.SecurityConfig; import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource; import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; import org.springframework.security.web.access.intercept.RequestKey; import org.springframework.security.web.util.AntUrlPathMatcher; import org.springframework.security.web.util.UrlMatcher; import org.springframework.stereotype.Service; import com.xyz.system.service.ISecurityService; /** * DefinitionSource. * resourceDetailService??URL-?, * ??LinkedHashMap<String, String>?URL?? * SpringSecurityLinkedHashMap<RequestKey, ConfigAttributeDefinition>?. * ?-?? * @see org.springframework.security.intercept.web.DefaultFilterInvocationDefinitionSource * @see ResourceDetailService * * @author Val */ @Service("databaseDefinitionSource") public class DefinitionSourceFactoryBean implements FactoryBean { @Autowired private ISecurityService securityManager; /** * Ant StyleURLMatcherResourceDetailService??RequestMapDefaultFilterInvocationDefinitionSource. */ public Object getObject() throws Exception { LinkedHashMap<RequestKey, Collection<ConfigAttribute>> requestMap = buildRequestMap(); UrlMatcher matcher = getUrlMatcher(); DefaultFilterInvocationSecurityMetadataSource metaSource = new DefaultFilterInvocationSecurityMetadataSource( matcher, requestMap); ; return metaSource; } @SuppressWarnings("unchecked") public Class getObjectType() { return FilterInvocationSecurityMetadataSource.class; } public boolean isSingleton() { return true; } /** * ??Ant StyleURLMatcher. */ protected UrlMatcher getUrlMatcher() { return new AntUrlPathMatcher(); } /** * resourceDetailService??LinkedHashMap<String, String>?URL?? * DefaultFilterInvocationDefinitionSource?LinkedHashMap<RequestKey, ConfigAttributeDefinition>?. */ protected LinkedHashMap<RequestKey, Collection<ConfigAttribute>> buildRequestMap() throws Exception { LinkedHashMap<String, String> srcMap = securityManager.getRequestMap(); LinkedHashMap<RequestKey, Collection<ConfigAttribute>> distMap = new LinkedHashMap<RequestKey, Collection<ConfigAttribute>>(); for (Map.Entry<String, String> entry : srcMap.entrySet()) { RequestKey key = new RequestKey(entry.getKey(), null); if (StringUtils.isNotBlank(entry.getValue())) { distMap.put(key, SecurityConfig.createListFromCommaDelimitedString(entry.getValue())); } } return distMap; } }