springspring-security-ldap

Dynamically configure LDAP server Properties using text file


I currently working with LDAP using Spring Security with XML Configuration. I need advice about how can i put attributes like URL, port, manager-dn and password in external file.

<ldap-server id="ldapServer"
        url="ldap://xxxxx:3268/dc=xxxxx,dc=com" port="3268"
        manager-dn="xxxxx@xxxxx.com" manager-password="xxxxxx" />

i mean, we need to put it externally because our other team (implementation team) need to change those properties values to go live without changing anything in war/binary file. Thank you


Solution

  • Done, thanks to this post

    Steps :

    1. create properties file and put it in the server

    ####### LDAP ##############
    ldap.urls= ldap://xxxx:3268/dc=xxxxx,dc=com
    ldap.manager-dn= xxxx@xxxxx.com
    ldap.manager-password= xxxx

    1. create properyplaceholder bean

    <beans:bean
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <beans:property name="location">
                <beans:value>file:///opt/xxxx/xxxxx/application.properties</beans:value>
            </beans:property>
        </beans:bean>

    1. access the properties from XML beans

    <ldap-server id="ldapServer" url="${ldap.urls}" port="3268"
            manager-dn="${ldap.manager-dn}"
            manager-password="${ldap.manager-password}" />