I would like to be able to initialize the FilterChainProxy
entirely using Spring XML tags, without relying on the special
syntax parsed by the ACEGI property editors.  I have various
reasons for this, one being that the Spring IDE and the XML
parser do not understand the bean names in the special syntax
as bean refs.   Figure 1 below is what I have in mind.

In order to get this to work, I had to create three classes:

1. A BeanRefConfigAttribute (implements org.acegisecurity.ConfigAttribute)
See Figure 4.

2. A  BeanRefFilterInvocationDefinitionDecorator (extends 
FilterInvocationDefinitionDecorator)
overrides the setMappings(List) method to create BeanRefConfigAttributes rather
than acegisecurity.SecurityConfig attributes.   See Figure 2.

3. A BeanRefFilterChainProxy (extends FilterChainProxy).
The only change necessary was to override
obtainAllDefinedFilters(ConfigAttributeDefinition configAttributeDefinition)
to get the beans out of the BeanRefConfigAttributes.  See Figure 3.
Unfortunately, this method is private

Questions:

1. Could the method obtainAllDefinedFilters be made protected?
This is a natural extension point for anyone wishing to implement
a new type of ConfigAttribute

2. Would the ACEGI developers consider adding the attached
code to the framework, for users who prefer the XML style of
initialization versus the property editor style?

-Robert Blumen

=========================================================================================
Figure 1: filter-chain.xml config file
=========
  <bean id="filterChainProxy"
        class="com.foo.web.security.servlet.filter.BeanRefFilterChainProxy">
    <property name="filterInvocationDefinitionSource">
      <bean 
class="com.foo.web.security.servlet.filter.BeanRefFilterInvocationDefinitionDecorator">

        <property name="decorated">
          <bean 
class="org.acegisecurity.intercept.web.PathBasedFilterInvocationDefinitionMap"/>
        </property>

        <property 
name="convertUrlToLowercaseBeforeComparison"><value>true</value></property>
        <property name="mappings">
          <list>
            <bean 
class="org.acegisecurity.intercept.web.FilterInvocationDefinitionSourceMapping">
              <property name="url"><value>/**</value></property>
              <property name="configAttributes">
                <list>
                  <ref bean="httpSessionContextIntegrationFilter"/>
                  <ref bean="logoutFilter"/>
                  <ref bean="authenticationProcessingFilter"/>
                  <ref bean="requestIntegrityFilter"/>
                  <ref bean="securityContextHolderAwareRequestFilter"/>
                  <ref bean="anonymousProcessingFilter"/>
                  <ref bean="switchUserProcessingFilter"/>
                  <ref bean="exceptionTranslationFilter"/>
                  <ref bean="filterInvocationInterceptor"/>
                </list>
              </property>
            </bean>
          </list>
        </property>
      </bean>
    </property>
  </bean>corator
3.


=========================================================================================
Figure 2: BeanRefFilterInvocationDefinitionDecorator
=========
   public void setMappings(List mappings) {

        if (getDecorated() == null) {
            throw new IllegalStateException("decorated object has not been 
set");
        }
        this.mappings = mappings;
        for (FilterInvocationDefinitionSourceMapping mapping : this.mappings) {
            ConfigAttributeDefinition configDefinition = new 
ConfigAttributeDefinition();

            // compare this to the ACEGI code: create a BeanRef here.
            for (Object bean : mapping.getConfigAttributes()) {
                configDefinition.addConfigAttribute(new 
BeanRefConfigAttribute(bean));
            }
            getDecorated().addSecureUrl(mapping.getUrl(), configDefinition);
        }
    }


=========================================================================================
Figure 3: BeanRefFilterChainProxy
=========

    protected Filter[] obtainAllDefinedFilters(ConfigAttributeDefinition 
configAttributeDefinition) {
        List list = new ArrayList();
        Iterator attributes = configAttributeDefinition.getConfigAttributes();

        while (attributes.hasNext()) {
            BeanRefConfigAttribute attr = (BeanRefConfigAttribute) 
attributes.next();
            Object bean = attr.getBean();
            list.add(bean);
        }
        return (Filter[]) list.toArray(new Filter[list.size()]);
    }

=========================================================================================
Figure 3: BeanRefFilterChainProxy
=========

public class BeanRefConfigAttribute implements ConfigAttribute {
    private Object bean;

    /**
     * @return null, indicating that the ConfigAttribute has more than
     * a name.
     */
    public String getAttribute() {
        return null;
    }

    /**
     * @return the Spring bean for this attribute
     */
    public Object getBean() {
        return this.bean;
    }

    /**
     * Constructor.
     * @param bean
     */
    public BeanRefConfigAttribute(Object bean) {
        this.bean = bean;
    }
}




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Home: http://acegisecurity.org
Acegisecurity-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/acegisecurity-developer

Reply via email to