/**
* <class>RdbmsBasedFilterInvocationDefinitionSource</class> 是基于数据库的权限存储实现, 它支持两种风格的配置
* @see com.skyon.uum.security.acegi.intercept.web.ConfigableFilterInvocationDefinition
* @see org.acegisecurity.intercept.web.RegExpBasedFilterInvocationDefinitionMap
* @see org.acegisecurity.intercept.web.PathBasedFilterInvocationDefinitionMap
* @since 2006-1-19
* @author 王政
* @version $Id: RdbmsBasedFilterInvocationDefinitionSource.java,v 1.6 2006/02/13 03:20:55 wz Exp $
*/
public
class RdbmsBasedFilterInvocationDefinitionSource extends AbstractFilterInvocationDefinitionSource
implements ConfigableFilterInvocationDefinition, InitializingBean {
//~ Static fields/initializers =============================================
privatestaticfinal Log logger = LogFactory.getLog(RdbmsBasedFilterInvocationDefinitionSource.class);
// ~ Instance fields ========================================================
privateString resourceExpression = PERL5_KEY;
privateboolean convertUrlToLowercaseBeforeComparison = false;
private ResourceMappingProvider resourceMappingProvider;
// ~ Methods ================================================================
/**
*
* @see org.acegisecurity.intercept.web.AbstractFilterInvocationDefinitionSource#lookupAttributes(java.lang.String)
*/
public ConfigAttributeDefinition lookupAttributes(String url){
FilterInvocationDefinitionSource actualSource = populateFilterInvocationDefinitionSource();
if(RegExpBasedFilterInvocationDefinitionMap.class.isInstance(actualSource)){
return((RegExpBasedFilterInvocationDefinitionMap) actualSource).lookupAttributes(url);
}elseif(PathBasedFilterInvocationDefinitionMap.class.isInstance(actualSource)){
return((PathBasedFilterInvocationDefinitionMap) actualSource).lookupAttributes(url);
}
throw newIllegalStateException("wrong type of " + actualSource + ", it should be " + RegExpBasedFilterInvocationDefinitionMap.class
+ " or " + PathBasedFilterInvocationDefinitionMap.class);
}
/**
*
* @see org.acegisecurity.intercept.ObjectDefinitionSource#getConfigAttributeDefinitions()
*/
publicIterator getConfigAttributeDefinitions(){
FilterInvocationDefinitionSource actualSource = populateFilterInvocationDefinitionSource();
if(RegExpBasedFilterInvocationDefinitionMap.class.isInstance(actualSource)){
return((RegExpBasedFilterInvocationDefinitionMap) actualSource).getConfigAttributeDefinitions();
}elseif(PathBasedFilterInvocationDefinitionMap.class.isInstance(actualSource)){
return((PathBasedFilterInvocationDefinitionMap) actualSource).getConfigAttributeDefinitions();
}
throw newIllegalStateException("wrong type of " + actualSource + ", it should be " + RegExpBasedFilterInvocationDefinitionMap.class
+ " or " + PathBasedFilterInvocationDefinitionMap.class);
}
private FilterInvocationDefinitionSource populateFilterInvocationDefinitionSource(){
FilterInvocationDefinitionMap definitionSource = null;
if(PERL5_KEY.equals(getResourceExpression())){
definitionSource = new RegExpBasedFilterInvocationDefinitionMap();
}elseif(ANT_PATH_KEY.equals(getResourceExpression())){
definitionSource = new PathBasedFilterInvocationDefinitionMap();
}else{
throw newIllegalArgumentException("wrong resourceExpression value");
}
definitionSource.setConvertUrlToLowercaseBeforeComparison(isConvertUrlToLowercaseBeforeComparison());
ResourceMapping[] mappings = getResourceMappingProvider().getResourceMappings();
if(mappings == null || mappings.length ==0){
return(FilterInvocationDefinitionSource) definitionSource;
}
for(int i = 0; i < mappings.length; i++){
ResourceMapping mapping = mappings[i];
String[] recipents = mapping.getRecipients();
if(recipents == null || recipents.length == 0){
if(logger.isErrorEnabled()){
logger.error("Notice, the resource : " + mapping.getResourcePath() + " hasn't no recipents, it will access by any one ! ");
}
continue;
}
StringBuffer valueBuffer = new StringBuffer();
for (int j = 0; j < recipents.length; j++) {
valueBuffer.append(recipents[j]);
if (j < recipents.length - 1) {
valueBuffer.append(STAND_DELIM_CHARACTER);
}
}
String value = valueBuffer.toString();
addSecureUrl(definitionSource, mapping.getResourcePath(), value);
}
return (FilterInvocationDefinitionSource )definitionSource;
}
/**
* @param source
* @param name
* @param value
* @throws IllegalArgumentException
*/
private synchronized void addSecureUrl(FilterInvocationDefinitionMap source, String name, String value)
throws IllegalArgumentException {
// Convert value to series of security configuration attributes
ConfigAttributeEditor configAttribEd = new ConfigAttributeEditor();
configAttribEd.setAsText(value);
ConfigAttributeDefinition attr = (ConfigAttributeDefinition) configAttribEd.getValue();
// Register the regular expression and its attribute
source.addSecureUrl(name, attr);
}
省去 getter, setter....
}
|