Hi,

Seems like a lot of people have been looking for ways to set a list property on a bean based on the values in external file. I would have thought that Spring would provide a simple utility for this but after a lot of searching nothing seems to fit to bill. So here's my shot.

Code:
public class ResourceListFactoryBean extends ListFactoryBean
{

    public ResourceListFactoryBean()
    {
        super();
    }

    public void setResource(Resource resource) throws IOException
    {
        Scanner scanner = new Scanner(resource.getInputStream());
        try
        {
            List<String> source = new ArrayList<String>();
            while (scanner.hasNextLine())
            {
                source.add(scanner.nextLine());
            }
            super.setSourceList(source);
        }

        finally
        {
            scanner.close();
        }
    }
}
this is how I use it to provide a set of userDnPatterns to spring security ladp BindAuthenicator

Code:
<bean id="dnPatterns" class="util.ResourceListFactoryBean">
    <property name="resource" value="classpath:ldap.properties" />
</bean>

....snip
<bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator">
    <constructor-arg ref="contextSource" />
    <property name="userDnPatterns" ref="dnPatterns" /> 
....snip
and heres the resouce file (ldap.properties) entries

Code:
cn={0},ou=people
uid={0},ou=people,dc=test
Simple!

Conor.