Configure spring security ldap-server attribute to use different url based on deployed environment

3.7k Views Asked by At

We are using spring security and have it working well. I am trying to figure out one thing that has not being obvious - how do I configure ldap-server attribute to use different url based on deployed environment?

This is what I have that is working:

<ldap-server url="ldap://testserver:port/o=blah" manager-dn="cn=bind,ou=Users,o=blah" manager-password="password"/>

<authentication-manager id="authenticationManager" alias="authenticationManager">
<ldap-authentication-provider            
    user-search-filter="(cn={0})"           
    user-search-base="ou=Users"           
    group-search-filter="(uniqueMember={0})"           
    group-search-base="ou=groups"           
    group-role-attribute="cn"           
    role-prefix="none">         
</ldap-authentication-provider>

Now, how do I configure it to use a different url based on deployed environment?

thanks in advance, Sharath

2

There are 2 best solutions below

0
On

You can use the url as variables and set them in a properties file. To change the properties file should be easier. I know you can do that with Maven - with jar or war plugin depending on packaging, including generating two (or more) packages with one execution - but I suppose you can with Ant or other managers too.

Of course, you could use that solution to change the whole xml, but it's easier to do that with a properties file because that way, when changing the configuration, the markup will not be in the way, only variables and values.

0
On

I've done that with Spring profiles:

In your spring.*.xml config file use this at the end of your file:

<beans profile="production">
...
</beans>
<beans profile="local">
...
</beans>

As VM Arguments the used profile must be provided: -Dspring.profiles.active=production

Regards