1
votes

We are using spring security & using LDAP to authenticate our web application. In our LDAP configuration, there are multiple userndn patterns available. I would like to know how to configure multiple userdn patterns in the applicationContext-security.xml file. I have the below configuration specified

<b:bean id="ldapProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean
            class="com.intl.set.him.mait.security.CustomLdapAuthenticator">
            <b:constructor-arg ref="ldapContextSource" />
            <b:property name="userDnPatterns" value="cn={0},OU=GEN,OU=Users"/>
            <b:property name= "commonNameQuery" value = "select USER_CN from emt.sec_users1 where user_id=?"/>
            <b:property name="datasource" ref="dataSourceMSSQL"/>  

</b:bean>

When I provide the above configuration in the xml file, users corresponding to Dn pattern for a particular location will only be able to login. I want to know how we can configure multiple userdn patterns in the xml file.

Any help on this is much appreciated. Thanks

1
Do not publish the internal info on he Web!!! - Michael

1 Answers

0
votes

The bean acts as a constructor (often with arguments and/or properties) for the specified class. If you simply extend that class in your own subclass, you can pass arguments to the supoerclass' constructor and set properties from the subclass:

CustomLdapAuthenticationProvider.java

public class CustomLdapAuthenticationProvider extends LdapAuthenticationProvider {
    //your constructor
    public CustomLdapAuthenticationProvider(unParsedArguments) {
        //some logic to parse the arguments as desired
        super(parsedArguments);
        //set super's properties as desired

    }

    //other methods as needed/required
}

This approach gives you considerable flexibility in your application design, and it's what motivates open-source -- it's easy to extend, override, etc. You're already doing it, too, for the most part.

Then, change your applicationContext-security.xml:

<bean id="ldapProvider"
        class="your.project.package.CustomLdapAuthenticationProvider">
    <constructor-arg value="firstArgument"/>
    <constructor-arg value="secondArgument"/>
    <!-- etc. //-->
    <property name="fieldName" value="valueToBeSet"/>
</bean>

Obviously, this is contrived, but you should see what you need to do: extend, override/overload, and call super's methods/constructors according to your logic as opposed to a static template.

I hope this helps.